Skip to main content

Module ansi

Module ansi 

Source
Expand description

ANSI escape sequence generation helpers.

This module provides pure byte-generation functions for ANSI/VT control sequences. It handles the encoding details so the Presenter can focus on state tracking and diffing.

§Design Principles

  • Pure functions: No state tracking, just byte generation
  • Zero allocation: Use stack buffers for common sequences
  • Explicit: Readable helpers over clever formatting

§Sequence Reference

CategorySequenceDescription
CSIESC [ n mSGR (Select Graphic Rendition)
CSIESC [ row ; col HCUP (Cursor Position, 1-indexed)
CSIESC [ n KEL (Erase Line)
CSIESC [ n JED (Erase Display)
CSIESC [ top ; bottom rDECSTBM (Set Scroll Region)
CSIESC [ ? 2026 h/lSynchronized Output (DEC)
OSCESC ] 8 ; ; url STHyperlink (OSC 8)
DECESC 7 / ESC 8Cursor save/restore (DECSC/DECRC)

Structs§

SgrCodes
SGR attribute codes for style flags.

Enums§

EraseDisplayMode
ED (Erase Display) mode.
EraseLineMode
EL (Erase Line) mode.

Constants§

ALT_SCREEN_ENTER
Enable alternate screen: CSI ? 1049 h
ALT_SCREEN_LEAVE
Disable alternate screen: CSI ? 1049 l
BRACKETED_PASTE_DISABLE
Disable bracketed paste: CSI ? 2004 l
BRACKETED_PASTE_ENABLE
Enable bracketed paste: CSI ? 2004 h
CURSOR_HIDE
Hide cursor: CSI ? 25 l
CURSOR_RESTORE
DEC cursor restore: ESC 8 (DECRC)
CURSOR_SAVE
DEC cursor save: ESC 7 (DECSC)
CURSOR_SHOW
Show cursor: CSI ? 25 h
FLAG_TABLE
Ordered table of (flag, on/off codes) for iteration.
FOCUS_DISABLE
Disable focus reporting: CSI ? 1004 l
FOCUS_ENABLE
Enable focus reporting: CSI ? 1004 h
MOUSE_DISABLE
Disable mouse reporting and clear legacy/alternate modes.
MOUSE_ENABLE
Enable SGR mouse reporting with mode-hygiene pre-reset:
RESET_SCROLL_REGION
Reset scroll region to full screen: CSI r
SGR_BLINK
SGR codes for blink (on=5, off=25).
SGR_BOLD
SGR codes for bold (on=1, off=22).
SGR_DIM
SGR codes for dim (on=2, off=22).
SGR_HIDDEN
SGR codes for hidden text (on=8, off=28).
SGR_ITALIC
SGR codes for italic (on=3, off=23).
SGR_RESET
SGR reset: CSI 0 m
SGR_REVERSE
SGR codes for reverse video (on=7, off=27).
SGR_STRIKETHROUGH
SGR codes for strikethrough (on=9, off=29).
SGR_UNDERLINE
SGR codes for underline (on=4, off=24).
SYNC_BEGIN
Begin synchronized output: CSI ? 2026 h
SYNC_END
End synchronized output: CSI ? 2026 l

Functions§

alt_screen_enter
Write alternate screen enter.
alt_screen_leave
Write alternate screen leave.
bracketed_paste_disable
Write bracketed paste disable.
bracketed_paste_enable
Write bracketed paste enable.
cha
CUP to column only: CSI col G (1-indexed)
cr
Move cursor to start of line: \r (CR)
cub
Move cursor back (left): CSI n D
cud
Move cursor down: CSI n B
cuf
Move cursor forward (right): CSI n C
cup
CUP (Cursor Position): CSI row ; col H (1-indexed)
cursor_hide
Write hide cursor.
cursor_restore
Write cursor restore (DECRC).
cursor_save
Write cursor save (DECSC).
cursor_show
Write show cursor.
cuu
Move cursor up: CSI n A
erase_display
ED (Erase Display): CSI n J
erase_line
EL (Erase Line): CSI n K
focus_disable
Write focus disable.
focus_enable
Write focus enable.
hyperlink_end
Close an OSC 8 hyperlink.
hyperlink_start
Open an OSC 8 hyperlink.
hyperlink_start_with_id
Open an OSC 8 hyperlink with an ID parameter.
lf
Move cursor down one line: \n (LF)
mouse_disable
Write mouse disable.
mouse_enable
Write mouse enable.
reset_scroll_region
Write reset scroll region.
set_scroll_region
DECSTBM (Set Top and Bottom Margins): CSI top ; bottom r
sgr_bg_16
Write SGR sequence for 16-color background.
sgr_bg_256
Write SGR sequence for 256-color background: CSI 48;5;n m
sgr_bg_default
Write SGR default background: CSI 49 m
sgr_bg_packed
Write SGR for a PackedRgba color as background (true color).
sgr_bg_rgb
Write SGR sequence for true color background: CSI 48;2;r;g;b m
sgr_codes_for_flag
Get SGR codes for a style flag.
sgr_fg_16
Write SGR sequence for 16-color foreground.
sgr_fg_256
Write SGR sequence for 256-color foreground: CSI 38;5;n m
sgr_fg_default
Write SGR default foreground: CSI 39 m
sgr_fg_packed
Write SGR for a PackedRgba color as foreground (true color).
sgr_fg_rgb
Write SGR sequence for true color foreground: CSI 38;2;r;g;b m
sgr_flags
Write SGR sequence for style flags (all set flags).
sgr_flags_off
Write SGR sequence to turn off specific style flags.
sgr_reset
Write SGR reset sequence.
sync_begin
Write synchronized output begin.
sync_end
Write synchronized output end.