Skip to Content
Navigation:

A stick figure smiling

This is a page from an upcoming zine called "The Secret Rules of the Terminal".

To get an email when the zine comes out, sign up for the zine announcements list!

Image of a comic. To read the full HTML alt text, click "read the transcript". browse more comics! get the zine!
read the transcript!

the terminal driver: an interface that hasn’t changed since the 80s

stressed-out stick figure with curly hair, surrounded by question marks: “I pressed an arrow key and it just printed out ^[[D???”

terminal driver, represented by a square smiley face: “what’s an arrow key?”

programs can choose to either:

  1. get a preprocessed line of text from the terminal driver when you press Enter (“canonical mode”, the default)

  2. get raw bytes like “backspace” immediately when you type them (“raw mode”)

“canonical mode” is a terrible way to edit text

because the terminal driver hasn’t changed much since the 80s, you can only do:

  1. backspace
  2. Ctrl+W (delete word)
  3. Ctrl+U (delete line)

how canonical mode works

  1. you type “helll” + backspace

person:

helll
<BACKSPACE>o
<Enter>
  1. the terminal emulator turns what you typed into bytes

terminal emulator, represented by a box with tiny arms and legs and a very cute winking cursor eye: hell\x7Fo\n

  1. the terminal driver passes on “hell” and interprets the backspace

PTMX -> TTY -> hello\n

  1. the program gets “hello\n”

The program is represented by a box with a smiley face, with a little arrow pointing to it, labelled “in”

In canonical mode, terminal driver doesn’t send anything to the program until you press Enter.

In raw mode, the terminal driver just sends “hell\xFo\n” without changing it

how to try out canonical mode

Run cat and type some stuff!

Interactive programs almost never use canonical mode because it’s so limited.

But if you run into it rlwrap $COMMAND can help

Saturday Morning Comics!

Want another comic like this in your email every Saturday? Sign up here!

I'll send you one of my favourite comics from my archives every Saturday.
© Julia Evans 2024 | All rights reserved (see the FAQ for notes about licensing)