Skip to Content
ReferenceANSI sequences

ANSI Escape Sequence Reference

This page is the authoritative reference for the ANSI escape sequences used by FrankenTUI. It feeds the Presenter, TerminalWriter, and terminal-model tests.

Notation

  • ESC = \x1b (0x1B)
  • CSI = ESC [ (Control Sequence Introducer)
  • OSC = ESC ] (Operating System Command)
  • ST = ESC \ or \x07 (String Terminator)
  • {n} = numeric parameter
  • {r}, {c} = row, column (1-indexed)

Direction Labels

Each sequence is annotated with its direction:

  • Emit — ftui writes this sequence to the terminal.
  • Parse — ftui reads and interprets this sequence from terminal input.
  • Both — used in both directions.

Cursor Movement (Emit)

Absolute Positioning

SequenceNameEffect
CSI {r};{c} HCUPMove cursor to row r, column c
CSI {r};{c} fHVPSame as CUP
CSI {c} GCHAMove cursor to column c
CSI {r} dVPAMove cursor to row r

Relative Movement

SequenceNameEffect
CSI {n} ACUUMove cursor up n rows
CSI {n} BCUDMove cursor down n rows
CSI {n} CCUFMove cursor forward n columns
CSI {n} DCUBMove cursor back n columns
CSI {n} ECNLMove to beginning of line n lines down
CSI {n} FCPLMove to beginning of line n lines up

Cursor Save/Restore (Emit)

SequenceNameEffect
ESC 7DECSCSave cursor position + attributes (DEC)
ESC 8DECRCRestore cursor position + attributes (DEC)
CSI sSCOSCSave cursor position (ANSI)
CSI uSCORCRestore cursor position (ANSI)

DEC save/restore (ESC 7/ESC 8) is preferred — it saves more state and has wider support. See ADR-001.

Cursor Visibility (Emit)

SequenceNameEffect
CSI ? 25 hDECTCEMShow cursor
CSI ? 25 lDECTCEMHide cursor

Cursor Style (Emit) — DECSCUSR

SequenceEffect
CSI 0 SP qDefault cursor style
CSI 1 SP qBlinking block
CSI 2 SP qSteady block
CSI 3 SP qBlinking underline
CSI 4 SP qSteady underline
CSI 5 SP qBlinking bar (I-beam)
CSI 6 SP qSteady bar (I-beam)

The SP in DECSCUSR is a literal space (0x20) before q.

Device Status Reports (Both)

SequenceDirectionEffect
CSI 6 nEmitRequest cursor position
CSI {r};{c} RParseCursor position response
CSI cEmitRequest primary device attributes (DA1)
CSI > cEmitRequest secondary device attributes (DA2)
CSI > 0 qEmitRequest terminal version (XTVERSION)

See Also