News for hackers. Stuff that matters.
Re:"Rules" that terminal programs follow by ucarion on Thursday December 12, 2024 @05:52PM (#42404247)
What does "cooked" mode mean in the context of this article?
Re:"Rules" that terminal programs follow by kelnos on Thursday December 12, 2024 @05:55PM (#42404264)
It means that the keystrokes you type aren't just immediately handled to the application in raw form; something higher up the chain (kernel, terminal emulator, shell) is pre-processing ("cooking") them in some way, possibly taking actions before (or in place of) passing the keystrokes to the application.

For example, if an application you're using has left things in cooked mode, and you press ctrl+c, the application will never "see" that keystroke; something higher up in the input chain (I believe Linux's TTY driver) will see it, swallow it, and send SIGINT to the application.

Applications can also put the tty into "raw mode", where this won't happen; in that case the app is responsible for implementing those "expected" keystroke behaviors, if it makes sense for the application to do so.

Re:"Rules" that terminal programs follow by lilyball on Thursday December 12, 2024 @06:33PM (#42404515)
cooked mode also generally gives input to the program a line at a time and handles things like backspace to delete characters, and it handles program output too, doing things like replacing \n with \r\n.
Re:"Rules" that terminal programs follow by teddyh on Thursday December 12, 2024 @07:38PM (#42404906)
No, line-by-line vs. character-by-character is a separate mode from “cooked” mode. See “stty extproc”.
Re:"Rules" that terminal programs follow by lilyball on Friday December 13, 2024 @03:41PM (#42412165)
I read up on this and "cooked but character-by-character" is apparently something called "cbreak mode" (or "rare mode").
Re:"Rules" that terminal programs follow by teddyh on Friday December 13, 2024 @05:46PM (#42413011)
According to stty(1), ”cbreak” is a negative alias of “icanon”, which simply enables the special functions of the ‘erase’ (backspace), ‘kill’ (Ctrl-U), ‘werase’ (Ctrl-W), and ‘rprnt’ (Ctrl-R) keybindings. “cooked” mode includes “icanon”.

So no, I do not think that what you wrote is correct. From what I can tell, the line-by-line mode is “extproc”.

Re:"Rules" that terminal programs follow by lilyball on Monday December 16, 2024 @06:20PM (#42436602)
On macOS, running `stty cbreak; tr a-zA-Z A-Za-z` causes `tr` to immediately transform every character as it's typed. If I SSH into a linux box that doesn't work, though I'm wondering if that's SSH's fault (it's not convenient right now to get direct access). Certainly the Linux manpage for stty(1) documents a setting

  min N  with -icanon, set N characters minimum for a completed read
which suggests that if you set -icanon (e.g. cbreak) then reads may complete after 1 character.

Also on macOS the documentation for cbreak is different, it lists a bunch of settings including -icanon, it's Linux that makes it literally an alias for -icanon.

Re:"Rules" that terminal programs follow by emmelaich on Thursday December 12, 2024 @06:54PM (#42404646)
Do stty -a and have a look at the output. Do `man stty` for the whole gory story.

Raw means send characters immediately, literally. Cooked imply some some of the flags are on, specifically (from memory) icanon, echo, among the `lflags`. Plus others.

Further down among `cchars` you'll see werase = ^w and kill = ^u. Here kill means kill (erase) the line, not send a signal.