Hacker News new | ask | show | jobs
by detaro 2024 days ago
caret notation just maps all ASCII control characters to ^ + letter, many of which do not always have keys. "Backspace" is 0x08 = 8th letter is H = ^H

it's also not just used as an input, but also what a terminal that can't do or doesn't understand a backspace as "delete character, step to the left" prints instead.

1 comments

Not just letters! "^X" indicates "X, but with the control-bit flipped", where the control-bit is the left-most of ASCII's 7 bits.

    1001000 ASCII 'H'
    1000000 "ctrl bit"
    0001000 ASCII backspace
But like I said, it's not just letters, if you use `cat -v` to show all non-printable characters in this notation, you'll also see things like "^@" for the 0x00 null byte and "^[" for the ESC. All of the terminal color-code control sequences start with ESC, so if you pipe colorized output to `cat -v`, you'll see a lot of "^[".
Huh I guess that explains why they chose [ as the second byte in the initiator for color control sequences: ESC [ = ^[ [