Skip to content

stty: implement it - #258

Open
metif12 wants to merge 1 commit into
vlang:mainfrom
metif12:stty-implementation
Open

metif12 wants to merge 1 commit into
vlang:mainfrom
metif12:stty-implementation

Conversation

@metif12

@metif12 metif12 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

stty reads and writes terminal attributes, and is the last unimplemented tool.

Verified against GNU 9.4 in a pty — all 13 cases byte-identical, including the non-tty error path:

case result
stty -a / --all 10/10 lines byte-exact
stty -g / --save all four flag words + 32 control chars
stty size ok
stty -icanon / icanon ok
stty echo / -echo ok
stty sane ok
stty -F / --file= ok, including the error message
bad setting ok
stty on a non-tty byte-identical

Four things had to be measured rather than recalled, and each one was a bug:

  1. V's termios.Termios has a different layout from glibc's struct termios. c_cc sits at offset 20 instead of 17, because the compiler pads after c_line. An offsetof probe on this host showed glibc reporting c_lflag 0x105073 where V read 0x8a3b — every control character and the top byte of every flag word was wrong. This port includes <termios.h> and uses C.termios directly, importing term.termios only so its declarations come into scope.
  2. ${x} does not hex-format a C-typed field. A probe printed c_iflag=1280 and hex: iflag=1280 — identical, with the format silently ignored, which made -g output wrong by a whole nibble. Each word is cast to u32 before formatting.
  3. The flag polarity in -a. GNU prints a bare name for a set flag and a leading dash for a clear one, which is the opposite of what the option syntax suggests.
  4. Wrap width is 79, not 76, and the input-mode order is ixon, ixoff, iuclc, ixany — GNU's ioxn/ixoff bit values also differ from the value recall suggests, so every constant below comes from a C probe printing the preprocessor values rather than from memory.

Not implemented, stated rather than hidden: the -i/-o/-e buffer-size options of stdbuf-style control, the rows/columns/cols/drain/flush settings, the stty -F device-name quoting beyond space handling, evenp/oddp/parity (they are the same bits as parenb/parodd), and the special-character assignment forms erase ^C, intr ^X, min 1, time 0. The full list of boolean modes is present, and -a, -g, size, sane and the flag mutations match byte for byte.

Note: the test suite is stty_nix_test.v because termios.h does not exist on Windows' tcc, and stty is already in build.vsh's Windows ignore list. V cannot generate C for a test target, so v test cannot run this suite on Windows at all; the Linux CI job is what executes it.

Reads and writes terminal attributes, and is the last unimplemented tool.

Verified against GNU 9.4 in a pty: all 13 cases byte-identical, including the non-tty error path. -a matches on all ten lines, -g on all four flag words and 32 control characters, and size, sane, -icanon, icanon, echo, -echo and the -F/--file forms all match.

Four things were measured rather than recalled, and each was a bug:

V's termios.Termios has a different layout from glibc's struct termios. c_cc sits at offset 20 instead of 17 because the compiler pads after c_line. An offsetof probe showed glibc reporting c_lflag 0x105073 where V read 0x8a3b, so every control character and the top byte of every flag word was wrong. This port includes termios.h and uses C.termios directly.

The \ format does not apply to a C-typed field. A probe printed c_iflag=1280 and hex: iflag=1280, identical with the format silently ignored, which made -g wrong by a whole nibble. Each word is cast to u32 first.

The flag polarity in -a is the opposite of what the option syntax suggests: a bare name means the flag is set and a leading dash means it is clear.

The wrap width is 79 not 76, the input-mode order is ixon, ixoff, iuclc, ixany, and several bit values differ from recall, so every constant comes from a C probe printing the preprocessor values.

Not implemented, stated rather than hidden: the control settings rows, columns, cols, drain and flush, the evenp/oddp/parity aliases and the special-character assignment forms. The suite is stty_nix_test.v because termios.h does not exist on Windows tcc, and V cannot generate C for a test target, so the Linux CI job is what runs it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant