coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

Improve the `stty --all` output to match GNU version

Open 3v1n0 opened this issue 1 month ago • 17 comments

The output of stty --all was not really matching GNU one, adjust it to follow the same logic

Before:

--- /tmp/gnu-stty	2025-11-21 01:41:14.909020716 +0100
+++ /tmp/rust-stty	2025-11-21 00:38:42.324215733 +0100
@@ -1,10 +1,6 @@
-speed 38400 baud; rows 57; columns 112; line = 0;
-intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
-eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
-werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
--parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
--ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
--iuclc -ixany -imaxbel iutf8
-opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
-echoctl echoke -flusho -extproc
+speed 38400 baud; rows 57; columns 115; line = 0;
+intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
+-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts 
+-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -ixoff -tandem ixon -ixany -imaxbel iutf8 
+opost -olcuc -ocrnl onlcr -onocr -onlret -ofdel nl0 cr0 tab0 bs0 vt0 ff0 
+isig icanon iexten echo echoe echok -echonl -noflsh -tostop -echoprt echoctl echoke -flusho -extpro```

After:

--- /tmp/gnu-stty	2025-11-21 01:41:14.909020716 +0100
+++ /tmp/rust-stty	2025-11-21 04:31:16.511313289 +0100
@@ -4,7 +4,7 @@
 werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
 -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
 -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
--iuclc -ixany -imaxbel iutf8
-opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
-echoctl echoke -flusho -extproc
+-ixany -imaxbel iutf8
+opost -olcuc -ocrnl onlcr -onocr -onlret -ofdel nl0 cr0 tab0 bs0 vt0 ff0
+isig icanon iexten echo echoe echok -echonl -noflsh -tostop -echoprt echoctl
+echoke -flusho -extproc

Highlight is not great for word diffing, but well:

❯ wdiff /tmp/stty-out /tmp/rstty-out 
speed 38400 baud; rows 57; columns 112; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
[--iuclc-]
-ixany -imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret [--ofill-] -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh [--xcase-] -tostop -echoprt echoctl
echoke -flusho -extpro

After the flags we're missing will be included upstream, the diff will be actually none.

3v1n0 avatar Nov 21 '25 03:11 3v1n0

GNU testsuite comparison:

GNU test failed: tests/cksum/cksum-base64-untagged. tests/cksum/cksum-base64-untagged is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Nov 21 '25 05:11 github-actions[bot]

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Nov 21 '25 06:11 github-actions[bot]

GNU testsuite comparison:

Congrats! The gnu test tests/cksum/cksum-base64-untagged is no longer failing!

github-actions[bot] avatar Nov 21 '25 07:11 github-actions[bot]

GNU testsuite comparison:

Congrats! The gnu test tests/cksum/cksum-base64-untagged is no longer failing!

github-actions[bot] avatar Nov 21 '25 07:11 github-actions[bot]

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

github-actions[bot] avatar Nov 21 '25 22:11 github-actions[bot]

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Nov 22 '25 06:11 github-actions[bot]

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

github-actions[bot] avatar Nov 22 '25 15:11 github-actions[bot]

For making this easier to review for the maintainers, do you think it would be possible to split the Flag updates and the column env variable and printer?

Recently the ability for the integration tests in test_stty are able to run on the CI and if it would be possible could you create a test for the column output showing it working?

ChrisDryden avatar Nov 24 '25 18:11 ChrisDryden

Recently the ability for the integration tests in test_stty are able to run on the CI and if it would be possible could you create a test for the column output showing it working?

Yeah, I was considering it in fact now that there is such support indeed... I was wondering also if doing GNU core-utils comparisons would make sense, but it cannot be done in a static way since the values may change, but a proper test would be runnig tty --all with both tools in the same environment and compare them, but I'm unsure how this can be achieved.

3v1n0 avatar Nov 24 '25 18:11 3v1n0

do you think it would be possible to split the Flag updates and the column env variable and printer?

Yeah, they are already in different commits. In fact I was expecting the PR to be reviewed considering each commit as atomic, but I can split it out if you prefer to have different PRs instead (I know github per-commit review workflow is far away from the good that it is in gitlab)

3v1n0 avatar Nov 24 '25 18:11 3v1n0

https://github.com/uutils/coreutils/issues/9338 I have some more details in here about some of the GNU current incompatibilities, there is a test in the GNU test suite that tests the COLUMN env variable and maybe replicating that would be the best way to do it

ChrisDryden avatar Nov 24 '25 18:11 ChrisDryden

This is an output agnostic way to test it thats used in the GNU test suite, that we're looking to have compatibility with

# Ensure we wrap output appropriately
for W in $(seq 80 90); do
  output_width=$(COLUMNS="$W" stty -a | wc -L)
  test "$output_width" -le "$W" || fail=1
done

ChrisDryden avatar Nov 24 '25 19:11 ChrisDryden

Hi, I come from nix-rust/nix, let me know if you need nix to drop a release when those PRs get merged

SteveLauC avatar Nov 25 '25 05:11 SteveLauC

Hi, I come from nix-rust/nix, let me know if you need nix to drop a release when those PRs get merged

We can probably wait until the libc missing stuff has landed too

3v1n0 avatar Nov 25 '25 09:11 3v1n0

Mind if I cherry-pick that first commit of yours to a new pr and add another commit for adding the integ tests for that commit? I'm just particularly focused on that env COLUMNS portion of the PR since after the saved state parser its the only thing missing to make a few of the STTY GNU tests pass.

ChrisDryden avatar Nov 25 '25 18:11 ChrisDryden

Mind if I cherry-pick that first commit of yours to a new pr and add another commit for adding the integ tests for that commit? I'm just particularly focused on that env COLUMNS portion of the PR since after the saved state parser its the only thing missing to make a few of the STTY GNU tests pass.

Sure, feel free

3v1n0 avatar Nov 25 '25 19:11 3v1n0

Hi, I come from nix-rust/nix, let me know if you need nix to drop a release when those PRs get merged

We can probably wait until the libc missing stuff has landed too

Yeah, nix PRs depend on those libc PRs

SteveLauC avatar Nov 26 '25 01:11 SteveLauC