ansi

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 14 Imported by: 190

Documentation

Overview

Package ansi defines common ANSI escape sequences based on the ECMA-48 specs.

All sequences use 7-bit C1 control codes, which are supported by most terminal emulators. OSC sequences are terminated by a BEL for wider compatibility with terminals.

Index

Constants

View Source
const (
	// SP is the space character (Char: \x20).
	SP = 0x20
	// DEL is the delete character (Caret: ^?, Char: \x7f).
	DEL = 0x7F
)
View Source
const (
	// NUL is the null character (Caret: ^@, Char: \0).
	NUL = 0x00
	// SOH is the start of heading character (Caret: ^A).
	SOH = 0x01
	// STX is the start of text character (Caret: ^B).
	STX = 0x02
	// ETX is the end of text character (Caret: ^C).
	ETX = 0x03
	// EOT is the end of transmission character (Caret: ^D).
	EOT = 0x04
	// ENQ is the enquiry character (Caret: ^E).
	ENQ = 0x05
	// ACK is the acknowledge character (Caret: ^F).
	ACK = 0x06
	// BEL is the bell character (Caret: ^G, Char: \a).
	BEL = 0x07
	// BS is the backspace character (Caret: ^H, Char: \b).
	BS = 0x08
	// HT is the horizontal tab character (Caret: ^I, Char: \t).
	HT = 0x09
	// LF is the line feed character (Caret: ^J, Char: \n).
	LF = 0x0A
	// VT is the vertical tab character (Caret: ^K, Char: \v).
	VT = 0x0B
	// FF is the form feed character (Caret: ^L, Char: \f).
	FF = 0x0C
	// CR is the carriage return character (Caret: ^M, Char: \r).
	CR = 0x0D
	// SO is the shift out character (Caret: ^N).
	SO = 0x0E
	// SI is the shift in character (Caret: ^O).
	SI = 0x0F
	// DLE is the data link escape character (Caret: ^P).
	DLE = 0x10
	// DC1 is the device control 1 character (Caret: ^Q).
	DC1 = 0x11
	// DC2 is the device control 2 character (Caret: ^R).
	DC2 = 0x12
	// DC3 is the device control 3 character (Caret: ^S).
	DC3 = 0x13
	// DC4 is the device control 4 character (Caret: ^T).
	DC4 = 0x14
	// NAK is the negative acknowledge character (Caret: ^U).
	NAK = 0x15
	// SYN is the synchronous idle character (Caret: ^V).
	SYN = 0x16
	// ETB is the end of transmission block character (Caret: ^W).
	ETB = 0x17
	// CAN is the cancel character (Caret: ^X).
	CAN = 0x18
	// EM is the end of medium character (Caret: ^Y).
	EM = 0x19
	// SUB is the substitute character (Caret: ^Z).
	SUB = 0x1A
	// ESC is the escape character (Caret: ^[, Char: \e).
	ESC = 0x1B
	// FS is the file separator character (Caret: ^\).
	FS = 0x1C
	// GS is the group separator character (Caret: ^]).
	GS = 0x1D
	// RS is the record separator character (Caret: ^^).
	RS = 0x1E
	// US is the unit separator character (Caret: ^_).
	US = 0x1F

	// LS0 is the locking shift 0 character.
	// This is an alias for [SI].
	LS0 = SI
	// LS1 is the locking shift 1 character.
	// This is an alias for [SO].
	LS1 = SO
)

C0 control characters.

These range from (0x00-0x1F) as defined in ISO 646 (ASCII). See: https://en.wikipedia.org/wiki/C0_and_C1_control_codes

View Source
const (
	// PAD is the padding character.
	PAD = 0x80
	// HOP is the high octet preset character.
	HOP = 0x81
	// BPH is the break permitted here character.
	BPH = 0x82
	// NBH is the no break here character.
	NBH = 0x83
	// IND is the index character.
	IND = 0x84
	// NEL is the next line character.
	NEL = 0x85
	// SSA is the start of selected area character.
	SSA = 0x86
	// ESA is the end of selected area character.
	ESA = 0x87
	// HTS is the horizontal tab set character.
	HTS = 0x88
	// HTJ is the horizontal tab with justification character.
	HTJ = 0x89
	// VTS is the vertical tab set character.
	VTS = 0x8A
	// PLD is the partial line forward character.
	PLD = 0x8B
	// PLU is the partial line backward character.
	PLU = 0x8C
	// RI is the reverse index character.
	RI = 0x8D
	// SS2 is the single shift 2 character.
	SS2 = 0x8E
	// SS3 is the single shift 3 character.
	SS3 = 0x8F
	// DCS is the device control string character.
	DCS = 0x90
	// PU1 is the private use 1 character.
	PU1 = 0x91
	// PU2 is the private use 2 character.
	PU2 = 0x92
	// STS is the set transmit state character.
	STS = 0x93
	// CCH is the cancel character.
	CCH = 0x94
	// MW is the message waiting character.
	MW = 0x95
	// SPA is the start of guarded area character.
	SPA = 0x96
	// EPA is the end of guarded area character.
	EPA = 0x97
	// SOS is the start of string character.
	SOS = 0x98
	// SGCI is the single graphic character introducer character.
	SGCI = 0x99
	// SCI is the single character introducer character.
	SCI = 0x9A
	// CSI is the control sequence introducer character.
	CSI = 0x9B
	// ST is the string terminator character.
	ST = 0x9C
	// OSC is the operating system command character.
	OSC = 0x9D
	// PM is the privacy message character.
	PM = 0x9E
	// APC is the application program command character.
	APC = 0x9F
)

C1 control characters.

These range from (0x80-0x9F) as defined in ISO 6429 (ECMA-48). See: https://en.wikipedia.org/wiki/C0_and_C1_control_codes

View Source
const (
	SystemClipboard  = 'c'
	PrimaryClipboard = 'p'
)

Clipboard names.

View Source
const (
	RequestNameVersion = "\x1b[>0q"
	XTVERSION          = RequestNameVersion
)

RequestNameVersion (XTVERSION) is a control sequence that requests the terminal's name and version. It responds with a DSR sequence identifying the terminal.

CSI > 0 q
DCS > | text ST

See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-PC-Style-Function-Keys

View Source
const (
	SaveCursor = "\x1b7"
	DECSC      = SaveCursor
)

SaveCursor (DECSC) is an escape sequence that saves the current cursor position.

ESC 7

See: https://vt100.net/docs/vt510-rm/DECSC.html

View Source
const (
	RestoreCursor = "\x1b8"
	DECRC         = RestoreCursor
)

RestoreCursor (DECRC) is an escape sequence that restores the cursor position.

ESC 8

See: https://vt100.net/docs/vt510-rm/DECRC.html

View Source
const (
	SaveCurrentCursorPosition = "\x1b[s"
	SCOSC                     = SaveCurrentCursorPosition
)

SaveCurrentCursorPosition (SCOSC) is a sequence for saving the current cursor position for SCO console mode.

CSI s

This acts like DECSC, except the page number where the cursor is located is not saved.

See: https://vt100.net/docs/vt510-rm/SCOSC.html

View Source
const (
	RestoreCurrentCursorPosition = "\x1b[u"
	SCORC                        = RestoreCurrentCursorPosition
)

RestoreCurrentCursorPosition (SCORC) is a sequence for restoring the current cursor position for SCO console mode.

CSI u

This acts like DECRC, except the page number where the cursor was saved is not restored.

See: https://vt100.net/docs/vt510-rm/SCORC.html

View Source
const (
	KeypadApplicationMode = "\x1b="
	DECKPAM               = KeypadApplicationMode
)

Keypad Application Mode (DECKPAM) is a mode that determines whether the keypad sends application sequences or ANSI sequences.

This works like enabling DECNKM. Use NumericKeypadMode to set the numeric keypad mode.

ESC =

See: https://vt100.net/docs/vt510-rm/DECKPAM.html

View Source
const (
	KeypadNumericMode = "\x1b>"
	DECKPNM           = KeypadNumericMode
)

Keypad Numeric Mode (DECKPNM) is a mode that determines whether the keypad sends application sequences or ANSI sequences.

This works the same as disabling DECNKM.

ESC >

See: https://vt100.net/docs/vt510-rm/DECKPNM.html

View Source
const (
	KittyDisambiguateEscapeCodes = 1 << iota
	KittyReportEventTypes
	KittyReportAlternateKeys
	KittyReportAllKeysAsEscapeCodes
	KittyReportAssociatedKeys

	KittyAllFlags = KittyDisambiguateEscapeCodes | KittyReportEventTypes |
		KittyReportAlternateKeys | KittyReportAllKeysAsEscapeCodes | KittyReportAssociatedKeys
)

Kitty keyboard protocol progressive enhancement flags. See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement

View Source
const (
	KeyboardActionMode = ANSIMode(2)
	KAM                = KeyboardActionMode

	SetKeyboardActionMode     = "\x1b[2h"
	ResetKeyboardActionMode   = "\x1b[2l"
	RequestKeyboardActionMode = "\x1b[2$p"
)

Keyboard Action Mode (KAM) is a mode that controls locking of the keyboard. When the keyboard is locked, it cannot send data to the terminal.

See: https://vt100.net/docs/vt510-rm/KAM.html

View Source
const (
	InsertReplaceMode = ANSIMode(4)
	IRM               = InsertReplaceMode

	SetInsertReplaceMode     = "\x1b[4h"
	ResetInsertReplaceMode   = "\x1b[4l"
	RequestInsertReplaceMode = "\x1b[4$p"
)

Insert/Replace Mode (IRM) is a mode that determines whether characters are inserted or replaced when typed.

When enabled, characters are inserted at the cursor position pushing the characters to the right. When disabled, characters replace the character at the cursor position.

See: https://vt100.net/docs/vt510-rm/IRM.html

View Source
const (
	SendReceiveMode = ANSIMode(12)
	LocalEchoMode   = SendReceiveMode
	SRM             = SendReceiveMode

	SetSendReceiveMode     = "\x1b[12h"
	ResetSendReceiveMode   = "\x1b[12l"
	RequestSendReceiveMode = "\x1b[12$p"

	SetLocalEchoMode     = "\x1b[12h"
	ResetLocalEchoMode   = "\x1b[12l"
	RequestLocalEchoMode = "\x1b[12$p"
)

Send Receive Mode (SRM) or Local Echo Mode is a mode that determines whether the terminal echoes characters back to the host. When enabled, the terminal sends characters to the host as they are typed.

See: https://vt100.net/docs/vt510-rm/SRM.html

View Source
const (
	LineFeedNewLineMode = ANSIMode(20)
	LNM                 = LineFeedNewLineMode

	SetLineFeedNewLineMode     = "\x1b[20h"
	ResetLineFeedNewLineMode   = "\x1b[20l"
	RequestLineFeedNewLineMode = "\x1b[20$p"
)

Line Feed/New Line Mode (LNM) is a mode that determines whether the terminal interprets the line feed character as a new line.

When enabled, the terminal interprets the line feed character as a new line. When disabled, the terminal interprets the line feed character as a line feed.

A new line moves the cursor to the first position of the next line. A line feed moves the cursor down one line without changing the column scrolling the screen if necessary.

See: https://vt100.net/docs/vt510-rm/LNM.html

View Source
const (
	CursorKeysMode = DECMode(1)
	DECCKM         = CursorKeysMode

	SetCursorKeysMode     = "\x1b[?1h"
	ResetCursorKeysMode   = "\x1b[?1l"
	RequestCursorKeysMode = "\x1b[?1$p"
)

Cursor Keys Mode (DECCKM) is a mode that determines whether the cursor keys send ANSI cursor sequences or application sequences.

See: https://vt100.net/docs/vt510-rm/DECCKM.html

View Source
const (
	EnableCursorKeys  = "\x1b[?1h"
	DisableCursorKeys = "\x1b[?1l"
)

Deprecated: use SetCursorKeysMode and ResetCursorKeysMode instead.

View Source
const (
	OriginMode = DECMode(6)
	DECOM      = OriginMode

	SetOriginMode     = "\x1b[?6h"
	ResetOriginMode   = "\x1b[?6l"
	RequestOriginMode = "\x1b[?6$p"
)

Origin Mode (DECOM) is a mode that determines whether the cursor moves to the home position or the margin position.

See: https://vt100.net/docs/vt510-rm/DECOM.html

View Source
const (
	AutoWrapMode = DECMode(7)
	DECAWM       = AutoWrapMode

	SetAutoWrapMode     = "\x1b[?7h"
	ResetAutoWrapMode   = "\x1b[?7l"
	RequestAutoWrapMode = "\x1b[?7$p"
)

Auto Wrap Mode (DECAWM) is a mode that determines whether the cursor wraps to the next line when it reaches the right margin.

See: https://vt100.net/docs/vt510-rm/DECAWM.html

View Source
const (
	X10MouseMode = DECMode(9)

	SetX10MouseMode     = "\x1b[?9h"
	ResetX10MouseMode   = "\x1b[?9l"
	RequestX10MouseMode = "\x1b[?9$p"
)

X10 Mouse Mode is a mode that determines whether the mouse reports on button presses.

The terminal responds with the following encoding:

CSI M CbCxCy

Where Cb is the button-1, where it can be 1, 2, or 3. Cx and Cy are the x and y coordinates of the mouse event.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

View Source
const (
	TextCursorEnableMode = DECMode(25)
	DECTCEM              = TextCursorEnableMode

	SetTextCursorEnableMode     = "\x1b[?25h"
	ResetTextCursorEnableMode   = "\x1b[?25l"
	RequestTextCursorEnableMode = "\x1b[?25$p"
)

Text Cursor Enable Mode (DECTCEM) is a mode that shows/hides the cursor.

See: https://vt100.net/docs/vt510-rm/DECTCEM.html

View Source
const (
	ShowCursor = SetTextCursorEnableMode
	HideCursor = ResetTextCursorEnableMode
)

These are aliases for SetTextCursorEnableMode and ResetTextCursorEnableMode.

View Source
const (
	CursorEnableMode        = DECMode(25)
	RequestCursorVisibility = "\x1b[?25$p"
)

Text Cursor Enable Mode (DECTCEM) is a mode that shows/hides the cursor.

See: https://vt100.net/docs/vt510-rm/DECTCEM.html

Deprecated: use SetTextCursorEnableMode and ResetTextCursorEnableMode instead.

View Source
const (
	NumericKeypadMode = DECMode(66)
	DECNKM            = NumericKeypadMode

	SetNumericKeypadMode     = "\x1b[?66h"
	ResetNumericKeypadMode   = "\x1b[?66l"
	RequestNumericKeypadMode = "\x1b[?66$p"
)

Numeric Keypad Mode (DECNKM) is a mode that determines whether the keypad sends application sequences or numeric sequences.

This works like DECKPAM and DECKPNM, but uses different sequences.

See: https://vt100.net/docs/vt510-rm/DECNKM.html

View Source
const (
	BackarrowKeyMode = DECMode(67)
	DECBKM           = BackarrowKeyMode

	SetBackarrowKeyMode     = "\x1b[?67h"
	ResetBackarrowKeyMode   = "\x1b[?67l"
	RequestBackarrowKeyMode = "\x1b[?67$p"
)

Backarrow Key Mode (DECBKM) is a mode that determines whether the backspace key sends a backspace or delete character. Disabled by default.

See: https://vt100.net/docs/vt510-rm/DECBKM.html

View Source
const (
	LeftRightMarginMode = DECMode(69)
	DECLRMM             = LeftRightMarginMode

	SetLeftRightMarginMode     = "\x1b[?69h"
	ResetLeftRightMarginMode   = "\x1b[?69l"
	RequestLeftRightMarginMode = "\x1b[?69$p"
)

Left Right Margin Mode (DECLRMM) is a mode that determines whether the left and right margins can be set with DECSLRM.

See: https://vt100.net/docs/vt510-rm/DECLRMM.html

View Source
const (
	NormalMouseMode = DECMode(1000)

	SetNormalMouseMode     = "\x1b[?1000h"
	ResetNormalMouseMode   = "\x1b[?1000l"
	RequestNormalMouseMode = "\x1b[?1000$p"
)

Normal Mouse Mode is a mode that determines whether the mouse reports on button presses and releases. It will also report modifier keys, wheel events, and extra buttons.

It uses the same encoding as X10MouseMode with a few differences:

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

View Source
const (
	MouseMode = DECMode(1000)

	EnableMouse  = "\x1b[?1000h"
	DisableMouse = "\x1b[?1000l"
	RequestMouse = "\x1b[?1000$p"
)

VT Mouse Tracking is a mode that determines whether the mouse reports on button press and release.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

Deprecated: use NormalMouseMode instead.

View Source
const (
	HighlightMouseMode = DECMode(1001)

	SetHighlightMouseMode     = "\x1b[?1001h"
	ResetHighlightMouseMode   = "\x1b[?1001l"
	RequestHighlightMouseMode = "\x1b[?1001$p"
)

Highlight Mouse Tracking is a mode that determines whether the mouse reports on button presses, releases, and highlighted cells.

It uses the same encoding as NormalMouseMode with a few differences:

On highlight events, the terminal responds with the following encoding:

CSI t CxCy
CSI T CxCyCxCyCxCy

Where the parameters are startx, starty, endx, endy, mousex, and mousey.

View Source
const (
	MouseHiliteMode = DECMode(1001)

	EnableMouseHilite  = "\x1b[?1001h"
	DisableMouseHilite = "\x1b[?1001l"
	RequestMouseHilite = "\x1b[?1001$p"
)

VT Hilite Mouse Tracking is a mode that determines whether the mouse reports on button presses, releases, and highlighted cells.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

Deprecated: use HighlightMouseMode instead.

View Source
const (
	ButtonEventMouseMode = DECMode(1002)

	SetButtonEventMouseMode     = "\x1b[?1002h"
	ResetButtonEventMouseMode   = "\x1b[?1002l"
	RequestButtonEventMouseMode = "\x1b[?1002$p"
)

Button Event Mouse Tracking is essentially the same as NormalMouseMode, but it also reports button-motion events when a button is pressed.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

View Source
const (
	MouseCellMotionMode = DECMode(1002)

	EnableMouseCellMotion  = "\x1b[?1002h"
	DisableMouseCellMotion = "\x1b[?1002l"
	RequestMouseCellMotion = "\x1b[?1002$p"
)

Cell Motion Mouse Tracking is a mode that determines whether the mouse reports on button press, release, and motion events.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

Deprecated: use ButtonEventMouseMode instead.

View Source
const (
	AnyEventMouseMode = DECMode(1003)

	SetAnyEventMouseMode     = "\x1b[?1003h"
	ResetAnyEventMouseMode   = "\x1b[?1003l"
	RequestAnyEventMouseMode = "\x1b[?1003$p"
)

Any Event Mouse Tracking is the same as ButtonEventMouseMode, except that all motion events are reported even if no mouse buttons are pressed.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

View Source
const (
	MouseAllMotionMode = DECMode(1003)

	EnableMouseAllMotion  = "\x1b[?1003h"
	DisableMouseAllMotion = "\x1b[?1003l"
	RequestMouseAllMotion = "\x1b[?1003$p"
)

All Mouse Tracking is a mode that determines whether the mouse reports on button press, release, motion, and highlight events.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

Deprecated: use AnyEventMouseMode instead.

View Source
const (
	FocusEventMode = DECMode(1004)

	SetFocusEventMode     = "\x1b[?1004h"
	ResetFocusEventMode   = "\x1b[?1004l"
	RequestFocusEventMode = "\x1b[?1004$p"
)

Focus Event Mode is a mode that determines whether the terminal reports focus and blur events.

The terminal sends the following encoding:

CSI I // Focus In
CSI O // Focus Out

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Focus-Tracking

View Source
const (
	ReportFocusMode = DECMode(1004)

	EnableReportFocus  = "\x1b[?1004h"
	DisableReportFocus = "\x1b[?1004l"
	RequestReportFocus = "\x1b[?1004$p"
)

Deprecated: use SetFocusEventMode, ResetFocusEventMode, and RequestFocusEventMode instead.

View Source
const (
	SgrExtMouseMode = DECMode(1006)

	SetSgrExtMouseMode     = "\x1b[?1006h"
	ResetSgrExtMouseMode   = "\x1b[?1006l"
	RequestSgrExtMouseMode = "\x1b[?1006$p"
)

SGR Extended Mouse Mode is a mode that changes the mouse tracking encoding to use SGR parameters.

The terminal responds with the following encoding:

CSI < Cb ; Cx ; Cy M

Where Cb is the same as NormalMouseMode, and Cx and Cy are the x and y.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

View Source
const (
	MouseSgrExtMode    = DECMode(1006)
	EnableMouseSgrExt  = "\x1b[?1006h"
	DisableMouseSgrExt = "\x1b[?1006l"
	RequestMouseSgrExt = "\x1b[?1006$p"
)

Deprecated: use SgrExtMouseMode SetSgrExtMouseMode, ResetSgrExtMouseMode, and RequestSgrExtMouseMode instead.

View Source
const (
	Utf8ExtMouseMode = DECMode(1005)

	SetUtf8ExtMouseMode     = "\x1b[?1005h"
	ResetUtf8ExtMouseMode   = "\x1b[?1005l"
	RequestUtf8ExtMouseMode = "\x1b[?1005$p"
)

UTF-8 Extended Mouse Mode is a mode that changes the mouse tracking encoding to use UTF-8 parameters.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

View Source
const (
	UrxvtExtMouseMode = DECMode(1015)

	SetUrxvtExtMouseMode     = "\x1b[?1015h"
	ResetUrxvtExtMouseMode   = "\x1b[?1015l"
	RequestUrxvtExtMouseMode = "\x1b[?1015$p"
)

URXVT Extended Mouse Mode is a mode that changes the mouse tracking encoding to use an alternate encoding.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

View Source
const (
	SgrPixelExtMouseMode = DECMode(1016)

	SetSgrPixelExtMouseMode     = "\x1b[?1016h"
	ResetSgrPixelExtMouseMode   = "\x1b[?1016l"
	RequestSgrPixelExtMouseMode = "\x1b[?1016$p"
)

SGR Pixel Extended Mouse Mode is a mode that changes the mouse tracking encoding to use SGR parameters with pixel coordinates.

This is similar to SgrExtMouseMode, but also reports pixel coordinates.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

View Source
const (
	AltScreenMode = DECMode(1047)

	SetAltScreenMode     = "\x1b[?1047h"
	ResetAltScreenMode   = "\x1b[?1047l"
	RequestAltScreenMode = "\x1b[?1047$p"
)

Alternate Screen Mode is a mode that determines whether the alternate screen buffer is active. When this mode is enabled, the alternate screen buffer is cleared.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer

View Source
const (
	SaveCursorMode = DECMode(1048)

	SetSaveCursorMode     = "\x1b[?1048h"
	ResetSaveCursorMode   = "\x1b[?1048l"
	RequestSaveCursorMode = "\x1b[?1048$p"
)

Save Cursor Mode is a mode that saves the cursor position. This is equivalent to SaveCursor and RestoreCursor.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer

View Source
const (
	AltScreenSaveCursorMode = DECMode(1049)

	SetAltScreenSaveCursorMode     = "\x1b[?1049h"
	ResetAltScreenSaveCursorMode   = "\x1b[?1049l"
	RequestAltScreenSaveCursorMode = "\x1b[?1049$p"
)

Alternate Screen Save Cursor Mode is a mode that saves the cursor position as in SaveCursorMode, switches to the alternate screen buffer as in AltScreenMode, and clears the screen on switch.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer

View Source
const (
	AltScreenBufferMode = DECMode(1049)

	SetAltScreenBufferMode     = "\x1b[?1049h"
	ResetAltScreenBufferMode   = "\x1b[?1049l"
	RequestAltScreenBufferMode = "\x1b[?1049$p"

	EnableAltScreenBuffer  = "\x1b[?1049h"
	DisableAltScreenBuffer = "\x1b[?1049l"
	RequestAltScreenBuffer = "\x1b[?1049$p"
)

Alternate Screen Buffer is a mode that determines whether the alternate screen buffer is active.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer

Deprecated: use AltScreenSaveCursorMode instead.

View Source
const (
	BracketedPasteMode = DECMode(2004)

	SetBracketedPasteMode     = "\x1b[?2004h"
	ResetBracketedPasteMode   = "\x1b[?2004l"
	RequestBracketedPasteMode = "\x1b[?2004$p"
)

Bracketed Paste Mode is a mode that determines whether pasted text is bracketed with escape sequences.

See: https://cirw.in/blog/bracketed-paste See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode

View Source
const (
	EnableBracketedPaste  = "\x1b[?2004h"
	DisableBracketedPaste = "\x1b[?2004l"
	RequestBracketedPaste = "\x1b[?2004$p"
)

Deprecated: use SetBracketedPasteMode, ResetBracketedPasteMode, and RequestBracketedPasteMode instead.

View Source
const (
	SynchronizedOutputMode = DECMode(2026)

	SetSynchronizedOutputMode     = "\x1b[?2026h"
	ResetSynchronizedOutputMode   = "\x1b[?2026l"
	RequestSynchronizedOutputMode = "\x1b[?2026$p"
)

Synchronized Output Mode is a mode that determines whether output is synchronized with the terminal.

See: https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036

View Source
const (
	SyncdOutputMode = DECMode(2026)

	EnableSyncdOutput  = "\x1b[?2026h"
	DisableSyncdOutput = "\x1b[?2026l"
	RequestSyncdOutput = "\x1b[?2026$p"
)

Deprecated: use SynchronizedOutputMode, SetSynchronizedOutputMode, and ResetSynchronizedOutputMode, and RequestSynchronizedOutputMode instead.

View Source
const (
	GraphemeClusteringMode = DECMode(2027)

	SetGraphemeClusteringMode     = "\x1b[?2027h"
	ResetGraphemeClusteringMode   = "\x1b[?2027l"
	RequestGraphemeClusteringMode = "\x1b[?2027$p"
)

Grapheme Clustering Mode is a mode that determines whether the terminal should look for grapheme clusters instead of single runes in the rendered text. This makes the terminal properly render combining characters such as emojis.

See: https://github.com/contour-terminal/terminal-unicode-core

View Source
const (
	EnableGraphemeClustering  = "\x1b[?2027h"
	DisableGraphemeClustering = "\x1b[?2027l"
	RequestGraphemeClustering = "\x1b[?2027$p"
)

Deprecated: use SetGraphemeClusteringMode, ResetGraphemeClusteringMode, and RequestGraphemeClusteringMode instead.

View Source
const (
	Win32InputMode = DECMode(9001)

	SetWin32InputMode     = "\x1b[?9001h"
	ResetWin32InputMode   = "\x1b[?9001l"
	RequestWin32InputMode = "\x1b[?9001$p"
)

Win32Input is a mode that determines whether input is processed by the Win32 console and Conpty.

See: https://github.com/microsoft/terminal/blob/main/doc/specs/%234999%20-%20Improved%20keyboard%20handling%20in%20Conpty.md

View Source
const (
	EnableWin32Input  = "\x1b[?9001h"
	DisableWin32Input = "\x1b[?9001l"
	RequestWin32Input = "\x1b[?9001$p"
)

Deprecated: use SetWin32InputMode, ResetWin32InputMode, and RequestWin32InputMode instead.

View Source
const (
	ResetInitialState = "\x1bc"
	RIS               = ResetInitialState
)

ResetInitialState (RIS) resets the terminal to its initial state.

ESC c

See: https://vt100.net/docs/vt510-rm/RIS.html

View Source
const (
	EraseScreenBelow   = "\x1b[J"
	EraseScreenAbove   = "\x1b[1J"
	EraseEntireScreen  = "\x1b[2J"
	EraseEntireDisplay = "\x1b[3J"
)

EraseDisplay constants. These are the possible values for the EraseDisplay function.

View Source
const (
	EraseLineRight  = "\x1b[K"
	EraseLineLeft   = "\x1b[1K"
	EraseEntireLine = "\x1b[2K"
)

EraseLine constants. These are the possible values for the EraseLine function.

View Source
const (
	SetTabEvery8Columns = "\x1b[?5W"
	DECST8C             = SetTabEvery8Columns
)

SetTabEvery8Columns (DECST8C) sets the tab stops at every 8 columns.

CSI ? 5 W

See: https://vt100.net/docs/vt510-rm/DECST8C.html

View Source
const (
	SetModifyOtherKeys1  = "\x1b[>4;1m"
	SetModifyOtherKeys2  = "\x1b[>4;2m"
	ResetModifyOtherKeys = "\x1b[>4m"
	QueryModifyOtherKeys = "\x1b[?4m"
)

Modify Other Keys (modifyOtherKeys) is an xterm feature that allows the terminal to modify the behavior of certain keys to send different escape sequences when pressed.

See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys

View Source
const Blur = "\x1b[O"

Blur is an escape sequence to notify the terminal that it has lost focus. This is used with FocusEventMode.

View Source
const BracketedPasteEnd = "\x1b[201~"

BracketedPasteEnd is the control sequence to disable bracketed paste mode.

View Source
const BracketedPasteStart = "\x1b[200~"

BracketedPasteStart is the control sequence to enable bracketed paste mode.

View Source
const CUB1 = "\x1b[D"

CUB1 is a sequence for moving the cursor left one cell.

View Source
const CUD1 = "\x1b[B"

CUD1 is a sequence for moving the cursor down one cell.

View Source
const CUF1 = "\x1b[C"

CUF1 is a sequence for moving the cursor right one cell.

View Source
const CUU1 = "\x1b[A"

CUU1 is a sequence for moving the cursor up one cell.

View Source
const CursorDown1 = "\x1b[B"

CursorDown1 is a sequence for moving the cursor down one cell.

This is equivalent to CursorDown(1). Deprecated: use CUD1 instead.

View Source
const CursorHomePosition = "\x1b[H"

CursorHomePosition is a sequence for moving the cursor to the upper left corner of the scrolling region. This is equivalent to `CursorPosition(1, 1)`.

View Source
const CursorLeft1 = CUB1

CursorLeft1 is a sequence for moving the cursor left one cell.

This is equivalent to CursorLeft(1). Deprecated: use CUB1 instead.

View Source
const CursorOrigin = "\x1b[1;1H"

CursorOrigin is a sequence for moving the cursor to the upper left corner of the display. This is equivalent to `SetCursorPosition(1, 1)`.

Deprecated: use CursorHomePosition instead.

View Source
const CursorRight1 = CUF1

CursorRight1 is a sequence for moving the cursor right one cell.

This is equivalent to CursorRight(1). Deprecated: use CUF1 instead.

View Source
const CursorUp1 = "\x1b[A"

CursorUp1 is a sequence for moving the cursor up one cell.

This is equivalent to CursorUp(1). Deprecated: use CUU1 instead.

View Source
const DisableKittyKeyboard = "\x1b[>0u"

DisableKittyKeyboard is a sequence to push zero into the terminal Kitty Keyboard stack to disable the protocol.

This is equivalent to PushKittyKeyboard(0).

View Source
const DisableModifyOtherKeys = "\x1b[>4;0m"

DisableModifyOtherKeys disables the modifyOtherKeys mode.

CSI > 4 ; 0 m

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys Deprecated: use ResetModifyOtherKeys instead.

View Source
const EnableModifyOtherKeys1 = "\x1b[>4;1m"

EnableModifyOtherKeys1 enables the modifyOtherKeys mode 1.

CSI > 4 ; 1 m

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys Deprecated: use SetModifyOtherKeys1 instead.

View Source
const EnableModifyOtherKeys2 = "\x1b[>4;2m"

EnableModifyOtherKeys2 enables the modifyOtherKeys mode 2.

CSI > 4 ; 2 m

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys Deprecated: use SetModifyOtherKeys2 instead.

View Source
const Focus = "\x1b[I"

Focus is an escape sequence to notify the terminal that it has focus. This is used with FocusEventMode.

View Source
const HomeCursorPosition = CursorHomePosition

HomeCursorPosition is a sequence for moving the cursor to the upper left corner of the scrolling region. This is equivalent to `SetCursorPosition(1, 1)`. Deprecated: use CursorHomePosition instead.

View Source
const HorizontalTabSet = "\x1bH"

HorizontalTabSet (HTS) sets a horizontal tab stop at the current cursor column.

This is equivalent to HTS.

ESC H

See: https://vt100.net/docs/vt510-rm/HTS.html

View Source
const HorizontalVerticalHomePosition = "\x1b[f"

HorizontalVerticalHomePosition is a sequence for moving the cursor to the upper left corner of the scrolling region. This is equivalent to `HorizontalVerticalPosition(1, 1)`.

View Source
const Index = "\x1bD"

Index (IND) is an escape sequence for moving the cursor down one line in the same column. If the cursor is at the bottom margin, the screen scrolls up. This has the same effect as IND.

View Source
const LS1R = "\x1b~"

Locking Shift 1 Right (LS1R) shifts G1 into GR character set.

View Source
const LS2 = "\x1bn"

Locking Shift 2 (LS2) shifts G2 into GL character set.

View Source
const LS2R = "\x1b}"

Locking Shift 2 Right (LS2R) shifts G2 into GR character set.

View Source
const LS3 = "\x1bo"

Locking Shift 3 (LS3) shifts G3 into GL character set.

View Source
const LS3R = "\x1b|"

Locking Shift 3 Right (LS3R) shifts G3 into GR character set.

View Source
const MoveCursorOrigin = CursorOrigin

MoveCursorOrigin is a sequence for moving the cursor to the upper left corner of the display. This is equivalent to `SetCursorPosition(1, 1)`.

Deprecated: use CursorHomePosition instead.

View Source
const RequestBackgroundColor = "\x1b]11;?\x07"

RequestBackgroundColor is a sequence that requests the current default terminal background color.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

View Source
const RequestCursorColor = "\x1b]12;?\x07"

RequestCursorColor is a sequence that requests the current terminal cursor color.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

View Source
const RequestCursorPosition = "\x1b[6n"

RequestCursorPosition is an escape sequence that requests the current cursor position.

CSI 6 n

The terminal will report the cursor position as a CSI sequence in the following format:

CSI Pl ; Pc R

Where Pl is the line number and Pc is the column number. See: https://vt100.net/docs/vt510-rm/CPR.html

View Source
const RequestExtendedCursorPosition = "\x1b[?6n"

RequestExtendedCursorPosition (DECXCPR) is a sequence for requesting the cursor position report including the current page number.

CSI ? 6 n

The terminal will report the cursor position as a CSI sequence in the following format:

CSI ? Pl ; Pc ; Pp R

Where Pl is the line number, Pc is the column number, and Pp is the page number. See: https://vt100.net/docs/vt510-rm/DECXCPR.html

View Source
const RequestForegroundColor = "\x1b]10;?\x07"

RequestForegroundColor is a sequence that requests the current default terminal foreground color.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

View Source
const RequestKittyKeyboard = "\x1b[?u"

RequestKittyKeyboard is a sequence to request the terminal Kitty keyboard protocol enabled flags.

See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/

View Source
const RequestModifyOtherKeys = "\x1b[?4m"

RequestModifyOtherKeys requests the modifyOtherKeys mode.

CSI ? 4  m

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys Deprecated: use QueryModifyOtherKeys instead.

View Source
const RequestPrimaryClipboard = "\x1b]52;p;?\x07"

RequestPrimaryClipboard is a sequence for requesting the primary clipboard.

This is equivalent to RequestClipboard(PrimaryClipboard).

View Source
const RequestPrimaryDeviceAttributes = "\x1b[c"

RequestPrimaryDeviceAttributes is a control sequence that requests the terminal's primary device attributes (DA1).

CSI c

See https://vt100.net/docs/vt510-rm/DA1.html

View Source
const RequestSystemClipboard = "\x1b]52;c;?\x07"

RequestSystemClipboard is a sequence for requesting the system clipboard.

This is equivalent to RequestClipboard(SystemClipboard).

View Source
const RequestXTVersion = RequestNameVersion

RequestXTVersion is a control sequence that requests the terminal's XTVERSION. It responds with a DSR sequence identifying the version.

CSI > Ps q
DCS > | text ST

See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-PC-Style-Function-Keys Deprecated: use RequestNameVersion instead.

View Source
const ResetBackgroundColor = "\x1b]111\x07"

ResetBackgroundColor is a sequence that resets the default terminal background color.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

View Source
const ResetCursorColor = "\x1b]112\x07"

ResetCursorColor is a sequence that resets the terminal cursor color.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

View Source
const ResetForegroundColor = "\x1b]110\x07"

ResetForegroundColor is a sequence that resets the default terminal foreground color.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

View Source
const ResetPrimaryClipboard = "\x1b]52;p;\x07"

ResetPrimaryClipboard is a sequence for resetting the primary clipboard.

This is equivalent to ResetClipboard(PrimaryClipboard).

View Source
const ResetStyle = "\x1b[m"

ResetStyle is a SGR (Select Graphic Rendition) style sequence that resets all attributes. See: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters

View Source
const ResetSystemClipboard = "\x1b]52;c;\x07"

ResetSystemClipboard is a sequence for resetting the system clipboard.

This is equivalent to ResetClipboard(SystemClipboard).

View Source
const RestoreCursorPosition = "\x1b[u"

RestoreCursorPosition (RCP or SCORC) is a sequence for restoring the cursor position.

CSI u

This acts like Restore, except the cursor stays on the same page where the cursor was saved.

See: https://vt100.net/docs/vt510-rm/SCORC.html Deprecated: use RestoreCurrentCursorPosition instead.

View Source
const ReverseIndex = "\x1bM"

ReverseIndex (RI) is an escape sequence for moving the cursor up one line in the same column. If the cursor is at the top margin, the screen scrolls down.

This has the same effect as RI.

View Source
const SaveCursorPosition = "\x1b[s"

SaveCursorPosition (SCP or SCOSC) is a sequence for saving the cursor position.

CSI s

This acts like Save, except the page number where the cursor is located is not saved.

See: https://vt100.net/docs/vt510-rm/SCOSC.html Deprecated: use SaveCurrentCursorPosition instead.

Variables

This section is empty.

Functions

func CBT added in v0.5.0

func CBT(n int) string

CBT is an alias for CursorBackwardTab.

func CHA added in v0.5.0

func CHA(col int) string

CHA is an alias for CursorHorizontalAbsolute.

func CHT added in v0.5.0

func CHT(n int) string

CHT is an alias for CursorHorizontalForwardTab.

func CNL added in v0.5.0

func CNL(n int) string

CNL is an alias for CursorNextLine.

func CPL added in v0.5.0

func CPL(n int) string

CPL is an alias for CursorPreviousLine.

func CPR added in v0.5.0

func CPR(line, column int) string

CPR is an alias for CursorPositionReport.

func CUB added in v0.5.0

func CUB(n int) string

CUB is an alias for CursorBackward.

func CUD added in v0.5.0

func CUD(n int) string

CUD is an alias for CursorDown.

func CUF added in v0.5.0

func CUF(n int) string

CUF is an alias for CursorForward.

func CUP added in v0.5.0

func CUP(col, row int) string

CUP is an alias for CursorPosition.

func CUU added in v0.5.0

func CUU(n int) string

CUU is an alias for CursorUp.

func CursorBackward added in v0.5.0

func CursorBackward(n int) string

CursorBackward (CUB) returns a sequence for moving the cursor left n cells.

CSI n D

See: https://vt100.net/docs/vt510-rm/CUB.html

func CursorBackwardTab added in v0.5.0

func CursorBackwardTab(n int) string

CursorBackwardTab (CBT) returns a sequence for moving the cursor to the previous tab stop n times.

Default is 1.

CSI n Z

See: https://vt100.net/docs/vt510-rm/CBT.html

func CursorDown

func CursorDown(n int) string

CursorDown (CUD) returns a sequence for moving the cursor down n cells.

CSI n B

See: https://vt100.net/docs/vt510-rm/CUD.html

func CursorForward added in v0.5.0

func CursorForward(n int) string

CursorForward (CUF) returns a sequence for moving the cursor right n cells.

CSI n C

See: https://vt100.net/docs/vt510-rm/CUF.html

func CursorHorizontalAbsolute added in v0.5.0

func CursorHorizontalAbsolute(col int) string

CursorHorizontalAbsolute (CHA) returns a sequence for moving the cursor to the given column.

Default is 1.

CSI n G

See: https://vt100.net/docs/vt510-rm/CHA.html

func CursorHorizontalForwardTab added in v0.5.0

func CursorHorizontalForwardTab(n int) string

CursorHorizontalForwardTab (CHT) returns a sequence for moving the cursor to the next tab stop n times.

Default is 1.

CSI n I

See: https://vt100.net/docs/vt510-rm/CHT.html

func CursorInformationReport added in v0.5.0

func CursorInformationReport(values ...int) string

CursorInformationReport (DECCIR) is the response to a cursor information report request. It reports the cursor position, visual attributes, and character protection attributes. It also reports the status of origin mode DECOM and the current active character set.

The response is a list of values separated by a semicolon (;) character.

DCS 1 $ u D ... D ST

Where D is a decimal number representing a value.

See: https://vt100.net/docs/vt510-rm/DECCIR.html

func CursorLeft

func CursorLeft(n int) string

CursorLeft (CUB) returns a sequence for moving the cursor left n cells.

CSI n D

See: https://vt100.net/docs/vt510-rm/CUB.html Deprecated: use CursorBackward instead.

func CursorNextLine

func CursorNextLine(n int) string

CursorNextLine (CNL) returns a sequence for moving the cursor to the beginning of the next line n times.

CSI n E

See: https://vt100.net/docs/vt510-rm/CNL.html

func CursorPosition added in v0.5.0

func CursorPosition(col, row int) string

CursorPosition (CUP) returns a sequence for setting the cursor to the given row and column.

Default is 1,1.

CSI n ; m H

See: https://vt100.net/docs/vt510-rm/CUP.html

func CursorPositionReport added in v0.5.0

func CursorPositionReport(line, column int) string

CursorPositionReport (CPR) is a control sequence that reports the cursor's position.

CSI Pl ; Pc R

Where Pl is the line number and Pc is the column number.

See also https://vt100.net/docs/vt510-rm/CPR.html

func CursorPreviousLine

func CursorPreviousLine(n int) string

CursorPreviousLine (CPL) returns a sequence for moving the cursor to the beginning of the previous line n times.

CSI n F

See: https://vt100.net/docs/vt510-rm/CPL.html

func CursorRight

func CursorRight(n int) string

CursorRight (CUF) returns a sequence for moving the cursor right n cells.

CSI n C

See: https://vt100.net/docs/vt510-rm/CUF.html Deprecated: use CursorForward instead.

func CursorUp

func CursorUp(n int) string

CursorUp (CUU) returns a sequence for moving the cursor up n cells.

CSI n A

See: https://vt100.net/docs/vt510-rm/CUU.html

func DA1 added in v0.5.0

func DA1(attrs ...int) string

DA1 is an alias for PrimaryDeviceAttributes.

func DA2 added in v0.5.0

func DA2(attrs ...int) string

DA2 is an alias for SecondaryDeviceAttributes.

func DA3 added in v0.5.0

func DA3(unitID string) string

DA3 is an alias for TertiaryDeviceAttributes.

func DCH added in v0.5.0

func DCH(n int) string

DCH is an alias for DeleteCharacter.

func DECCIR added in v0.5.0

func DECCIR(values ...int) string

DECCIR is an alias for CursorInformationReport.

func DECRPM added in v0.5.0

func DECRPM(mode Mode, value ModeSetting) string

DECRPM is an alias for ReportMode.

func DECRQM added in v0.5.0

func DECRQM(m Mode) string

DECRQM is an alias for RequestMode.

func DECRQPSR added in v0.5.0

func DECRQPSR(n int) string

DECRQPSR is an alias for RequestPresentationStateReport.

func DECSCUSR added in v0.5.0

func DECSCUSR(style int) string

DECSCUSR is an alias for SetCursorStyle.

func DECSLRM added in v0.5.0

func DECSLRM(left, right int) string

DECSLRM is an alias for SetLeftRightMargins.

func DECSTBM added in v0.5.0

func DECSTBM(top, bot int) string

DECSTBM is an alias for SetTopBottomMargins.

func DECTABSR added in v0.5.0

func DECTABSR(stops ...int) string

DECTABSR is an alias for TabStopReport.

func DECXCPR added in v0.5.0

func DECXCPR(line, column, page int) string

DECXCPR is an alias for ExtendedCursorPositionReport.

func DL added in v0.5.0

func DL(n int) string

DL is an alias for DeleteLine.

func DSR added in v0.5.0

func DSR(status Status) string

DSR is an alias for DeviceStatusReport.

func DecodeSequence added in v0.2.0

func DecodeSequence[T string | []byte](b T, state byte, p *Parser) (seq T, width int, n int, newState byte)

DecodeSequence decodes the first ANSI escape sequence or a printable grapheme from the given data. It returns the sequence slice, the number of bytes read, the cell width for each sequence, and the new state.

The cell width will always be 0 for control and escape sequences, 1 for ASCII printable characters, and the number of cells other Unicode characters occupy. It uses the uniseg package to calculate the width of Unicode graphemes and characters. This means it will always do grapheme clustering (mode 2027).

Passing a non-nil *Parser as the last argument will allow the decoder to collect sequence parameters, data, and commands. The parser cmd will have the packed command value that contains intermediate and marker characters. In the case of a OSC sequence, the cmd will be the OSC command number. Use Command and Parameter types to unpack command intermediates and markers as well as parameters.

Zero Command means the CSI, DCS, or ESC sequence is invalid. Moreover, checking the validity of other data sequences, OSC, DCS, etc, will require checking for the returned sequence terminator bytes such as ST (ESC \\) and BEL).

We store the command byte in Command in the most significant byte, the marker byte in the next byte, and the intermediate byte in the least significant byte. This is done to avoid using a struct to store the command and its intermediates and markers. The command byte is always the least significant byte i.e. [Cmd & 0xff]. Use the Command type to unpack the command, intermediate, and marker bytes. Note that we only collect the last marker character and intermediate byte.

The [p.Params] slice will contain the parameters of the sequence. Any sub-parameter will have the parser.HasMoreFlag set. Use the Parameter type to unpack the parameters.

Example:

var state byte // the initial state is always zero [NormalState]
p := NewParser(32, 1024) // create a new parser with a 32 params buffer and 1024 data buffer (optional)
input := []byte("\x1b[31mHello, World!\x1b[0m")
for len(input) > 0 {
	seq, width, n, newState := DecodeSequence(input, state, p)
	log.Printf("seq: %q, width: %d", seq, width)
	state = newState
	input = input[n:]
}

func DeleteCharacter added in v0.5.0

func DeleteCharacter(n int) string

DeleteCharacter (DCH) deletes n characters at the current cursor position. As the characters are deleted, the remaining characters move to the left and the cursor remains at the same position.

Default is 1.

CSI Pn P

See: https://vt100.net/docs/vt510-rm/DCH.html

func DeleteLine

func DeleteLine(n int) string

DeleteLine (DL) deletes n lines at the current cursor position. Existing lines are moved up.

CSI Pn M

See: https://vt100.net/docs/vt510-rm/DL.html

func DeviceStatusReport added in v0.5.0

func DeviceStatusReport(statues ...Status) string

DeviceStatusReport (DSR) is a control sequence that reports the terminal's status. The terminal responds with a DSR sequence.

CSI Ps n
CSI ? Ps n

If one of the statuses is a DECStatus, the sequence will use the DEC format.

See also https://vt100.net/docs/vt510-rm/DSR.html

func ECH added in v0.5.0

func ECH(n int) string

ECH is an alias for EraseCharacter.

func ED added in v0.5.0

func ED(n int) string

ED is an alias for EraseDisplay.

func EL added in v0.5.0

func EL(n int) string

EL is an alias for EraseLine.

func Equal added in v0.2.0

func Equal[T string | []byte](a, b T) bool

Equal returns true if the given byte slices are equal.

func EraseCharacter added in v0.5.0

func EraseCharacter(n int) string

EraseCharacter (ECH) returns a sequence for erasing n characters and moving the cursor to the right. This doesn't affect other cell attributes.

Default is 1.

CSI n X

See: https://vt100.net/docs/vt510-rm/ECH.html

func EraseDisplay

func EraseDisplay(n int) string

EraseDisplay (ED) clears the display or parts of the display. A screen is the shown part of the terminal display excluding the scrollback buffer. Possible values:

Default is 0.

 0: Clear from cursor to end of screen.
 1: Clear from cursor to beginning of the screen.
 2: Clear entire screen (and moves cursor to upper left on DOS).
 3: Clear entire display which delete all lines saved in the scrollback buffer (xterm).

CSI <n> J

See: https://vt100.net/docs/vt510-rm/ED.html

func EraseLine

func EraseLine(n int) string

EraseLine (EL) clears the current line or parts of the line. Possible values:

0: Clear from cursor to end of line.
1: Clear from cursor to beginning of the line.
2: Clear entire line.

The cursor position is not affected.

CSI <n> K

See: https://vt100.net/docs/vt510-rm/EL.html

func Execute

func Execute(w io.Writer, s string) (int, error)

Execute is a function that "execute" the given escape sequence by writing it to the provided output writter.

This is a syntactic sugar over io.WriteString.

func ExtendedCursorPositionReport added in v0.5.0

func ExtendedCursorPositionReport(line, column, page int) string

ExtendedCursorPositionReport (DECXCPR) is a control sequence that reports the cursor's position along with the page number (optional).

CSI ? Pl ; Pc R
CSI ? Pl ; Pc ; Pv R

Where Pl is the line number, Pc is the column number, and Pv is the page number.

If the page number is zero or negative, the returned sequence won't include the page number.

See also https://vt100.net/docs/vt510-rm/DECXCPR.html

func FirstGraphemeCluster added in v0.2.0

func FirstGraphemeCluster[T string | []byte](b T, state int) (T, T, int, int)

FirstGraphemeCluster returns the first grapheme cluster in the given string or byte slice. This is a syntactic sugar function that wraps uniseg.FirstGraphemeClusterInString and uniseg.FirstGraphemeCluster.

func HPA added in v0.5.0

func HPA(col int) string

HPA is an alias for HorizontalPositionAbsolute.

func HPR added in v0.5.0

func HPR(n int) string

HPR is an alias for HorizontalPositionRelative.

func HVP added in v0.5.0

func HVP(col, row int) string

HVP is an alias for HorizontalVerticalPosition.

func Hardwrap

func Hardwrap(s string, limit int, preserveSpace bool) string

Hardwrap wraps a string or a block of text to a given line length, breaking word boundaries. This will preserve ANSI escape codes and will account for wide-characters in the string. When preserveSpace is true, spaces at the beginning of a line will be preserved.

func HasApcPrefix added in v0.2.0

func HasApcPrefix[T string | []byte](b T) bool

HasApcPrefix returns true if the given byte slice has an APC prefix.

func HasCsiPrefix added in v0.2.0

func HasCsiPrefix[T string | []byte](b T) bool

HasCsiPrefix returns true if the given byte slice has a CSI prefix.

func HasDcsPrefix added in v0.2.0

func HasDcsPrefix[T string | []byte](b T) bool

HasDcsPrefix returns true if the given byte slice has a DCS prefix.

func HasEscPrefix added in v0.2.0

func HasEscPrefix[T string | []byte](b T) bool

HasEscPrefix returns true if the given byte slice has an ESC prefix.

func HasOscPrefix added in v0.2.0

func HasOscPrefix[T string | []byte](b T) bool

HasOscPrefix returns true if the given byte slice has an OSC prefix.

func HasPmPrefix added in v0.2.0

func HasPmPrefix[T string | []byte](b T) bool

HasPmPrefix returns true if the given byte slice has a PM prefix.

func HasPrefix added in v0.2.0

func HasPrefix[T string | []byte](b, prefix T) bool

HasPrefix returns true if the given byte slice has prefix.

func HasSosPrefix added in v0.2.0

func HasSosPrefix[T string | []byte](b T) bool

HasSosPrefix returns true if the given byte slice has a SOS prefix.

func HasStPrefix added in v0.2.0

func HasStPrefix[T string | []byte](b T) bool

HasStPrefix returns true if the given byte slice has a ST prefix.

func HasSuffix added in v0.2.0

func HasSuffix[T string | []byte](b, suffix T) bool

HasSuffix returns true if the given byte slice has suffix.

func HorizontalPositionAbsolute added in v0.5.0

func HorizontalPositionAbsolute(col int) string

HorizontalPositionAbsolute (HPA) returns a sequence for moving the cursor to the given column. This has the same effect as CUP.

Default is 1.

CSI n `

See: https://vt100.net/docs/vt510-rm/HPA.html

func HorizontalPositionRelative added in v0.5.0

func HorizontalPositionRelative(n int) string

HorizontalPositionRelative (HPR) returns a sequence for moving the cursor right n columns relative to the current position. This has the same effect as CUP.

Default is 1.

CSI n a

See: https://vt100.net/docs/vt510-rm/HPR.html

func HorizontalVerticalPosition added in v0.5.0

func HorizontalVerticalPosition(col, row int) string

HorizontalVerticalPosition (HVP) returns a sequence for moving the cursor to the given row and column.

Default is 1,1.

CSI n ; m f

This has the same effect as CursorPosition.

See: https://vt100.net/docs/vt510-rm/HVP.html

func ICH added in v0.5.0

func ICH(n int) string

ICH is an alias for InsertCharacter.

func IL added in v0.5.0

func IL(n int) string

IL is an alias for InsertLine.

func InsertCharacter added in v0.5.0

func InsertCharacter(n int) string

InsertCharacter (ICH) inserts n blank characters at the current cursor position. Existing characters move to the right. Characters moved past the right margin are lost. ICH has no effect outside the scrolling margins.

Default is 1.

CSI Pn @

See: https://vt100.net/docs/vt510-rm/ICH.html

func InsertLine

func InsertLine(n int) string

InsertLine (IL) inserts n blank lines at the current cursor position. Existing lines are moved down.

CSI Pn L

See: https://vt100.net/docs/vt510-rm/IL.html

func KeyModifierOptions added in v0.5.0

func KeyModifierOptions(p int, vs ...int) string

KeyModifierOptions (XTMODKEYS) sets/resets xterm key modifier options.

Default is 0.

CSI > Pp m
CSI > Pp ; Pv m

If Pv is omitted, the resource is reset to its initial value.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_

func KittyKeyboard added in v0.2.0

func KittyKeyboard(flags, mode int) string

KittyKeyboard returns a sequence to request keyboard enhancements from the terminal. The flags argument is a bitmask of the Kitty keyboard protocol flags. While mode specifies how the flags should be interpreted.

Possible values for flags mask:

1:  Disambiguate escape codes
2:  Report event types
4:  Report alternate keys
8:  Report all keys as escape codes
16: Report associated text

Possible values for mode:

1: Set given flags and unset all others
2: Set given flags and keep existing flags unchanged
3: Unset given flags and keep existing flags unchanged

See https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement

func ModifyOtherKeys added in v0.2.0

func ModifyOtherKeys(mode int) string

ModifyOtherKeys returns a sequence that sets XTerm modifyOtherKeys mode. The mode argument specifies the mode to set.

0: Disable modifyOtherKeys mode.
1: Enable modifyOtherKeys mode 1.
2: Enable modifyOtherKeys mode 2.

CSI > 4 ; mode m

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys Deprecated: use SetModifyOtherKeys1 or SetModifyOtherKeys2 instead.

func MouseSgr added in v0.5.0

func MouseSgr(b byte, x, y int, release bool) string

MouseSgr returns an escape sequence representing a mouse event in SGR mode.

CSI < Cb ; Cx ; Cy M
CSI < Cb ; Cx ; Cy m (release)

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking

func MouseX10 added in v0.5.0

func MouseX10(b byte, x, y int) string

MouseX10 returns an escape sequence representing a mouse event in X10 mode. Note that this requires the terminal support X10 mouse modes.

CSI M Cb Cx Cy

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking

func MoveCursor deprecated

func MoveCursor(col, row int) string

MoveCursor (CUP) returns a sequence for setting the cursor to the given row and column.

CSI n ; m H

See: https://vt100.net/docs/vt510-rm/CUP.html

Deprecated: use CursorPosition instead.

func Notify added in v0.4.3

func Notify(s string) string

Notify sends a desktop notification using iTerm's OSC 9.

OSC 9 ; Mc ST
OSC 9 ; Mc BEL

Where Mc is the notification body.

See: https://iterm2.com/documentation-escape-codes.html

func PanDown added in v0.5.0

func PanDown(n int) string

PanDown is an alias for ScrollUp.

func PanUp added in v0.5.0

func PanUp(n int) string

PanUp is an alias for ScrollDown.

func Params

func Params(p []byte) [][]uint

Params parses and returns a list of control sequence parameters.

Parameters are positive integers separated by semicolons. Empty parameters default to zero. Parameters can have sub-parameters separated by colons.

Any non-parameter bytes are ignored. This includes bytes that are not in the range of 0x30-0x3B.

See ECMA-48 § 5.4.1.

func PopKittyKeyboard

func PopKittyKeyboard(n int) string

PopKittyKeyboard returns a sequence to pop n number of flags from the terminal Kitty Keyboard stack.

CSI < flags u

See https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement

func PrimaryDeviceAttributes added in v0.5.0

func PrimaryDeviceAttributes(attrs ...int) string

PrimaryDeviceAttributes (DA1) is a control sequence that reports the terminal's primary device attributes.

CSI c
CSI 0 c
CSI ? Ps ; ... c

If no attributes are given, or if the attribute is 0, this function returns the request sequence. Otherwise, it returns the response sequence.

See https://vt100.net/docs/vt510-rm/DA1.html

func PushKittyKeyboard

func PushKittyKeyboard(flags int) string

PushKittyKeyboard returns a sequence to push the given flags to the terminal Kitty Keyboard stack.

Possible values for flags mask:

0:  Disable all features
1:  Disambiguate escape codes
2:  Report event types
4:  Report alternate keys
8:  Report all keys as escape codes
16: Report associated text

CSI > flags u

See https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement

func PutParser added in v0.3.1

func PutParser(p *Parser)

PutParser returns a parser to a sync pool. The parser is reset automatically.

func QueryKeyModifierOptions added in v0.5.0

func QueryKeyModifierOptions(pp int) string

QueryKeyModifierOptions (XTQMODKEYS) requests xterm key modifier options.

Default is 0.

CSI ? Pp m

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_

func REP added in v0.5.0

func REP(n int) string

REP is an alias for RepeatPreviousCharacter.

func RM added in v0.5.0

func RM(modes ...Mode) string

RM is an alias for ResetMode.

func RepeatPreviousCharacter added in v0.5.0

func RepeatPreviousCharacter(n int) string

RepeatPreviousCharacter (REP) repeats the previous character n times. This is identical to typing the same character n times.

Default is 1.

CSI Pn b

See: ECMA-48 § 8.3.103

func ReportMode added in v0.5.0

func ReportMode(mode Mode, value ModeSetting) string

ReportMode (DECRPM) returns a sequence that the terminal sends to the host in response to a mode request DECRQM.

ANSI format:

CSI Pa ; Ps ; $ y

DEC format:

CSI ? Pa ; Ps $ y

Where Pa is the mode number, and Ps is the mode value.

0: Not recognized
1: Set
2: Reset
3: Permanent set
4: Permanent reset

See: https://vt100.net/docs/vt510-rm/DECRPM.html

func RequestClipboard

func RequestClipboard(c byte) string

RequestClipboard returns a sequence for requesting the clipboard.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

func RequestMode added in v0.5.0

func RequestMode(m Mode) string

RequestMode (DECRQM) returns a sequence to request a mode from the terminal. The terminal responds with a report mode function DECRPM.

ANSI format:

CSI Pa $ p

DEC format:

CSI ? Pa $ p

See: https://vt100.net/docs/vt510-rm/DECRQM.html

func RequestPresentationStateReport added in v0.5.0

func RequestPresentationStateReport(n int) string

RequestPresentationStateReport (DECRQPSR) requests the terminal to send a report of the presentation state. This includes the cursor information DECCIR, and tab stop DECTABSR reports.

Default is 0.

Possible values: 0: Error, request ignored. 1: Cursor information report DECCIR. 2: Tab stop report DECTABSR.

CSI Ps $ w

See: https://vt100.net/docs/vt510-rm/DECRQPSR.html

func RequestTermcap

func RequestTermcap(caps ...string) string

RequestTermcap is an alias for XTGETTCAP.

func RequestTerminfo added in v0.5.0

func RequestTerminfo(caps ...string) string

RequestTerminfo is an alias for XTGETTCAP.

func ResetClipboard

func ResetClipboard(c byte) string

ResetClipboard returns a sequence for resetting the clipboard.

This is equivalent to SetClipboard(c, "").

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

func ResetHyperlink(params ...string) string

ResetHyperlink returns a sequence for resetting the hyperlink.

This is equivalent to SetHyperlink("", params...).

See: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda

func ResetKeyModifierOptions added in v0.5.0

func ResetKeyModifierOptions(pp int) string

ResetKeyModifierOptions resets xterm key modifier options. This is an alias for KeyModifierOptions.

func ResetMode added in v0.5.0

func ResetMode(modes ...Mode) string

ResetMode (RM) returns a sequence to reset a mode. The mode arguments are a list of modes to reset.

If one of the modes is a DECMode, the sequence will use the DEC format.

ANSI format:

CSI Pd ; ... ; Pd l

DEC format:

CSI ? Pd ; ... ; Pd l

See: https://vt100.net/docs/vt510-rm/RM.html

func SCS added in v0.5.0

func SCS(gset byte, charset byte) string

SCS is an alias for SelectCharacterSet.

func SD added in v0.5.0

func SD(n int) string

SD is an alias for ScrollDown.

func SGR added in v0.5.0

func SGR(ps ...Attr) string

SGR is an alias for SelectGraphicRendition.

func SM added in v0.5.0

func SM(modes ...Mode) string

SM is an alias for SetMode.

func SU added in v0.5.0

func SU(n int) string

SU is an alias for ScrollUp.

func ScreenPassthrough

func ScreenPassthrough(seq string, limit int) string

ScreenPassthrough wraps the given ANSI sequence in a DCS passthrough sequence to be sent to the outer terminal. This is used to send raw escape sequences to the outer terminal when running inside GNU Screen.

DCS <data> ST

Note: Screen limits the length of string sequences to 768 bytes (since 2014). Use zero to indicate no limit, otherwise, this will chunk the returned string into limit sized chunks.

See: https://www.gnu.org/software/screen/manual/screen.html#String-Escapes See: https://git.savannah.gnu.org/cgit/screen.git/tree/src/screen.h?id=c184c6ec27683ff1a860c45be5cf520d896fd2ef#n44

func ScrollDown

func ScrollDown(n int) string

ScrollDown (SD) scrolls the screen down n lines. New lines are added at the top of the screen.

CSI Pn T

See: https://vt100.net/docs/vt510-rm/SD.html

func ScrollUp

func ScrollUp(n int) string

ScrollUp (SU) scrolls the screen up n lines. New lines are added at the bottom of the screen.

CSI Pn S

See: https://vt100.net/docs/vt510-rm/SU.html

func SecondaryDeviceAttributes added in v0.5.0

func SecondaryDeviceAttributes(attrs ...int) string

SecondaryDeviceAttributes (DA2) is a control sequence that reports the terminal's secondary device attributes.

CSI > c
CSI > 0 c
CSI > Ps ; ... c

See https://vt100.net/docs/vt510-rm/DA2.html

func SelectCharacterSet added in v0.5.0

func SelectCharacterSet(gset byte, charset byte) string

SelectCharacterSet sets the G-set character designator to the specified character set.

ESC Ps Pd

Where Ps is the G-set character designator, and Pd is the identifier. For 94-character sets, the designator can be one of:

  • ( G0
  • ) G1
  • * G2
  • + G3

For 96-character sets, the designator can be one of:

  • - G1
  • . G2
  • / G3

Some common 94-character sets are:

  • 0 DEC Special Drawing Set
  • A United Kingdom (UK)
  • B United States (USASCII)

Examples:

ESC ( B  Select character set G0 = United States (USASCII)
ESC ( 0  Select character set G0 = Special Character and Line Drawing Set
ESC ) 0  Select character set G1 = Special Character and Line Drawing Set
ESC * A  Select character set G2 = United Kingdom (UK)

See: https://vt100.net/docs/vt510-rm/SCS.html

func SelectGraphicRendition added in v0.5.0

func SelectGraphicRendition(ps ...Attr) string

Select Graphic Rendition (SGR) is a command that sets display attributes.

Default is 0.

CSI Ps ; Ps ... m

See: https://vt100.net/docs/vt510-rm/SGR.html

func SetBackgroundColor

func SetBackgroundColor(c color.Color) string

SetBackgroundColor returns a sequence that sets the default terminal background color.

OSC 11 ; color ST
OSC 11 ; color BEL

Where color is the encoded color number.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

func SetClipboard

func SetClipboard(c byte, d string) string

SetClipboard returns a sequence for manipulating the clipboard.

OSC 52 ; Pc ; Pd ST
OSC 52 ; Pc ; Pd BEL

Where Pc is the clipboard name and Pd is the base64 encoded data. Empty data or invalid base64 data will reset the clipboard.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

func SetCursorColor

func SetCursorColor(c color.Color) string

SetCursorColor returns a sequence that sets the terminal cursor color.

OSC 12 ; color ST
OSC 12 ; color BEL

Where color is the encoded color number.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

func SetCursorPosition added in v0.4.0

func SetCursorPosition(col, row int) string

SetCursorPosition (CUP) returns a sequence for setting the cursor to the given row and column.

CSI n ; m H

See: https://vt100.net/docs/vt510-rm/CUP.html Deprecated: use CursorPosition instead.

func SetCursorStyle added in v0.2.2

func SetCursorStyle(style int) string

SetCursorStyle (DECSCUSR) returns a sequence for changing the cursor style.

Default is 1.

CSI Ps SP q

Where Ps is the cursor style:

0: Blinking block
1: Blinking block (default)
2: Steady block
3: Blinking underline
4: Steady underline
5: Blinking bar (xterm)
6: Steady bar (xterm)

See: https://vt100.net/docs/vt510-rm/DECSCUSR.html See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81

func SetForegroundColor

func SetForegroundColor(c color.Color) string

SetForegroundColor returns a sequence that sets the default terminal foreground color.

OSC 10 ; color ST
OSC 10 ; color BEL

Where color is the encoded color number.

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

func SetHyperlink(uri string, params ...string) string

SetHyperlink returns a sequence for starting a hyperlink.

OSC 8 ; Params ; Uri ST
OSC 8 ; Params ; Uri BEL

To reset the hyperlink, omit the URI.

See: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda

func SetIconName

func SetIconName(s string) string

SetIconName returns a sequence for setting the icon name.

OSC 1 ; title ST
OSC 1 ; title BEL

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Operating-System-Commands

func SetIconNameWindowTitle

func SetIconNameWindowTitle(s string) string

SetIconNameWindowTitle returns a sequence for setting the icon name and window title.

OSC 0 ; title ST
OSC 0 ; title BEL

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Operating-System-Commands

func SetKeyModifierOptions added in v0.5.0

func SetKeyModifierOptions(pp int, pv int) string

SetKeyModifierOptions sets xterm key modifier options. This is an alias for KeyModifierOptions.

func SetLeftRightMargins added in v0.5.0

func SetLeftRightMargins(left, right int) string

SetLeftRightMargins (DECSLRM) sets the left and right margins for the scrolling region.

Default is 1 and the right of the screen.

CSI Pl ; Pr s

See: https://vt100.net/docs/vt510-rm/DECSLRM.html

func SetMode added in v0.5.0

func SetMode(modes ...Mode) string

SetMode (SM) returns a sequence to set a mode. The mode arguments are a list of modes to set.

If one of the modes is a DECMode, the sequence will use the DEC format.

ANSI format:

CSI Pd ; ... ; Pd h

DEC format:

CSI ? Pd ; ... ; Pd h

See: https://vt100.net/docs/vt510-rm/SM.html

func SetPointerShape added in v0.2.2

func SetPointerShape(shape string) string

SetPointerShape returns a sequence for changing the mouse pointer cursor shape. Use "default" for the default pointer shape.

OSC 22 ; Pt ST
OSC 22 ; Pt BEL

Where Pt is the pointer shape name. The name can be anything that the operating system can understand. Some common names are:

  • copy
  • crosshair
  • default
  • ew-resize
  • n-resize
  • text
  • wait

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Operating-System-Commands

func SetPrimaryClipboard

func SetPrimaryClipboard(d string) string

SetPrimaryClipboard returns a sequence for setting the primary clipboard.

This is equivalent to SetClipboard(PrimaryClipboard, d).

func SetScrollingRegion

func SetScrollingRegion(t, b int) string

SetScrollingRegion (DECSTBM) sets the top and bottom margins for the scrolling region. The default is the entire screen.

CSI <top> ; <bottom> r

See: https://vt100.net/docs/vt510-rm/DECSTBM.html Deprecated: use SetTopBottomMargins instead.

func SetSystemClipboard

func SetSystemClipboard(d string) string

SetSystemClipboard returns a sequence for setting the system clipboard.

This is equivalent to SetClipboard(SystemClipboard, d).

func SetTopBottomMargins added in v0.5.0

func SetTopBottomMargins(top, bot int) string

SetTopBottomMargins (DECSTBM) sets the top and bottom margins for the scrolling region. The default is the entire screen.

Default is 1 and the bottom of the screen.

CSI Pt ; Pb r

See: https://vt100.net/docs/vt510-rm/DECSTBM.html

func SetWindowTitle

func SetWindowTitle(s string) string

SetWindowTitle returns a sequence for setting the window title.

OSC 2 ; title ST
OSC 2 ; title BEL

See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Operating-System-Commands

func StringWidth

func StringWidth(s string) int

StringWidth returns the width of a string in cells. This is the number of cells that the string will occupy when printed in a terminal. ANSI escape codes are ignored and wide characters (such as East Asians and emojis) are accounted for.

func Strip

func Strip(s string) string

Strip removes ANSI escape codes from a string.

func TBC added in v0.5.0

func TBC(n int) string

TBC is an alias for TabClear.

func TabClear added in v0.5.0

func TabClear(n int) string

TabClear (TBC) clears tab stops.

Default is 0.

Possible values: 0: Clear tab stop at the current column. (default) 3: Clear all tab stops.

CSI Pn g

See: https://vt100.net/docs/vt510-rm/TBC.html

func TabStopReport added in v0.5.0

func TabStopReport(stops ...int) string

TabStopReport (DECTABSR) is the response to a tab stop report request. It reports the tab stops set in the terminal.

The response is a list of tab stops separated by a slash (/) character.

DCS 2 $ u D ... D ST

Where D is a decimal number representing a tab stop.

See: https://vt100.net/docs/vt510-rm/DECTABSR.html

func TertiaryDeviceAttributes added in v0.5.0

func TertiaryDeviceAttributes(unitID string) string

TertiaryDeviceAttributes (DA3) is a control sequence that reports the terminal's tertiary device attributes.

CSI = c
CSI = 0 c
DCS ! | Text ST

Where Text is the unit ID for the terminal.

If no unit ID is given, or if the unit ID is 0, this function returns the request sequence. Otherwise, it returns the response sequence.

See https://vt100.net/docs/vt510-rm/DA3.html

func TmuxPassthrough

func TmuxPassthrough(seq string) string

TmuxPassthrough wraps the given ANSI sequence in a special DCS passthrough sequence to be sent to the outer terminal. This is used to send raw escape sequences to the outer terminal when running inside Tmux.

DCS tmux ; <escaped-data> ST

Where <escaped-data> is the given sequence in which all occurrences of ESC (0x1b) are doubled i.e. replaced with ESC ESC (0x1b 0x1b).

Note: this needs the `allow-passthrough` option to be set to `on`.

See: https://github.com/tmux/tmux/wiki/FAQ#what-is-the-passthrough-escape-sequence-and-how-do-i-use-it

func Truncate

func Truncate(s string, length int, tail string) string

Truncate truncates a string to a given length, adding a tail to the end if the string is longer than the given length. This function is aware of ANSI escape codes and will not break them, and accounts for wide-characters (such as East Asians and emojis).

func VPA added in v0.5.0

func VPA(row int) string

VPA is an alias for VerticalPositionAbsolute.

func VPR added in v0.5.0

func VPR(n int) string

VPR is an alias for VerticalPositionRelative.

func VerticalPositionAbsolute added in v0.5.0

func VerticalPositionAbsolute(row int) string

VerticalPositionAbsolute (VPA) returns a sequence for moving the cursor to the given row.

Default is 1.

CSI n d

See: https://vt100.net/docs/vt510-rm/VPA.html

func VerticalPositionRelative added in v0.5.0

func VerticalPositionRelative(n int) string

VerticalPositionRelative (VPR) returns a sequence for moving the cursor down n rows relative to the current position.

Default is 1.

CSI n e

See: https://vt100.net/docs/vt510-rm/VPR.html

func Wordwrap

func Wordwrap(s string, limit int, breakpoints string) string

Wordwrap wraps a string or a block of text to a given line length, not breaking word boundaries. This will preserve ANSI escape codes and will account for wide-characters in the string. The breakpoints string is a list of characters that are considered breakpoints for word wrapping. A hyphen (-) is always considered a breakpoint.

Note: breakpoints must be a string of 1-cell wide rune characters.

func Wrap

func Wrap(s string, limit int, breakpoints string) string

Wrap wraps a string or a block of text to a given line length, breaking word boundaries if necessary. This will preserve ANSI escape codes and will account for wide-characters in the string. The breakpoints string is a list of characters that are considered breakpoints for word wrapping. A hyphen (-) is always considered a breakpoint.

Note: breakpoints must be a string of 1-cell wide rune characters.

func XTGETTCAP added in v0.5.0

func XTGETTCAP(caps ...string) string

RequestTermcap (XTGETTCAP) requests Termcap/Terminfo strings.

DCS + q <Pt> ST

Where <Pt> is a list of Termcap/Terminfo capabilities, encoded in 2-digit hexadecimals, separated by semicolons.

See: https://man7.org/linux/man-pages/man5/terminfo.5.html See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

func XTMODKEYS added in v0.5.0

func XTMODKEYS(p int, vs ...int) string

XTMODKEYS is an alias for KeyModifierOptions.

func XTQMODKEYS added in v0.5.0

func XTQMODKEYS(pp int) string

XTQMODKEYS is an alias for QueryKeyModifierOptions.

Types

type ANSIMode added in v0.5.0

type ANSIMode int //nolint:revive

ANSIMode represents an ANSI terminal mode.

func (ANSIMode) Mode added in v0.5.0

func (m ANSIMode) Mode() int

Mode returns the ANSI mode as an integer.

type ANSIStatus added in v0.5.0

type ANSIStatus int //nolint:revive

ANSIStatus represents an ANSI terminal status report.

func (ANSIStatus) Status added in v0.5.0

func (s ANSIStatus) Status() int

Status returns the status report identifier.

type ApcSequence

type ApcSequence struct {
	// Data contains the raw data of the sequence.
	Data []byte
}

ApcSequence represents an APC sequence.

func (ApcSequence) Bytes

func (s ApcSequence) Bytes() []byte

Bytes implements Sequence.

func (ApcSequence) Clone

func (a ApcSequence) Clone() Sequence

Clone returns a deep copy of the APC sequence.

func (ApcSequence) String

func (s ApcSequence) String() string

String implements Sequence.

type Attr

type Attr = int

Attr is a SGR (Select Graphic Rendition) style attribute.

const (
	ResetAttr                        Attr = 0
	BoldAttr                         Attr = 1
	FaintAttr                        Attr = 2
	ItalicAttr                       Attr = 3
	UnderlineAttr                    Attr = 4
	SlowBlinkAttr                    Attr = 5
	RapidBlinkAttr                   Attr = 6
	ReverseAttr                      Attr = 7
	ConcealAttr                      Attr = 8
	StrikethroughAttr                Attr = 9
	NoBoldAttr                       Attr = 21 // Some terminals treat this as double underline.
	NormalIntensityAttr              Attr = 22
	NoItalicAttr                     Attr = 23
	NoUnderlineAttr                  Attr = 24
	NoBlinkAttr                      Attr = 25
	NoReverseAttr                    Attr = 27
	NoConcealAttr                    Attr = 28
	NoStrikethroughAttr              Attr = 29
	BlackForegroundColorAttr         Attr = 30
	RedForegroundColorAttr           Attr = 31
	GreenForegroundColorAttr         Attr = 32
	YellowForegroundColorAttr        Attr = 33
	BlueForegroundColorAttr          Attr = 34
	MagentaForegroundColorAttr       Attr = 35
	CyanForegroundColorAttr          Attr = 36
	WhiteForegroundColorAttr         Attr = 37
	ExtendedForegroundColorAttr      Attr = 38
	DefaultForegroundColorAttr       Attr = 39
	BlackBackgroundColorAttr         Attr = 40
	RedBackgroundColorAttr           Attr = 41
	GreenBackgroundColorAttr         Attr = 42
	YellowBackgroundColorAttr        Attr = 43
	BlueBackgroundColorAttr          Attr = 44
	MagentaBackgroundColorAttr       Attr = 45
	CyanBackgroundColorAttr          Attr = 46
	WhiteBackgroundColorAttr         Attr = 47
	ExtendedBackgroundColorAttr      Attr = 48
	DefaultBackgroundColorAttr       Attr = 49
	ExtendedUnderlineColorAttr       Attr = 58
	DefaultUnderlineColorAttr        Attr = 59
	BrightBlackForegroundColorAttr   Attr = 90
	BrightRedForegroundColorAttr     Attr = 91
	BrightGreenForegroundColorAttr   Attr = 92
	BrightYellowForegroundColorAttr  Attr = 93
	BrightBlueForegroundColorAttr    Attr = 94
	BrightMagentaForegroundColorAttr Attr = 95
	BrightCyanForegroundColorAttr    Attr = 96
	BrightWhiteForegroundColorAttr   Attr = 97
	BrightBlackBackgroundColorAttr   Attr = 100
	BrightRedBackgroundColorAttr     Attr = 101
	BrightGreenBackgroundColorAttr   Attr = 102
	BrightYellowBackgroundColorAttr  Attr = 103
	BrightBlueBackgroundColorAttr    Attr = 104
	BrightMagentaBackgroundColorAttr Attr = 105
	BrightCyanBackgroundColorAttr    Attr = 106
	BrightWhiteBackgroundColorAttr   Attr = 107

	RGBColorIntroducerAttr      Attr = 2
	ExtendedColorIntroducerAttr Attr = 5
)

SGR (Select Graphic Rendition) style attributes. See: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters

type BasicColor

type BasicColor uint8

BasicColor is an ANSI 3-bit or 4-bit color with a value from 0 to 15.

const (
	// Black is the ANSI black color.
	Black BasicColor = iota

	// Red is the ANSI red color.
	Red

	// Green is the ANSI green color.
	Green

	// Yellow is the ANSI yellow color.
	Yellow

	// Blue is the ANSI blue color.
	Blue

	// Magenta is the ANSI magenta color.
	Magenta

	// Cyan is the ANSI cyan color.
	Cyan

	// White is the ANSI white color.
	White

	// BrightBlack is the ANSI bright black color.
	BrightBlack

	// BrightRed is the ANSI bright red color.
	BrightRed

	// BrightGreen is the ANSI bright green color.
	BrightGreen

	// BrightYellow is the ANSI bright yellow color.
	BrightYellow

	// BrightBlue is the ANSI bright blue color.
	BrightBlue

	// BrightMagenta is the ANSI bright magenta color.
	BrightMagenta

	// BrightCyan is the ANSI bright cyan color.
	BrightCyan

	// BrightWhite is the ANSI bright white color.
	BrightWhite
)

func (BasicColor) RGBA

func (c BasicColor) RGBA() (uint32, uint32, uint32, uint32)

RGBA returns the red, green, blue and alpha components of the color. It satisfies the color.Color interface.

type Color

type Color interface {
	color.Color
}

Color is a color that can be used in a terminal. ANSI (including ANSI256) and 24-bit "true colors" fall under this category.

type Colorizer added in v0.5.0

type Colorizer interface {
	color.Color
	fmt.Stringer
}

Colorizer is a color.Color interface that can be formatted as a string.

type Command added in v0.5.0

type Command int

Command represents a sequence command. This is used to pack/unpack a sequence command with its intermediate and marker characters. Those are commonly found in CSI and DCS sequences.

func Cmd added in v0.2.0

func Cmd(marker, inter, cmd int) (c Command)

Cmd returns a packed Command with the given command, marker, and intermediate. The first byte is the command, the next shift is the marker, and the next shift is the intermediate.

Even though this function takes integers, it only uses the lower 8 bits of each integer.

func (Command) Command added in v0.5.0

func (c Command) Command() int

Command returns the unpacked command byte of the CSI sequence.

func (Command) Intermediate added in v0.5.0

func (c Command) Intermediate() int

Intermediate returns the unpacked intermediate byte of the CSI sequence. An intermediate byte is in the range of 0x20-0x2F. This includes these characters from ' ', '!', '"', '#', '$', '%', '&', ”', '(', ')', '*', '+', ',', '-', '.', '/'. Zero is returned if the sequence does not have an intermediate byte.

func (Command) Marker added in v0.5.0

func (c Command) Marker() int

Marker returns the unpacked marker byte of the CSI sequence. This is always gonna be one of the following '<' '=' '>' '?' and in the range of 0x3C-0x3F. Zero is returned if the sequence does not have a marker.

type ControlCode

type ControlCode byte

ControlCode represents a control code character. This is a character that is not printable and is used to control the terminal. This would be a character in the C0 or C1 set in the range of 0x00-0x1F and 0x80-0x9F.

func (ControlCode) Bytes

func (c ControlCode) Bytes() []byte

Bytes implements Sequence.

func (ControlCode) Clone

func (c ControlCode) Clone() Sequence

Clone returns a deep copy of the control code.

func (ControlCode) String

func (c ControlCode) String() string

String implements Sequence.

type CsiSequence

type CsiSequence struct {
	// Params contains the raw parameters of the sequence.
	// This is a slice of integers, where each integer is a 32-bit integer
	// containing the parameter value in the lower 31 bits and a flag in the
	// most significant bit indicating whether there are more sub-parameters.
	Params []Parameter

	// Cmd contains the raw command of the sequence.
	// The command is a 32-bit integer containing the CSI command byte in the
	// lower 8 bits, the private marker in the next 8 bits, and the intermediate
	// byte in the next 8 bits.
	//
	//  CSI ? u
	//
	// Is represented as:
	//
	//  'u' | '?' << 8
	Cmd Command
}

CsiSequence represents a control sequence introducer (CSI) sequence.

The sequence starts with a CSI sequence, CSI (0x9B) in a 8-bit environment or ESC [ (0x1B 0x5B) in a 7-bit environment, followed by any number of parameters in the range of 0x30-0x3F, then by any number of intermediate byte in the range of 0x20-0x2F, then finally with a single final byte in the range of 0x20-0x7E.

CSI P..P I..I F

See ECMA-48 § 5.4.

func (CsiSequence) Bytes

func (s CsiSequence) Bytes() []byte

Bytes returns the byte representation of the sequence. The bytes will always be in the 7-bit format i.e (ESC [ P..P I..I F).

func (CsiSequence) Clone

func (s CsiSequence) Clone() Sequence

Clone returns a deep copy of the CSI sequence.

func (CsiSequence) Command

func (s CsiSequence) Command() int

Command returns the command byte of the CSI sequence.

func (CsiSequence) Intermediate

func (s CsiSequence) Intermediate() int

Intermediate returns the intermediate byte of the CSI sequence. An intermediate byte is in the range of 0x20-0x2F. This includes these characters from ' ', '!', '"', '#', '$', '%', '&', ”', '(', ')', '*', '+', ',', '-', '.', '/'. Zero is returned if the sequence does not have an intermediate byte.

func (CsiSequence) Marker

func (s CsiSequence) Marker() int

Marker returns the marker byte of the CSI sequence. This is always gonna be one of the following '<' '=' '>' '?' and in the range of 0x3C-0x3F. Zero is returned if the sequence does not have a marker.

func (CsiSequence) Param

func (s CsiSequence) Param(i, def int) (int, bool)

Param is a helper that returns the parameter at the given index and falls back to the default value if the parameter is missing. If the index is out of bounds, it returns the default value and false.

func (CsiSequence) String

func (s CsiSequence) String() string

String returns a string representation of the sequence. The string will always be in the 7-bit format i.e (ESC [ P..P I..I F).

type DECMode added in v0.5.0

type DECMode int

DECMode represents a private DEC terminal mode.

func (DECMode) Mode added in v0.5.0

func (m DECMode) Mode() int

Mode returns the DEC mode as an integer.

type DECStatus added in v0.5.0

type DECStatus int

DECStatus represents a DEC terminal status report.

func (DECStatus) Status added in v0.5.0

func (s DECStatus) Status() int

Status returns the status report identifier.

type DcsSequence

type DcsSequence struct {
	// Params contains the raw parameters of the sequence.
	// This is a slice of integers, where each integer is a 32-bit integer
	// containing the parameter value in the lower 31 bits and a flag in the
	// most significant bit indicating whether there are more sub-parameters.
	Params []Parameter

	// Data contains the string raw data of the sequence.
	// This is the data between the final byte and the escape sequence terminator.
	Data []byte

	// Cmd contains the raw command of the sequence.
	// The command is a 32-bit integer containing the DCS command byte in the
	// lower 8 bits, the private marker in the next 8 bits, and the intermediate
	// byte in the next 8 bits.
	//
	//  DCS > 0 ; 1 $ r <data> ST
	//
	// Is represented as:
	//
	//  'r' | '>' << 8 | '$' << 16
	Cmd Command
}

DcsSequence represents a Device Control String (DCS) escape sequence.

The DCS sequence is used to send device control strings to the terminal. The sequence starts with the C1 control code character DCS (0x9B) or ESC P in 7-bit environments, followed by parameter bytes, intermediate bytes, a command byte, followed by data bytes, and ends with the C1 control code character ST (0x9C) or ESC \ in 7-bit environments.

This follows the parameter string format. See ECMA-48 § 5.4.1

func (DcsSequence) Bytes

func (s DcsSequence) Bytes() []byte

Bytes returns the byte representation of the sequence. The bytes will always be in the 7-bit format i.e (ESC P p..p i..i F <data> ESC \).

func (DcsSequence) Clone

func (s DcsSequence) Clone() Sequence

Clone returns a deep copy of the DCS sequence.

func (DcsSequence) Command

func (s DcsSequence) Command() int

Command returns the command byte of the CSI sequence.

func (DcsSequence) Intermediate

func (s DcsSequence) Intermediate() int

Intermediate returns the intermediate byte of the DCS sequence. An intermediate byte is in the range of 0x20-0x2F. This includes these characters from ' ', '!', '"', '#', '$', '%', '&', ”', '(', ')', '*', '+', ',', '-', '.', '/'. Zero is returned if the sequence does not have an intermediate byte.

func (DcsSequence) Marker

func (s DcsSequence) Marker() int

Marker returns the marker byte of the DCS sequence. This is always gonna be one of the following '<' '=' '>' '?' and in the range of 0x3C-0x3F. Zero is returned if the sequence does not have a marker.

func (DcsSequence) Param

func (s DcsSequence) Param(i, def int) (int, bool)

Param is a helper that returns the parameter at the given index and falls back to the default value if the parameter is missing. If the index is out of bounds, it returns the default value and false.

func (DcsSequence) Split added in v0.5.0

func (s DcsSequence) Split() []string

Split returns a slice of data split by the semicolon.

func (DcsSequence) String

func (s DcsSequence) String() string

String returns a string representation of the sequence. The string will always be in the 7-bit format i.e (ESC P p..p i..i f <data> ESC \).

type EscSequence

type EscSequence Command

EscSequence represents an escape sequence.

func (EscSequence) Bytes

func (e EscSequence) Bytes() []byte

Bytes implements Sequence.

func (EscSequence) Clone

func (e EscSequence) Clone() Sequence

Clone returns a deep copy of the escape sequence.

func (EscSequence) Command

func (e EscSequence) Command() int

Command returns the command byte of the escape sequence.

func (EscSequence) Intermediate

func (e EscSequence) Intermediate() int

Intermediate returns the intermediate byte of the escape sequence.

func (EscSequence) String

func (e EscSequence) String() string

String implements Sequence.

type ExtendedColor

type ExtendedColor uint8

ExtendedColor is an ANSI 256 (8-bit) color with a value from 0 to 255.

func (ExtendedColor) RGBA

func (c ExtendedColor) RGBA() (uint32, uint32, uint32, uint32)

RGBA returns the red, green, blue and alpha components of the color. It satisfies the color.Color interface.

type Grapheme added in v0.5.0

type Grapheme struct {
	Cluster string
	Width   int
}

Grapheme represents a grapheme cluster.

func (Grapheme) Clone added in v0.5.0

func (g Grapheme) Clone() Sequence

Clone returns a deep copy of the grapheme.

type HexColorizer added in v0.5.0

type HexColorizer struct{ color.Color }

HexColorizer is a color.Color that can be formatted as a hex string.

func (HexColorizer) String added in v0.5.0

func (h HexColorizer) String() string

String returns the color as a hex string. If the color is nil, an empty string is returned.

type Mode added in v0.4.0

type Mode interface {
	Mode() int
}

Mode represents an interface for terminal modes. Modes can be set, reset, and requested.

type ModeSetting added in v0.5.0

type ModeSetting byte

ModeSetting represents a mode setting.

const (
	ModeNotRecognized ModeSetting = iota
	ModeSet
	ModeReset
	ModePermanentlySet
	ModePermanentlyReset
)

ModeSetting constants.

func (ModeSetting) IsNotRecognized added in v0.5.0

func (m ModeSetting) IsNotRecognized() bool

IsNotRecognized returns true if the mode is not recognized.

func (ModeSetting) IsPermanentlyReset added in v0.5.0

func (m ModeSetting) IsPermanentlyReset() bool

IsPermanentlyReset returns true if the mode is permanently reset.

func (ModeSetting) IsPermanentlySet added in v0.5.0

func (m ModeSetting) IsPermanentlySet() bool

IsPermanentlySet returns true if the mode is permanently set.

func (ModeSetting) IsReset added in v0.5.0

func (m ModeSetting) IsReset() bool

IsReset returns true if the mode is reset or permanently reset.

func (ModeSetting) IsSet added in v0.5.0

func (m ModeSetting) IsSet() bool

IsSet returns true if the mode is set or permanently set.

type OscSequence

type OscSequence struct {
	// Data contains the raw data of the sequence including the identifier
	// command.
	Data []byte

	// Cmd contains the raw command of the sequence.
	Cmd int
}

OscSequence represents an OSC sequence.

The sequence starts with a OSC sequence, OSC (0x9D) in a 8-bit environment or ESC ] (0x1B 0x5D) in a 7-bit environment, followed by positive integer identifier, then by arbitrary data terminated by a ST (0x9C) in a 8-bit environment, ESC \ (0x1B 0x5C) in a 7-bit environment, or BEL (0x07) for backwards compatibility.

OSC Ps ; Pt ST
OSC Ps ; Pt BEL

See ECMA-48 § 5.7.

func (OscSequence) Bytes

func (s OscSequence) Bytes() []byte

Bytes returns the byte representation of the OSC sequence. To be more compatible with different terminal, this will always return a 7-bit formatted sequence, terminated by BEL.

func (OscSequence) Clone

func (o OscSequence) Clone() Sequence

Clone returns a deep copy of the OSC sequence.

func (OscSequence) Command

func (o OscSequence) Command() int

Command returns the OSC command. This is always gonna be a positive integer that identifies the OSC sequence.

func (OscSequence) Split added in v0.5.0

func (o OscSequence) Split() []string

Split returns a slice of data split by the semicolon with the first element being the identifier command.

func (OscSequence) String

func (s OscSequence) String() string

String returns the string representation of the OSC sequence. To be more compatible with different terminal, this will always return a 7-bit formatted sequence, terminated by BEL.

type Parameter added in v0.5.0

type Parameter int

Parameter represents a sequence parameter. Sequence parameters with sub-parameters are packed with the HasMoreFlag set. This is used to unpack the parameters from a CSI and DCS sequences.

func Param added in v0.2.0

func Param(p int, hasMore bool) (s Parameter)

Param returns a packed Parameter with the given parameter and whether this parameter has following sub-parameters.

func (Parameter) HasMore added in v0.5.0

func (s Parameter) HasMore() bool

HasMore unpacks the HasMoreFlag from the parameter.

func (Parameter) Param added in v0.5.0

func (s Parameter) Param(def int) int

Param returns the unpacked parameter at the given index. It returns the default value if the parameter is missing.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser represents a DEC ANSI compatible sequence parser.

It uses a state machine to parse ANSI escape sequences and control characters. The parser is designed to be used with a terminal emulator or similar application that needs to parse ANSI escape sequences and control characters. See package parser for more information.

func GetParser added in v0.3.1

func GetParser() *Parser

GetParser returns a parser from a sync pool.

func NewParser

func NewParser(d ParserDispatcher) *Parser

NewParser returns a new parser with an optional ParserDispatcher. The Parser uses a default size of 32 for the parameters and 64KB for the data buffer. Use Parser.SetParamsSize and Parser.SetDataSize to set the size of the parameters and data buffer respectively.

func (*Parser) Advance

func (p *Parser) Advance(b byte) parser.Action

Advance advances the parser using the given byte. It returns the action performed by the parser.

func (*Parser) Cmd

func (p *Parser) Cmd() Command

Cmd returns the packed command of the last dispatched sequence.

func (*Parser) Data

func (p *Parser) Data() []byte

Data returns the raw data of the last dispatched sequence.

func (*Parser) Param added in v0.5.0

func (p *Parser) Param(i, def int) (int, bool)

Param returns the parameter at the given index and falls back to the default value if the parameter is missing. If the index is out of bounds, it returns the default value and false.

func (*Parser) Params

func (p *Parser) Params() []Parameter

Params returns the list of parsed packed parameters.

func (*Parser) Parse

func (p *Parser) Parse(b []byte)

Parse parses the given dispatcher and byte buffer. Deprecated: Loop over the buffer and call Parser.Advance instead.

func (*Parser) Reset

func (p *Parser) Reset()

Reset resets the parser to its initial state.

func (*Parser) Rune added in v0.5.0

func (p *Parser) Rune() rune

Rune returns the last dispatched sequence as a rune.

func (*Parser) SetDataSize added in v0.5.0

func (p *Parser) SetDataSize(size int)

SetDataSize sets the size of the data buffer. This is used when constructing OSC, DCS, SOS, PM, and APC sequences. If size is less than or equal to 0, the data buffer is unlimited and will grow as needed.

func (*Parser) SetDispatcher added in v0.5.0

func (p *Parser) SetDispatcher(d ParserDispatcher)

SetDispatcher sets the dispatcher function to call when a sequence is complete.

func (*Parser) SetParamsSize added in v0.5.0

func (p *Parser) SetParamsSize(size int)

SetParamsSize sets the size of the parameters buffer. This is used when constructing CSI and DCS sequences.

func (*Parser) State

func (p *Parser) State() parser.State

State returns the current state of the parser.

func (*Parser) StateName

func (p *Parser) StateName() string

StateName returns the name of the current state.

type ParserDispatcher

type ParserDispatcher func(Sequence)

ParserDispatcher is a function that dispatches a sequence.

type PmSequence

type PmSequence struct {
	// Data contains the raw data of the sequence.
	Data []byte
}

PmSequence represents a PM sequence.

func (PmSequence) Bytes

func (s PmSequence) Bytes() []byte

Bytes implements Sequence.

func (PmSequence) Clone

func (p PmSequence) Clone() Sequence

Clone returns a deep copy of the PM sequence.

func (PmSequence) String

func (s PmSequence) String() string

String implements Sequence.

type Rune

type Rune rune

Rune represents a printable character.

func (Rune) Clone

func (r Rune) Clone() Sequence

Clone returns a deep copy of the rune.

type Sequence

type Sequence interface {
	// Clone returns a deep copy of the sequence.
	Clone() Sequence
}

Sequence represents an ANSI sequence. This can be a control sequence, escape sequence, a printable character, etc. A Sequence can be one of the following types:

type SosSequence

type SosSequence struct {
	// Data contains the raw data of the sequence.
	Data []byte
}

SosSequence represents a SOS sequence.

func (SosSequence) Bytes

func (s SosSequence) Bytes() []byte

Bytes implements Sequence.

func (SosSequence) Clone

func (s SosSequence) Clone() Sequence

Clone returns a deep copy of the SOS sequence.

func (SosSequence) String

func (s SosSequence) String() string

String implements Sequence.

type State added in v0.2.0

type State = byte

State represents the state of the ANSI escape sequence parser used by DecodeSequence.

const (
	NormalState State = iota
	MarkerState
	ParamsState
	IntermedState
	EscapeState
	StringState
)

ANSI escape sequence states used by DecodeSequence.

type Status added in v0.5.0

type Status interface {
	// Status returns the status report identifier.
	Status() int
}

Status represents a terminal status report.

type Style

type Style []string

Style represents an ANSI SGR (Select Graphic Rendition) style.

func (Style) BackgroundColor

func (s Style) BackgroundColor(c Color) Style

BackgroundColor appends the background color style attribute to the style.

func (Style) Bold

func (s Style) Bold() Style

Bold appends the bold style attribute to the style.

func (Style) Conceal

func (s Style) Conceal() Style

Conceal appends the conceal style attribute to the style.

func (Style) CurlyUnderline

func (s Style) CurlyUnderline() Style

CurlyUnderline appends the curly underline style attribute to the style. This is a convenience method for UnderlineStyle(CurlyUnderlineStyle).

func (Style) DashedUnderline

func (s Style) DashedUnderline() Style

DashedUnderline appends the dashed underline style attribute to the style. This is a convenience method for UnderlineStyle(DashedUnderlineStyle).

func (Style) DefaultBackgroundColor

func (s Style) DefaultBackgroundColor() Style

DefaultBackgroundColor appends the default background color style attribute to the style.

func (Style) DefaultForegroundColor

func (s Style) DefaultForegroundColor() Style

DefaultForegroundColor appends the default foreground color style attribute to the style.

func (Style) DefaultUnderlineColor

func (s Style) DefaultUnderlineColor() Style

DefaultUnderlineColor appends the default underline color style attribute to the style.

func (Style) DottedUnderline

func (s Style) DottedUnderline() Style

DottedUnderline appends the dotted underline style attribute to the style. This is a convenience method for UnderlineStyle(DottedUnderlineStyle).

func (Style) DoubleUnderline

func (s Style) DoubleUnderline() Style

DoubleUnderline appends the double underline style attribute to the style. This is a convenience method for UnderlineStyle(DoubleUnderlineStyle).

func (Style) Faint

func (s Style) Faint() Style

Faint appends the faint style attribute to the style.

func (Style) ForegroundColor

func (s Style) ForegroundColor(c Color) Style

ForegroundColor appends the foreground color style attribute to the style.

func (Style) Italic

func (s Style) Italic() Style

Italic appends the italic style attribute to the style.

func (s Style) NoBlink() Style

NoBlink appends the no blink style attribute to the style.

func (Style) NoBold

func (s Style) NoBold() Style

NoBold appends the no bold style attribute to the style.

func (Style) NoConceal added in v0.1.2

func (s Style) NoConceal() Style

NoConceal appends the no conceal style attribute to the style.

func (Style) NoItalic

func (s Style) NoItalic() Style

NoItalic appends the no italic style attribute to the style.

func (Style) NoReverse

func (s Style) NoReverse() Style

NoReverse appends the no reverse style attribute to the style.

func (Style) NoStrikethrough

func (s Style) NoStrikethrough() Style

NoStrikethrough appends the no strikethrough style attribute to the style.

func (Style) NoUnderline

func (s Style) NoUnderline() Style

NoUnderline appends the no underline style attribute to the style.

func (Style) NormalIntensity

func (s Style) NormalIntensity() Style

NormalIntensity appends the normal intensity style attribute to the style.

func (s Style) RapidBlink() Style

RapidBlink appends the rapid blink style attribute to the style.

func (Style) Reset

func (s Style) Reset() Style

Reset appends the reset style attribute to the style.

func (Style) Reverse

func (s Style) Reverse() Style

Reverse appends the reverse style attribute to the style.

func (s Style) SlowBlink() Style

SlowBlink appends the slow blink style attribute to the style.

func (Style) Strikethrough

func (s Style) Strikethrough() Style

Strikethrough appends the strikethrough style attribute to the style.

func (Style) String

func (s Style) String() string

String returns the ANSI SGR (Select Graphic Rendition) style sequence for the given style.

func (Style) Styled

func (s Style) Styled(str string) string

Styled returns a styled string with the given style applied.

func (Style) Underline

func (s Style) Underline() Style

Underline appends the underline style attribute to the style.

func (Style) UnderlineColor

func (s Style) UnderlineColor(c Color) Style

UnderlineColor appends the underline color style attribute to the style.

func (Style) UnderlineStyle added in v0.3.0

func (s Style) UnderlineStyle(u UnderlineStyle) Style

UnderlineStyle appends the underline style attribute to the style.

type TrueColor

type TrueColor uint32

TrueColor is a 24-bit color that can be used in the terminal. This can be used to represent RGB colors.

For example, the color red can be represented as:

TrueColor(0xff0000)

func (TrueColor) RGBA

func (c TrueColor) RGBA() (uint32, uint32, uint32, uint32)

RGBA returns the red, green, blue and alpha components of the color. It satisfies the color.Color interface.

type UnderlineStyle added in v0.3.0

type UnderlineStyle = int

UnderlineStyle represents an ANSI SGR (Select Graphic Rendition) underline style.

const (
	// NoUnderlineStyle is the default underline style.
	NoUnderlineStyle UnderlineStyle = iota
	// SingleUnderlineStyle is a single underline style.
	SingleUnderlineStyle
	// DoubleUnderlineStyle is a double underline style.
	DoubleUnderlineStyle
	// CurlyUnderlineStyle is a curly underline style.
	CurlyUnderlineStyle
	// DottedUnderlineStyle is a dotted underline style.
	DottedUnderlineStyle
	// DashedUnderlineStyle is a dashed underline style.
	DashedUnderlineStyle
)

type XRGBAColorizer added in v0.5.0

type XRGBAColorizer struct{ color.Color }

XRGBAColorizer is a color.Color that can be formatted as an XParseColor rgba: string.

See: https://linux.die.net/man/3/xparsecolor

func (XRGBAColorizer) String added in v0.5.0

func (x XRGBAColorizer) String() string

String returns the color as an XParseColor rgba: string. If the color is nil, an empty string is returned.

type XRGBColorizer added in v0.5.0

type XRGBColorizer struct{ color.Color }

XRGBColorizer is a color.Color that can be formatted as an XParseColor rgb: string.

See: https://linux.die.net/man/3/xparsecolor

func (XRGBColorizer) String added in v0.5.0

func (x XRGBColorizer) String() string

String returns the color as an XParseColor rgb: string. If the color is nil, an empty string is returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL