coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

stty: set control characters

Open willshuttleworth opened this issue 8 months ago • 12 comments

Added functionality to set mappings between control characters (erase, intr, kill, etc.) and specific characters given by the user (^C, for example).

I had to rework the argument processing as it was previously processing one flag at a time, but this feature requires processing of consecutive args (ie stty erase ^C). Added string_to_control_char() to convert strings like "^C", "X", "0x7F" to their ASCII value if they are valid control char mappings. Also added apply_char_mapping() to set new control char mappings using termios.

I'm a relatively new Rust programmer, so I'd love feedback on things that could be written more idiomatically or concisely. This PR is related to issue #7357.

willshuttleworth avatar May 13 '25 14:05 willshuttleworth

GNU testsuite comparison:

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

github-actions[bot] avatar May 13 '25 15:05 github-actions[bot]

GNU testsuite comparison:

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

github-actions[bot] avatar May 15 '25 14:05 github-actions[bot]

anything else you'd like me to fix? i can push the final review commit now if we're all good

willshuttleworth avatar May 15 '25 15:05 willshuttleworth

@willshuttleworth from my side it looks good, maybe @tertsdiepraam has something to add as he wrote most of the current implementation.

cakebaker avatar May 15 '25 15:05 cakebaker

@cakebaker i have committed the final code review related changes

willshuttleworth avatar May 16 '25 20:05 willshuttleworth

GNU testsuite comparison:

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

github-actions[bot] avatar May 17 '25 05:05 github-actions[bot]

it would be nice to have tests

sylvestre avatar May 20 '25 07:05 sylvestre

the one issue with testing is that cargo test doesnt run in a tty, so i would need to do some reworking to test properly. there are two main options i can imagine now. this first is reworking uumain() so that control char parsing is done before the call to tcgetattr() and i can test for argument combinations that fail. or, i could rework the way testing is done so that a separate tty process is spawned and used. this crate seems to accomplish that. the first option seems to be the easier and more pragmatic approach, but i could be ignorant of better options.

willshuttleworth avatar May 20 '25 18:05 willshuttleworth

that would be ideal you could also start by testing at function level (like cc_to_index)

sylvestre avatar May 20 '25 18:05 sylvestre

ok, i have reworked the earlier changes so that some testing can be done. the new approach is to parse and collect all arguments, return errors if necessary, then apply the new flags. none of the tty related calls are made until parsing is complete, so errors during parsing can be tested for.

willshuttleworth avatar May 24 '25 17:05 willshuttleworth

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

github-actions[bot] avatar May 24 '25 18:05 github-actions[bot]

GNU testsuite comparison:

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

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

GNU testsuite comparison:

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

github-actions[bot] avatar Jun 02 '25 09:06 github-actions[bot]

@cakebaker i have integrated the changes from your review

willshuttleworth avatar Jun 03 '25 14:06 willshuttleworth

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/timeout/timeout (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Jun 03 '25 14:06 github-actions[bot]

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Jun 05 '25 09:06 github-actions[bot]

Thanks!

cakebaker avatar Jun 05 '25 09:06 cakebaker

thank you for all the help :) also, we can close this issue now.

willshuttleworth avatar Jun 05 '25 14:06 willshuttleworth