termios
There’s a C library for manipulating terminal I/O settings called termios(3)
. These are some notes I took on termios
settings while working through Build Your Own Text Editor.
Terminal Shortcuts
Ctrl
+S
:XOFF
(“transmit off”), stop sending output (in case your teletype terminal needs to catch up with typing output)Ctrl
+Q
:XON
(“transmit on”), resume sending outputCtrl
+Y
: suspend program to background (usefg
to bring to foreground), likeCtrl
+Z
but it waits for the program to read input before it suspends itCtrl
+C
:SIGINT
, interrupt signalCtrl
+Z
:SIGTSTP
, terminal stop signalCtrl
+\
:SIGQUIT
, quit signalCtrl
+V
: “Verbatim”, sends next character verbatim (e.g.Ctrl
+V
followed byCtrl
+C
will send0x03
instead ofSIGINT
)Ctrl
+M
: Should produce0x0C
(because it’s the 13th letter), but the terminal converts'\r'
(0x0C
) to'\n'
(0x0A
) when theICRNL
flag is on
Local Modes (c_lflag
)
ECHO
: echo what you typeICANON
: canonical mode, wait for enter to read inputISIG
: respond toSIGINT
/SIGTSTP
IEXTEN
Input Modes (c_iflag
)
ICRNL
: converts'\r'
(0x0C
) to'\n'
(0x0A
)IXON
: whether to acceptXOFF
/XON
BRKINT
: sendSIGINT
on a break conditionINPCK
: enables parity checkingISTRIP
: Strips the 8th bit of every byte (like you’re not holdingCtrl
on an old keyboard)
Output Modes (c_oflag
)
OPOST
: output processing, prints'\r\n'
when asked to print'\n'
Control Modes (c_cflag
)
CS8
: Sets byte size to 8 bits. A mask, not flag.
Control Characters Array (c_cc
)
VMIN
: minimum number of bytes that read needs before returningVTIME
: timeout for read (units of 100 ms)c_iflag
: input modes (low-level input handling)c_oflag
: output modes (low-level output handling)c_lflag
: local modes (high-level input handling)c_cflag
: control modes (serial port behavior)