- Note 1
- Permission of the author has been granted to publish this here.
- Note 2
- This is based on the 1.2.13 kernel, with an addendum for 1.3.28.
- I've now checked back from 2.4.12. None of the information below has been changed. The only added feature is console cut-n-paste.
- (I used http://lxr.linux.no/blurb.html to check the changes. How very useful.)
Linux Console Driver
(Everything you ever wanted to know but couldn't be bothered to look in the source for.)
Author: Peter L Jones <email@example.com>
Date: Wed Sep 27 19:12:25 BST 1995
Addendum for: 1.3.28
I've not documented "hardware scrollback".
I don't use UTF. I've only covered it to the extent I can fathom from the source.
In UTF mode, once a complete character is assembled, it is translated.
Otherwise, the character then has its top bit set, if requested, and is then translated.
A glyph is to be displayed if
- we've assembled a complete UTF character
- we translated it okay
- it's not a control character, or we're displaying control characters
Otherwise, it might be a control character.
Otherwise it's ignore
These are characters that make a "mark" on the display.
You can never display the glyph for char(27) by transmitting ESC.
You cannot display glyphs for any character in the Control Characters table, unless enabled.
If there is a "pending newline"
a crlf sequence is issued prior to the glyph.
If we're in "insert mode",
the rest of the line is shifted right; the character in the last column is lost.
The glyph is then displayed.
If the cursor is in the last column,
If automatic margins are turned on,
the "pending newline" state is set (see earlier)
the next glyph can overwrite this one.
Otherwise the cursor is advanced.
Control characters can occur during ESCape sequence processing.
- bell - make a tone on the console speaker
- bs (backspace) - cursor to previous character (will not wrap to previous line)
- tab - cursor to next tab position
- ^j ^k ^l
- lf (linefeed) - cursor to next line, scroll if end of scrolling region; if CRLF mode select, cr as well
- cr (carriage return) - cursor to start of current line
- charset 1 - translate table G1, display control characters as glyphs
- charset 0 - translate table G0, don't display control characters as glyphs
Note: "charset n" sets the current translate table; e.g. ^n (sets charset 1, translate table G1, display control characters as glyphs) followed by ^[[10m would leave G1 in effect but disable display of control characters as glyphs and display setting the top bit of glyphs.
- ^x ^z
- cancel any ESCape sequence in progress
- begin an ESCape sequence
- "delete" - ignored
- begin a CSI sequence
- begin a CSI sequence
- begin a UTF control sequence
- begin a set G0 sequence
- begin a set G1 sequence
- begin a DEC test sequence
- cr, lf
- ri (reverse index) - cursor up, reverse scroll if top of scrolling region
- set tab in the current column
- request for terminal ID (response is ^[[?6c - VT102)
- store cursor position
- restore cursor position
- reset terminal completely
- Keypad is numeric (normal)
- Keypad is application (act as function keys)
There are two formats:
- Function keys are indicated by CSI [ and are dealt with later.
- The general format is CSI (i.e. ^[[), zero to 16 parameters (decimal numbers separated by semicolons) and a character to indicate the function being performed. E.g ^[[1;43;37m.
Missing parameters are defaulted. Screen co-ordinates and movements start at and default to 1 (unless otherwise stated). Parameters are named par1, par2 etc in the following descriptions.
CSI h and CSI l can have an optional ? after the CSI and before any parameters. This indicates "DEC Private" modes.
Note:Other manufacturers use different characters to select their private modes - Linux doesn't support any but DEC.
CSI ACursor Up by par1 lines
CSI FCursor Up by par1 lines, and to start of line
CSI eCursor Down by par1 lines
CSI ECursor Down by par1 lines, and to start of line
CSI aCursor Right by par1 characters
CSI DCursor Left by par1 characters
CSI dSet cursor vertical position to par1
CSI `Set cursor horizonal position to par1
CSI fSet cursor vertical position to par2 and horizontal position to par1
CSI LInsert par1 lines
CSI MDelete par1 lines
CSI @Insert par1 characters
CSI PDelete par1 characters
CSI XErase par1 characters (wraps around line ends)
CSI JScreen Erase sequence:
- CSI h
- Set Mode sequence
- CSI l
- Clear Mode sequence
- CSI n
- Request report:
- par1 = 5
- Status report: response is ^[[0n (terminal okay)
- par1 = 6
- Cursor report: response is ^[[y;xR - where y is
relative if origin mode is selected
CSI KLine Clear sequence:
- par1 = 0
- erase from cursor to end of display
- par1 = 1
- erase from start of display to cursor
- par1 = 2
- erase whole display
CSI cIf par1 = 0 (default), requests terminal ID (response is ^[[?6c - VT102)
CSI gClear tabs:
- par1 = 0
- erase from cursor to end of line
- par1 = 1
- erase from start of line to cursor
- par1 = 2
- erase whole line
CSI qSet LEDs; par1 indicates which LED to turn on - 0 - none, 1 - , 2 - , 3 - .
CSI rSet scrolling region
- par1 = 0
- Clears tab at the current column
- par1 = 3
- Clears all tabs
CSI sStore cursor position
CSI uRestore cursor position
CSI mCharacter Rendition sequence
CSI ]setterm(1) command sequence
- top, default and minimum 1, must be less than par2
- bottom, default and maximum end of display
Set and Clear Mode Sequences
CSI h sets modes; CSI l clears modes. There are two sets of modes -
ANSI standard and DEC private.
- Monitor (display control characters)
DEC Private modes:
- Cursor keys as application keys (send ^[Ox as appl, ^[[x as normal)
- 80 (off) or 132 (on) columns
- Inverse video
- Origin mode (and go to origin)
- Autowrap (right margin)
- Mouse reports #1
- Cursor visible
- Mouse reports #2
Character Rendition Sequences
Each parameter is actioned in order. You cannot get bright backgrounds (rather, I can't).
Author's comment:On SVR4, attribute code 6 is used for bright
background, if I remember correctly.
- default (intensity normal, underline off, blink off, normal video,
default colours (which start as white on black))
- intensity bold
- intensity dim
- 21 22
- intensity normal
- underline on
- underline off
- blink on
- blink off
- reverse video
- normal video
- restore translate table, turn off display of control chars, don't set the "top" bit of glyphs displayed
- disable the translate table, display control chars as glyphs, don't set the "top" bit of glyphs displayed
- disable the translate table, display control chars as glyphs, set the "top" bit of glyphs displayed
- underline on, set foreground colour to default
- underline off, set foreground colour to default
- set background colour to default
- set foreground colour (0-black, 1-red, 2-green, 3-brown, 4-blue,
5-magenta, 6-cyan, 7-white)
- set background colour (as foreground)
Setterm Commmand Sequences
The command is in par1, followed by parameters.
- Set underline colour - par2 is 0 to 15, which is 0 to 7 as in set foreground colour above, plus bold versions
- Set dim colour - par2 as above
- Store current attributes as defaults (so that CSI 0 m restores to
- Set blanking interval to par2 minutes (max one hour - i.e. 60)
UTF Control Sequences
- Turn off UTF
- Turn on UTF (^[%8 is deprecated)
There are two character sets, known as G0 and G1. G0 is the default character set. Each can be set to one of four mappings. The mappings, and the sequences to select them, are:
G0 G1Map Name
^[(B ^[)B 0Normal Map (default G0 map)
^[(0 ^[)0 1Graphics Map (default G1 map)
^[(U ^[)U 2Null Map
^[(K ^[)K 3User Map
The maps themselves are defined in "consolemap.c". "Normal Map" translates the standard IBM PC ROM character set to standard 8-bit ISO Latin-1. "Graphics Map" translates to the VT100 character set in graphics mode. "Null Map" passed the ROM characters straight through, except BS, CR, LF, LL, SO, SI and ESC. "User Map" is available to be changed in the source or by mapscrn(8).
DEC Test Sequences
Only one test, ^[#8, is defined. This fills the display with the character 'E' (to allow the display to be centred).
The console driver changed in 1.3.x. This section documents the changes between 1.2.13 and 1.3.28.
Font support is enhanced.
In addition to ESC, some other control characters cannot have their glyphs displayed - ^@ ^H ^J ^L ^M ^N ^O ^[.
Hardware scrollback has been enhanced.
The "Normal Map" has been renamed "Latin 1 Map" (LAT1_MAP).
UTF support has been enhanced.
Note:UTF mode can be used to display the excluded control characters - display UTF character 0xF0cc, where cc is the hex code of the position in the ROM character set to display.
512 byte font support is added.
Font height support allows the screen to resize to fit the font.
A new set of Nonstandard Sequences is defined, prefixed by ESC ]. (setterm commands are still CSI ].)
Each virtual console gains a colour palette, which defines the actual colours used on the display (so you can get yellow rather than brown, for example).
^RResets the default palette
- Set palette. Seven parameters are collected:
- is the palette element to redefine (0-7, as set foreground colour above)
- par2, par3
- set the red component
- par4, par5
- set the green component
- par6, par7
- set the blue component