1 Terminal Features
liquibyte edited this page 2026-11-19 16:23:31 -06:00

Terminal Features

Hanshi's terminal is Hosho, a terminal library built into the program. This page lists, feature by feature, what Hosho understands: the control sequences and modes, the reports, colors and text attributes, the keyboard and mouse protocols, pictures, right-to-left text, shell marks, hyperlinks and the clipboard, and for each one the terminal or the specification it follows. It is a reference for people who write programs for terminals, or who want to know whether a program will work.

1. Where the behavior comes from

Hosho was written from public standards and manuals, not from the source code of another terminal. Its sources are these documents:

Document What Hosho takes from it
ECMA-48, Control Functions for Coded Character Sets The control functions and their parameters; C1 controls.
Paul Flo Williams, A parser for DEC's ANSI-compatible video terminals The parser's state machine.
The DEC VT100, VT102, VT220, VT320, VT420 and VT510 manuals; the VT330/VT340 graphics manual DEC's functions, modes, reports, character sets, sixel and its colors.
XTerm Control Sequences (ctlseqs) xterm's extensions, the keys and the mouse. Where two documents differ, Hosho does what xterm's ctlseqs says, because programs are tested against xterm.
The terminfo entry xterm-256color What programs expect: it is the TERM a program gets with the PC and VT220 keyboards.
The terminfo entries xterm-sun, xterm-hp, xterm-sco, rxvt, linux The keys of those keyboards.
kitty's keyboard protocol, graphics protocol and desktop notifications documents Those three protocols.
iTerm2's inline images document Inline pictures.
The Unicode Character Database (18.0) and UAX #9, the Unicode Bidirectional Algorithm Character widths, and the order of right-to-left text.
RFC 1950 and RFC 1951 (zlib and deflate) Compressed picture data.
X11's rgb.txt Color names.

The terminal most features follow is xterm; then come kitty (its keyboard protocol, graphics and notifications), iTerm2 (inline images) and rxvt (a key set, and urxvt's form of mouse reports). Nothing was taken from GNOME's VTE library or from another terminal's code. In the tables below, "Follows" names the terminal or the document among these whose description Hosho follows for the feature; a dash means that Hosho's source names none.

How output and keys pass through Hosho: the program writes to the pseudoterminal, the parser splits the bytes, the terminal carries out each function on the screen, and the widget draws it; keys go from the widget through the input encoder back to the program

Output goes left to right along the top; what you type goes back along the bottom. Reports (the answers to a program's questions) go from the terminal to the program the same way.

2. Characters and control codes

Feature What Hosho does Follows
UTF-8 Output is read as UTF-8; a wrong sequence shows U+FFFD. —
C1 controls Read when they come as UTF-8 (U+0080 to U+009F), as ESC and a second character. ECMA-48 5.3
Sub-parameters, BEL ending an OSC, CAN, SUB and ESC cancelling a string As xterm; the three places where Hosho's parser differs from Williams' diagram. xterm ctlseqs
BEL, BS, HT, LF, VT, FF, CR, SO, SI, ENQ The bell; back space (with reverse wrap, mode 45, to the line above); tab; new line (with LNM also carriage return); shift out and in; ENQ sends the answerback text. ECMA-48, VT100
Character sets G0 to G3 ESC ( ) * + with ASCII, DEC Special Graphics (line drawing), DEC Supplemental, DEC Technical, and the 13 national sets: British, Dutch, Finnish, French, French Canadian, German, Italian, Norwegian/Danish (both forms), Portuguese, Spanish, Swedish, Swiss. ESC - . / with ISO Latin-1. Locking shifts SO, SI, LS2, LS3; single shifts SS2, SS3. A national set is used only in national mode (42), the British set always. VT100 User Guide, VT220 manual (national sets), VT320 manual (Portuguese, Norwegian/Danish ISO form), vt100.net (Technical); the British set as xterm
Wide characters East Asian wide and full-width characters take two cells, ambiguous ones one cell; marks and format characters none. Unicode 18.0, UAX #11
Combining marks and emoji sequences Marks join the character before them (up to 16 in a cell); U+200D joins the next character; U+FE0F makes a narrow emoji two cells wide. —
Grapheme clusters (mode 2027) On at first and after a reset. Each grapheme cluster is one character on the screen, of one cell or two: a flag of two regional letters, an emoji with a skin tone, emoji joined with U+200D, a letter with its spacing mark, a Hangul syllable made of parts. Reset, each character with a width gets cells of its own. Indic conjuncts are not joined yet. UAX #29
VT52 mode CSI ? 2 l makes the terminal a VT52 (its cursor keys, erases, ESC Y addressing, graphics, keypad); ESC < leaves it, and the terminal is a VT100 until a reset. VT100 User Guide, chapter 3
8-bit answers ESC SP G (S8C1T) makes answers and keys use one C1 byte; ESC SP F (S7C1T) goes back. VT220

3. Cursor, editing and scrolling

Feature Sequences Follows
Cursor movement CUU, CUD, CUF, CUB, CNL, CPL, CHA, HPA, HPR, VPA, VPR, CUP, HVP, CHT, CBT, IND, NEL, RI, DECBI, DECFI ECMA-48, VT510
Save and restore the cursor DECSC and DECRC (ESC 7, ESC 8), SCOSC and SCORC (CSI s, CSI u), mode 1048 VT100; xterm
Erase ED (0, 1, 2, and 3 for the scrollback), EL, ECH; erased cells take the current background color (bce) ECMA-48; xterm (ED 3); terminfo xterm-256color (bce)
Protected cells DECSCA with DECSED and DECSEL; SPA and EPA VT220, ECMA-48
Insert and delete ICH, DCH, IL, DL, DECIC, DECDC, SL, SR; IRM (insert mode, mode 4) ECMA-48, VT420
Scrolling and margins SU, SD, DECSTBM (top and bottom), DECLRMM (mode 69) with DECSLRM (left and right margins); DECOM (mode 6) VT420; xterm
Tab stops HTS, TBC; one every 8 columns at first ECMA-48
Repeat REP, only straight after a character ECMA-48
Rectangles DECCRA (copy), DECFRA (fill), DECERA (erase), DECSERA (selective erase), DECCARA and DECRARA (change and reverse attributes), DECSACE, DECRQCRA (checksum) and XTCHECKSUM VT420; the checksum by xterm's rules
Line size DECDHL (double height), DECDWL (double width), DECSWL, DECALN (screen alignment test) VT100
Page size DECCOLM (80 or 132 columns, with mode 40; mode 95 keeps the screen), DECSCPP, DECSLPP, DECSNLS, and CSI 8 t; all but DECCOLM change the window's size, so they work only with "Programs can move and size the window" on (DECCOLM needs mode 40 instead) VT510; xterm (mode 40)
Cursor shape DECSCUSR: block, underline or bar, steady or blinking; 0 for the user's own. Mode 12 blinks; mode 25 shows or hides the cursor. VT510, xterm; mode 12 as terminfo's cnorm
Status line DECSSDT (none, the terminal's own indicator line, or one the program writes), DECSASD VT420
Printing MC: print the screen or the scroll region, the cursor's line, auto print, printer controller mode; DECPEX, DECPFF VT510
Keyboard lights DECLL VT510
Resets DECSTR (soft reset; autowrap stays on, as in xterm), RIS (full reset; the scrollback stays) VT510; xterm
Wrapping DECAWM (mode 7); reverse wrap (mode 45); the text is wrapped again when the width changes VT100; xterm (45)

4. Colors and text attributes

Feature SGR Follows
Bold, faint, italic, blink, inverse, invisible, strike-through 1, 2, 3, 5 and 6 (one kind of blink), 7, 8, 9; off with 22 to 29 ECMA-48
Underline styles 4 and 21 (double); 4:0 to 4:5: none, single, double, curly, dotted, dashed —
Overline 53, 55 ECMA-48
16 colors 30 to 37, 40 to 47, 90 to 97, 100 to 107, and 39, 49 ECMA-48; xterm (the bright colors)
256 colors and 24-bit color 38 and 48 with ;5;n, ;2;r;g;b, and the colon forms :5:n, :2:r:g:b, :2::r:g:b xterm
Underline color 58 (in the same forms), 59 —
Changing colors OSC 4 (palette), OSC 10, 11, 12 (text, background, cursor), OSC 13 to 19, with ? to ask; OSC 104 and 110 to 119 reset them. Colors as rgb:r/g/b, #rgb forms or X11 color names. xterm; X11 rgb.txt
Reverse video DECSCNM (mode 5) VT100

5. Modes

Modes What they do Follows
1 (DECCKM), 66 (DECNKM), ESC = and ESC > Application cursor keys; application keypad. VT100, VT420
67 (DECBKM) Backspace sends BS in place of DEL. VT420
12 (SRM, ANSI) Reset: the terminal shows what you type itself (local echo). ECMA-48
20 (LNM) New line mode. ECMA-48
47, 1047, 1049 The second (alternate) screen of full-screen programs. xterm
80 (DECSDM) Sixel display mode. VT330/VT340
1004 Focus reports: CSI I and CSI O. xterm
1007 Alternate scroll: the wheel sends Up and Down on the second screen. xterm
1034, 1036 Alt sets the eighth bit, or sends ESC first (on at first). xterm
1051, 1052, 1053, 1061 Sun, HP, SCO and VT220 keyboards (Keyboard and Mouse). xterm
2004 Bracketed paste. xterm
2026 Synchronized output: the terminal waits with drawing until the program has written its frame, for at most a second. —
2027 Grapheme clusters (section 2); on at first. —
8 (BDSM, ANSI), 2501 Right-to-left text in its reading order (on at first); a line's direction from its first strong character. ECMA-48 (BDSM); UAX #9; the terminal BiDi proposal (2501)

Mouse modes are in section 8. Modes Hosho does not have are answered as "not recognized" when a program asks; among them are highlight mouse tracking (1001) and the xterm modes 1010, 1011, 1035, 1037, 1039, 1042, 1043 and 1046.

6. Reports

A program asks Hosho answers Follows
What are you (DA1, CSI c, ESC Z) CSI ? 64;4;6;9;15;21;22;28 c: a VT420 with sixel, selective erase, national sets, the technical set, horizontal scrolling, color and rectangles. VT420
DA2 (CSI > c) CSI > 41;10;0 c: a VT420. VT420
Name and version (XTVERSION, CSI > q) `DCS > Hosho 1.3 ST`
Status, cursor position (DSR, CPR, DECXCPR) As a VT420: also the printer, the user-defined keys, the keyboard, the locator, macro space, memory checksum, data integrity and sessions. VT420
A mode's state (DECRQM) Set, reset, always set, always reset, or not recognized. VT420
A setting (DECRQSS) Margins, SGR, cursor shape, protection, conformance level, DECSACE, page size, status line, the modifier settings and the title modes. VT420; xterm
A terminfo capability (XTGETTCAP) The values of xterm-256color: its name, colors, RGB, Tc, the cursor and underline style capabilities, the keys and others. xterm
Presentation state (DECRQPSR), its restore (DECRSPS), terminal state (DECRQTSR), user-preferred set (DECRQUPSS), displayed extent (DECRQDE) DECCIR and DECTABSR; DECRQTSR answers with an empty state. VT420, VT510
Graphics limits (XTSMGRAPHICS) 256 color registers; sixel pictures up to 4096 by 4096. xterm
Text area and cell size (CSI 14 t, 16 t, 18 t, 19 t) Always answered. xterm
Window state, position, icon name, title (CSI 11, 13, 15, 20, 21 t) Only with "Programs can move and size the window" on. CSI 20 t gives the icon name (the title while a program has named no icon), CSI 21 t the title. xterm
Title stack, title modes (CSI 22 t, 23 t, XTSMTITLE, XTRMTITLE, XTTITLEPOS) A stack of 10 titles; titles in hexadecimal. xterm

7. Operating system commands (OSC)

OSC What it does Follows
0, 1, 2 The title and the icon name. xterm
4, 10 to 19, 104, 110 to 119 Colors (section 4). xterm
7 The shell's folder, as file://host/path. —
8 Hyperlinks: text with an address, opened with Ctrl+click. A dotted underline shows them. —
9 A notification with the text. ConEmu's sub-commands (9;1 to 9;12) other than 9;4 are ignored and give no notification. —
9;4 Progress of a job: none, a percentage, an error, an unknown end, paused. A thin bar shows it. —
22 The mouse pointer's shape, by name. —
52 Set or read the clipboard (or the PRIMARY selection with p), only as Preferences allows. xterm
99 kitty's notifications: title and body, also in parts. kitty's desktop notifications
133 Shell marks: A, B, C, D (Shell Integration). —
777;notify A notification with a title and a text. —
1337;File= iTerm2's inline pictures (section 9). iTerm2's inline images

8. Keyboard and mouse protocols

Feature What Hosho sends Follows
Keys PC-style function keys with xterm's modifier numbers (Keyboard and Mouse). xterm ctlseqs, terminfo xterm-256color
Other keyboards VT220, Sun, HP, SCO, rxvt and the Linux console. With Sun, HP, SCO, rxvt or the Linux console, a program gets the matching TERM (xterm-sun, xterm-hp, xterm-sco, rxvt-256color or rxvt, linux) when that terminfo entry is installed, and xterm-256color otherwise. xterm (VT220, modes 1051 to 1053, 1061); terminfo xterm-sun, xterm-hp, xterm-sco, rxvt, linux
modifyOtherKeys and its forms Levels 1 and 2 (XTMODKEYS, with XTQMODKEYS to ask), and the CSI u form (XTFMTKEYS). xterm
kitty keyboard protocol All five flags: unambiguous codes, repeats and releases, alternate keys, all keys as codes, the text of a key; a stack of 8 for each screen. kitty's keyboard protocol
F13 to F20 As xterm on a PC: F1 to F8 with Shift (CSI 1;2P to CSI 19;2~); with the VT220 keyboard, the VT220's own CSI 25~ to CSI 34~. xterm; VT220
User-defined keys DECUDK: a program defines Shift+F1 to Shift+F20. VT220
Answerback ENQ and Ctrl+Break send the answerback text. VT100
Mouse tracking Modes 9 (X10: presses), 1000 (press and release), 1002 (also drags), 1003 (all motion); buttons 1 to 3, the wheel, buttons 8 to 11, and Shift, Alt and Control. xterm
Mouse encodings The X10 bytes (to column 223), UTF-8 (1005), SGR (1006), urxvt's form (1015), SGR in pixels (1016). xterm; urxvt (1015)
DEC locator DECELR, DECSLE, DECRQLP, DECEFR: positions in cells or pixels. VT420
Focus and paste Focus reports (1004), bracketed paste (2004). xterm

9. Pictures

Protocol What Hosho has Follows
Sixel (DCS q) Raster attributes, 256 color registers (in HLS or RGB; at first the VT340's 16 colors), repeats, transparent background (P2 = 1); pictures up to 4096 by 4096 pixels; DECSDM. The cursor goes below the picture. VT330/VT340 manual, xterm ctlseqs
iTerm2 inline images (OSC 1337;File=) inline=1, width and height in cells, pixels or percent, preserveAspectRatio; PNG, JPEG, GIF and BMP files. iTerm2's inline images
kitty graphics protocol (APC G) Pixels as RGB (f=24), RGBA (f=32) or PNG (f=100), sent in the sequence itself, in parts (m=1) and compressed (o=z); store (a=t), store and show (a=T), show again (a=p), query (a=q), delete (a=d: all, by number, at the cursor, at a cell, in a column or a row); a size in cells (c, r); C=1 keeps the cursor; up to 32 stored pictures; answers OK or an error. kitty's graphics protocol; RFC 1950 and 1951

A sixel picture or an iTerm2 file may be up to 64 MiB as it is sent. A kitty picture may come in parts up to 64 MiB in all; a larger one is dropped, and the answer is the error EFBIG.

A picture becomes cells of the screen, so it scrolls and is erased as text is. Picture files, sixel data and compressed data are taken apart in a jail; kitty's plain RGB and RGBA pixels need no taking apart and are copied outside it (Safety).

Feature What Hosho has Follows
Right-to-left text The implicit rules of the Unicode Bidirectional Algorithm, with mirrored characters, for each line; modes 8 and 2501. UAX #9
Hyperlinks OSC 8, and addresses (scheme://... and mailto:) and file names found in the text (Using the Terminal). —
Shell marks OSC 133 A, B, C and D, with Hosho's own hosho=infer; OSC 7. A D whose status is 0 counts as success also when more fields follow it; a D with no status ends the command but gives its prompt no mark of success or failure. —
Search, command blocks, copy as HTML The terminal's own (Using the Terminal). —

11. Known limitations

  • No DA3 (CSI = c), no rapid blink of its own (SGR 6 is SGR 5), no SGR color with a color space given after semicolons, and no rgbi: or CIE color forms.
  • No OSC 5, 6, 105, 106 or 633, and of OSC 1337 only File=. Of ConEmu's OSC 9 sub-commands, only 9;4 (progress) is done.
  • Of kitty's graphics protocol: no files or shared memory (t=f, t=s, t=t), no part of a picture, no offsets, no layers, no placement numbers, no placeholders. An answer is sent only to a request with a number (i). The capital delete forms other than A and I keep the stored picture.
  • kitty notifications: buttons, icons and sounds are not used, and a body sent in parts gives a notification for each part.
  • Indic conjuncts (consonants joined by a virama) are not joined into one grapheme cluster.
  • In VT52 mode, the VT52's print sequences are not there, and the sequences of ANSI mode still work.