Julia Evans
Follow
ASCII control characters in my terminal
The author explores the concept of control codes in the terminal, such as Ctrl-A, Ctrl-C, and Ctrl-W, and how they work. There are 33 ASCII control characters, which can be categorized into codes handled by the operating system's terminal driver, codes that correspond to literal key presses, and codes used by readline. The author notes that there is no real structure to which codes are in which categories, as they evolved organically. There are only 33 control codes, which means that if you want to use Ctrl-1 as a keyboard shortcut, it's not meaningful, as it's the same as pressing 1. The author also notes that Ctrl+Shift+C is not a control code and its behavior depends on the terminal emulator. The official ASCII names for control codes are not very useful, as they were originally defined for telegraph machines and have since been repurposed. The author finds it hard to use Ctrl-M and Ctrl-I as keyboard shortcuts, as they are equivalent to Enter and Tab, respectively. The author provides a Python script to identify what control codes get sent when pressing various key combinations. The author notes that some control codes, such as Ctrl-W and Ctrl-U, can be handled differently depending on whether the terminal is in canonical or noncanonical mode. Finally, the author acknowledges that there are many caveats and conflicts when it comes to control codes, and that not all of this information is necessarily useful in practice.