Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 1 based indexing bug #9

Merged
merged 3 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/src/usage.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Usage

### Example

```julia
using TERMIOS
const T = TERMIOS
options = T.termios()
T.tcgetattr(stdin, options)
# Disable ctrl-c, disable CR translation, disable stripping 8th bit (unicode), disable parity
options.c_iflag &= ~(T.BRKINT | T.ICRNL | T.INPCK | T.ISTRIP | T.IXON)
# Disable output processing
options.c_oflag &= ~(T.OPOST)
# Disable parity
options.c_cflag &= ~(T.CSIZE | T.PARENB)
# Set character size to 8 bits (unicode)
options.c_cflag |= (T.CS8)
# Disable echo, disable canonical mode (line mode), disable input processing, disable signals
options.c_lflag &= ~(T.ECHO | T.ICANON | T.IEXTEN | T.ISIG)
options.c_cc[T.VMIN] = 0
options.c_cc[T.VTIME] = 1
T.tcsetattr(stdin, T.TCSANOW, options)
```

### API

```@autodocs
Expand Down
4 changes: 2 additions & 2 deletions src/TERMIOS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,12 @@ struct _C_CC
end

function Base.getindex(c_cc::_C_CC, index)
return collect(c_cc.ref._c_cc)[index]
return collect(c_cc.ref._c_cc)[index + 1]
end

function Base.setindex!(c_cc::_C_CC, value, index)
_c_cc = collect(c_cc.ref._c_cc)
_c_cc[index] = value
_c_cc[index + 1] = value
c_cc.ref._c_cc = NTuple{NCCS, UInt8}(_c_cc)
end

Expand Down
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const c_iflag = Sys.islinux() ? 0x00000500 : 0x0000000000006b02
const c_oflag = Sys.islinux() ? 0x00000005 : 0x0000000000000003
const c_cflag = Sys.islinux() ? 0x000000bf : 0x0000000000004b00
const c_lflag = Sys.islinux() ? 0x00008a3b : 0x00000000000005cf
const c_cc = Sys.islinux() ? (0x03, 0x1c, 0x7f, 0x15, 0x04, 0x00, 0x01, 0x00, 0x11, 0x13, 0x1a, 0x00, 0x12, 0x0f, 0x17, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00) : (0x04, 0xff, 0xff, 0x7f, 0x17, 0x15, 0x12, 0xff, 0x03, 0x1c, 0x1a, 0x19, 0x11, 0x13, 0x16, 0x0f, 0x01, 0x00, 0x14, 0xff)
const c_cc = Sys.islinux() ? (0x03, 0x1c, 0x7f, 0x15, 0x04, 0x00, 0x01, 0x00, 0x11, 0x13, 0x1a, 0x00, 0x12, 0x0f, 0x17, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00) : (0x04, 0xff, 0xff, 0x7f, 0x17, 0x15, 0x12, 0x00, 0x03, 0x1c, 0x1a, 0x19, 0x11, 0x13, 0x16, 0x0f, 0x01, 0x00, 0x14, 0x00)
const c_ispeed = Sys.islinux() ? 0x0000000f : 0x0000000000009600
const c_ospeed = Sys.islinux() ? 0x0000000f : 0x0000000000009600

Expand All @@ -18,7 +18,7 @@ const c_ospeed = Sys.islinux() ? 0x0000000f : 0x0000000000009600
@test term.c_oflag == c_oflag
@test term.c_cflag == c_cflag
@test term.c_lflag == c_lflag
@test_broken term.c_cc == c_cc
@test term.c_cc.ref._c_cc == c_cc
@test term.c_ispeed == c_ispeed
@test term.c_ospeed == c_ospeed

Expand All @@ -28,7 +28,7 @@ const c_ospeed = Sys.islinux() ? 0x0000000f : 0x0000000000009600
@test term.c_oflag == c_oflag
@test term.c_cflag == c_cflag
@test term.c_lflag == c_lflag
@test_broken term.c_cc == c_cc
@test term.c_cc.ref._c_cc == c_cc
@test term.c_ispeed == c_ispeed
@test term.c_ospeed == c_ospeed

Expand Down Expand Up @@ -59,7 +59,7 @@ end
@test term.c_oflag == c_oflag
@test term.c_cflag == c_cflag
@test term.c_lflag == c_lflag
@test_broken term.c_cc == c_cc
@test term.c_cc.ref._c_cc == c_cc
@test term.c_ispeed == c_ispeed
@test term.c_ospeed == c_ospeed

Expand Down