3 ms·
I agree with your overall point but your example isn't a great one because ^L would be handled by the controlling process regardless of the terminal state. You
by hnlmorg 3y ago
I agree with your overall point but your example isn't a great one because ^L would be handled by the controlling process regardless of the terminal state. You don't need any special magic here. And blanking specific sections of a screen wouldn't need any special magic unless you're launching other processes and forwarding their output to the terminal. But if you're not forwarding the output of other processes then you can use standard ANSI escape sequences (or even just \s) to blank specific parts of the screen.
\s is a bit hacky for blanking though, it can produce some undesired results in terms of copy/pasting from the terminal and resizing. But if you've got a "full screen" process like you're describing, you'd be trapping SIGWINCH for resize events anyway.
- hnlmorg 3y agoSince I'm getting downvoted so I'll evidence my point a little more: Bash source for the ^L hotkey: https://git.savannah.gnu.org/cgit/bash.git/tree/lib/readline/text.c#n589 https://git.savannah.gnu.org/cgit/bash.git/tree/lib/readline... Notice it's calling termcap: _rl_clear_screen (0); /* calls termcap function to clear screen */ So lets look at what termcap does: $ tput clear | hexdump -c 0000000 033 [ H 033 [ 2 J 0000007 Which isn't the ASCII character ^L (0xC) but instead an ANSI escape code (CSI sequence, to be exact) https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_... The actual ASCII character for ^L is form feed, (FF: https://www.ascii-code.net https://www.ascii-code.net) which does serve a similar function but designed for old printers: https://en.wikipedia.org/wiki/Page_break#Form_feed https://en.wikipedia.org/wiki/Page_break#Form_feed It doesn't actually clear the screen on modern TTYs. You can try this yourself: $ printf "\f" $ awk 'BEGIN{printf "%c", 12}' $ Notice how each time it's effectively doing the same as \n? So in conclusion, ^L clearing the screen isn't something built into the TTY. It's just a hot key like ^U. There are some hot keys are are driven by the TTY though. ^C, for example. When you press ^C you're not actually sending the 0x3 ASCII character to the controlling process, your TTY gobbles that up and sends a signal to the controlling process instead (albeit this behaviour can be changed by altering the TTYs mode, which requires making a SYSCALL). So here we've discussed ANSI escape codes, signals and SYSCALLs. However none of these interactions are ASCII characters despite how they're depicted in printed media. Suffice to say, terminals are complicated :)