The line discipline is related to terminals and pseudo terminals. Read the tty demystified page at first. Then read termios(3). A terminal may have several states, see stty(1). In some states it does not handle control characters. In other states, it won't handle all of them (for example; DC3
might not have a specific handling).
Terminals are quite complex stuff (and they are legacy things, since in the real world physical terminals such as the VT100 are no more used, you'll find them in museums only in 2017, only virtual terminals are practically used in Linux today). I recommend using some library like ncurses if you want to code some text-based user interface (or something like readline if you want a line based one). See also termcap and read about ANSI escape codes. BTW most interactive shells (like bash
or zsh
...) and terminal applications (e.g. vim
) are using a library such as libreadline
, libtinfo
, libncurses
, etc... And it is the application or library code and the terminal emulator program (e.g. gnome-terminal
or xterm
) which handles most control characters and escape codes. The kernel only handles the line discipline.
BTW, in 2017 we use UTF-8 everywhere (not ASCII anymore), so even terminal emulators know about UTF-8. Unicode requires a more sophisticated behavior (think about a user mixing left-to-right and right-to-left languages -e.g. English and Hebrew or Arabic- in the same input line). The behavior of most terminal emulators is configurable (e.g. you can enable or disable the audio beep for BEL
or make it only a blink).
And the support of various control characters may happen in different layers (or might not happen, in the sense that some don't have any special meaning)...
At last, graphical user interfaces (with widget toolkits like Qt or GTK+) and web interfaces (you might use some HTTP server library like libonion) are more widely used than before.
If you want to code a text-based user interface application today, I strongly recommend using some additional library (like ncurses
etc...).
BTW, some behavior could be tuned or configured for each user or pseudo-terminal, and some various terminal emulators are more or less configurable; see also console_codes(4), locale(7), ascii(7), UTF-8(7), charsets(7), environ(7), pty(7), signal(7), term(7), termio(7), unicode(7).
You could also configure, or improve, some particular terminal emulator (they are free software, so you can study and patch their source code) to fit your particular needs (and add specific behavior for those weird control characters that you want to do something useful). The behavior of a specific terminal emulator on weird control characters is specific to that emulator; I guess that most of them would skip or ignore some of them.
However, you can have device files (such as for modems, keyboards, etc...) and files (or socket(7)-s) handling arbitrary sequence of bytes (they don't need to be ASCII or UTF-8, the character encoding is conventional only).
AFAIK, many control characters (notably horizontal and vertical tabs, returns, form feeds, escapes, ...) - probably most of them - are not handled by the line discipline implemented in kernel code. But they are known to application code (in particular those using ncurses
or readline
) and to the terminal emulator (e.g. gnome-terminal
or xterm
).
ESC
is often interpreted for ANSI escape codes (which are not defined by ASCII) – Basile Starynkevitch Oct 29 '17 at 07:33