brewery
notashelf /
5023e1033827ec5853e0e15c789a19eb04982549

beer

public

A terminal worth pouring time into

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/beer.git
crates/beer-protocols/README.mdMarkdown233 lines13.1 KB

beer-protocols

The terminal-protocol building blocks beer is built on: byte codecs, the terminfo capability table, character-set translation, SGR parsing, and the keyboard/mouse wire encoders. Everything here is a pure function or a plain data type, with no terminal state, so each protocol detail can be read and tested on its own. beer feeds these into its vte-driven dispatcher and its grid model.

This README doubles as the reference for which escape sequences, OSC commands, and POSIX behaviours beer actually implements - the parts a user notices. Sequences not listed here are parsed and ignored rather than passed through. Notation: ESC is 0x1b, CSI is ESC [, OSC is ESC ], DCS is ESC P, ST is the string terminator ESC \ (a BEL is also accepted to end an OSC). Ps is a numeric parameter, Pt a text parameter.

Crate layout

ModuleWhat it covers
codecbase64 (OSC 52), hex (XTGETTCAP names), file:// URI percent-decoding (OSC 7)
capsterminfo capabilities answered over XTGETTCAP
charsetG0/G1 designation and DEC special-graphics line drawing
sgrthe multi-parameter SGR colour and underline forms
keylegacy xterm/VT and kitty keyboard-protocol key encoding
mouseX10 / UTF-8 / SGR mouse-report encoding
stylethe enums an SGR/DECSET stream selects

C0 control characters

ByteNameEffect
0x07BELrings the bell (visual flash / command / urgency, per config)
0x08BSbackspace
0x09HTtab to next stop
0x0A-0x0CLF/VT/FFline feed
0x0DCRcarriage return
0x0ESOinvoke G1 (shift out)
0x0FSIinvoke G0 (shift in)

Cursor movement and editing (CSI)

SequenceNameEffect
CSI Ps ACUUcursor up
CSI Ps B / CSI Ps eCUDcursor down
CSI Ps C / CSI Ps aCUFcursor forward
CSI Ps DCUBcursor back
CSI Ps ECNLcursor down, to column 1
CSI Ps FCPLcursor up, to column 1
CSI Ps G / `CSI Ps ``CHAmove to column
CSI Ps dVPAmove to row
CSI Ps ; Ps H / fCUP/HVPmove to row;col
CSI Ps JEDerase in display (0 below, 1 above, 2 all)
CSI Ps KELerase in line (0 right, 1 left, 2 all)
CSI Ps @ICHinsert blank characters
CSI Ps PDCHdelete characters
CSI Ps LILinsert lines
CSI Ps MDLdelete lines
CSI Ps XECHerase characters
CSI Ps SSUscroll up
CSI Ps TSDscroll down
CSI Ps ; Ps rDECSTBMset scroll region (top;bottom)
CSI Ps gTBCclear tab stop (0) or all tabs (3)
CSI s / CSI uSCOSC/SCORCsave / restore cursor

ESC (non-CSI)

SequenceNameEffect
ESC DINDline feed
ESC MRIreverse index
ESC ENELnext line
ESC 7 / ESC 8DECSC/DECRCsave / restore cursor
ESC HHTSset tab stop
ESC cRISfull reset
ESC ( c / ESC ) cSCSdesignate G0 / G1 charset (0 = DEC special graphics, B = ASCII)

Graphic rendition (SGR, CSI Ps m)

Bold (1), dim (2), italic (3), underline (4), blink (5/6), reverse (7), hidden (8), strike (9), and their resets (22-29). Overline (53) and its reset (55). Underline styles via 4:x and SGR 21: single, double, curly, dotted, dashed.

Colours: the 16 ANSI colours (30-37, 90-97 foreground; 40-47, 100-107 background) and default (39/49). Extended colour for foreground (38), background (48), and underline (58/59), in both the legacy semicolon form (38;5;n, 38;2;r;g;b) and the colon-subparameter form (38:5:n, 38:2:r:g:b, with an ignored colour-space id). 256-colour and 24-bit truecolor are fully supported.

Modes (DECSET/DECRST CSI [?] Ps h / l)

ModeNameEffect
4 (ANSI)IRMinsert/replace
?1DECCKMapplication cursor keys
?6DECOMorigin mode
?7DECAWMautowrap
?25DECTCEMcursor visibility
?9-X10 mouse reporting
?1000-normal mouse (press/release)
?1002-button-event mouse (drag)
?1003-any-event mouse (all motion)
?1004-focus in/out reporting
?1005-UTF-8 mouse coordinates
?1006-SGR mouse coordinates
?47 / ?1047-alternate screen
?1049-alternate screen + save/restore cursor
?2004-bracketed paste
?2026-synchronized output

Mode state is reportable with DECRQM (CSI [?] Ps $ p), which replies CSI [?] Ps ; state $ y (1 set, 2 reset, 0 unrecognized).

Cursor style (DECSCUSR, CSI Ps SP q)

0/1 blinking block, 2 steady block, 3 blinking underline, 4 steady underline, 5 blinking bar, 6 steady bar. The configured default applies until an application overrides it.

Device reports

SequenceNameReply
CSI cDA1CSI ?62;22c (VT220 + ANSI colour)
CSI > cDA2CSI >0;276;0c
CSI = cDA3DCS !|00000000 ST
CSI 5 nDSRCSI 0n (terminal OK)
CSI 6 nCPRCSI row;col R (cursor position)
CSI > qXTVERSIONDCS >|beer(version) ST
DCS + q <names> STXTGETTCAPper name, DCS 1 + r name=value ST or DCS 0 + r name ST

XTGETTCAP answers TN (terminal name beer), Co/colors (256), and RGB (8/8/8, i.e. truecolor).

Window title

OSC 0 ; Pt and OSC 2 ; Pt set the title. The title stack (CSI 22 t push, CSI 23 t pop) is supported, so full-screen programs can save and restore it.

OSC commands

CommandEffect
OSC 0 / OSC 2set window title
OSC 4 ; idx ; specset / query palette entry (? queries)
OSC 104 [; idx ...]reset palette (all, or listed entries)
OSC 10 / OSC 11set / query default foreground / background
OSC 110 / OSC 111reset foreground / background
OSC 12 / OSC 112set / reset cursor colour
OSC 17 / OSC 19set / query selection background / foreground
OSC 7 ; file://host/pathreport working directory (used for new windows)
OSC 8 ; params ; URIhyperlink (empty URI ends it)
OSC 9 ; Ptdesktop notification (iTerm2 style)
OSC 777 ; notify ; title ; bodydesktop notification (rxvt style)
OSC 99 ; metadata ; bodydesktop notification (kitty style, single-chunk)
OSC 52 ; target ; dataclipboard set (base64) or query (?)
OSC 133 ; A/B/C/Dshell-integration prompt marks

Colour specs follow the X11 forms #rrggbb and rgb:rr/gg/bb (1-4 hex digits per channel). Colour queries reply in the rgb:rrrr/gggg/bbbb form.

Clipboard (OSC 52)

OSC 52 ; c ; <base64> sets the clipboard, ; p ; the primary selection; ; c ; ? queries. For privacy, a query is answered from the text beer itself last placed there, not the live system clipboard - so a remote program cannot read what another application copied.

Shell integration (OSC 133 / OSC 7)

Prompt marks A (prompt start), B (command start), C (output start), and D (command end) drive prompt-jumping and “pipe last command output”. OSC 7 tracks the working directory so a new window opens in the same place.

Keyboard

The legacy xterm/VT encoding covers cursor keys (with DECCKM application mode), the editing keypad (Insert/Delete/PageUp/PageDown), F1-F12, and the xterm modifier parameter (CSI 1 ; m <letter>), with Alt sending a