quitting in the terminal

wizard zines
@b0rk TIL about the C→3→SIGINT mapping!

@dngrs @b0rk A tiny technical caveat: control-C sends a byte with value 0x03 on purpose; this is designed into ASCII; the control key maps A through Z to control codes 1 through 26 in alphabetical order; yes, this is why control-[ is another way to type the ESC key.

But the "character code 0x03 means send SIGINT" rule is adjustable (with the `stty` command) and SIGINT itself is usually *not* signal number 3 (there's no official rule for which signals have which numbers, but SIGINT is almost always number 2).

@zwol @dngrs thanks, I need to be better about clarifying which parts of this are configurable and which parts aren't

I think the rules are

* you *can* sometimes configure what `alt` or `option` do in your terminal emulator
* you *can’t* configure what byte `Ctrl+C` will send
* you *can* configure what `3` does (via stty like you said)
* if your terminal emulator sends an escape code (via alt+x, mouse, etc), you usually *can't* configure how the program will handle those escape codes
* ???

@b0rk @dngrs stty also lets you change _which byte_ will send SIGINT (and SIGQUIT and SIGTSTP), like if you want Ctrl-\ (0x28) to mean SIGINT instead of SIGQUIT you can do that. It doesn't even have to be a control code! But setting it to any graphic character or to ^@ ^H ^I ^J ^L ^M ^? ESC or SPACE is liable to have undesirable side effects. This is probably too much detail for the zine I'm just brain dumping.

Some programs do let you configure how the escape codes are handled but it's gonna be program by program and you will have to dig through the manual to find out if it's possible. Because this was the jargon back in the 1970s and it stuck, the term to look for in the manual is often "key binding" or "key rebinding".

I can't think of anything else right now.

@zwol @b0rk @dngrs re. graphic characters, a weird historical thing is that bell labs era unix used # to delete a character and @ to delete a line - the stty erase and stty kill characters that are these days usually ^? and ^U

https://man.freebsd.org/cgi/man.cgi?query=tty&sektion=4&apropos=0&manpath=Unix+Seventh+Edition

and nowadays its rare to encounter tty cooked mode unless typing directly into cat

tty(4)

@fanf @b0rk @dngrs Oh that's a good point. I actually have no idea if readline / editline / vi / etc pay attention to what the terminal thinks the special characters are.

You're in tty cooked mode whenever you need to SIGINT or SIGTSTP a long-running program that doesn't talk to the terminal, though.

I remember # for erase and @ for kill line being mentioned in a 1980s guide to programming microcomputers (think original IBM PC) in cut-down C — there was one chapter of "here's all the stuff Unix 7 C has that Lattice C had to leave out" and of course then had to orient you to the shell a little bit first. I imagine they date to the very earliest days when everyone was stuck using printing terminals.