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
- Variables
- func ByteToGraphemeRange(str string, byteStart, byteStop int) (charStart, charStop int)
- func CBT(n int) string
- func CHA(col int) string
- func CHT(n int) string
- func CNL(n int) string
- func CPL(n int) string
- func CPR(line, column int) string
- func CUB(n int) string
- func CUD(n int) string
- func CUF(n int) string
- func CUP(col, row int) string
- func CUU(n int) string
- func Command(prefix, inter, final byte) (c int)
- func CursorBackward(n int) string
- func CursorBackwardTab(n int) string
- func CursorDown(n int) string
- func CursorForward(n int) string
- func CursorHorizontalAbsolute(col int) string
- func CursorHorizontalForwardTab(n int) string
- func CursorInformationReport(values ...int) string
- func CursorLeft(n int) stringdeprecated
- func CursorNextLine(n int) string
- func CursorPosition(col, row int) string
- func CursorPositionReport(line, column int) string
- func CursorPreviousLine(n int) string
- func CursorRight(n int) stringdeprecated
- func CursorUp(n int) string
- func Cut(s string, left, right int) string
- func CutWc(s string, left, right int) string
- func DA1(attrs ...int) string
- func DA2(attrs ...int) string
- func DA3(unitID string) string
- func DCH(n int) string
- func DECCIR(values ...int) string
- func DECRPM(mode Mode, value ModeSetting) string
- func DECRQM(m Mode) string
- func DECRQPSR(n int) string
- func DECSCUSR(style int) string
- func DECSLRM(left, right int) string
- func DECSTBM(top, bot int) string
- func DECTABSR(stops ...int) string
- func DECXCPR(line, column, page int) string
- func DL(n int) string
- func DSR(status StatusReport) string
- func DecodeSequence[T string | []byte](b T, state byte, p *Parser) (seq T, width int, n int, newState byte)
- func DecodeSequenceWc[T string | []byte](b T, state byte, p *Parser) (seq T, width int, n int, newState byte)
- func DeleteCharacter(n int) string
- func DeleteLine(n int) string
- func DeviceStatusReport(statues ...StatusReport) string
- func ECH(n int) string
- func ED(n int) string
- func EL(n int) string
- func EncodeMouseButton(b MouseButton, motion, shift, alt, ctrl bool) (m byte)
- func Equal[T string | []byte](a, b T) bool
- func EraseCharacter(n int) string
- func EraseDisplay(n int) string
- func EraseLine(n int) string
- func Execute(w io.Writer, s string) (int, error)
- func ExtendedCursorPositionReport(line, column, page int) string
- func FirstGraphemeCluster[T string | []byte](b T, state int) (T, T, int, int)
- func HPA(col int) string
- func HPR(n int) string
- func HVP(col, row int) string
- func Hardwrap(s string, limit int, preserveSpace bool) string
- func HardwrapWc(s string, limit int, preserveSpace bool) string
- func HasApcPrefix[T string | []byte](b T) bool
- func HasCsiPrefix[T string | []byte](b T) bool
- func HasDcsPrefix[T string | []byte](b T) bool
- func HasEscPrefix[T string | []byte](b T) bool
- func HasOscPrefix[T string | []byte](b T) bool
- func HasPmPrefix[T string | []byte](b T) bool
- func HasPrefix[T string | []byte](b, prefix T) bool
- func HasSosPrefix[T string | []byte](b T) bool
- func HasStPrefix[T string | []byte](b T) bool
- func HasSuffix[T string | []byte](b, suffix T) bool
- func HorizontalPositionAbsolute(col int) string
- func HorizontalPositionRelative(n int) string
- func HorizontalVerticalPosition(col, row int) string
- func ICH(n int) string
- func IL(n int) string
- func ITerm2(data any) string
- func InsertCharacter(n int) string
- func InsertLine(n int) string
- func KeyModifierOptions(p int, vs ...int) string
- func KittyGraphics(payload []byte, opts ...string) string
- func KittyKeyboard(flags, mode int) string
- func ModifyOtherKeys(mode int) stringdeprecated
- func MouseSgr(b byte, x, y int, release bool) string
- func MouseX10(b byte, x, y int) string
- func MoveCursor(col, row int) stringdeprecated
- func Notify(s string) string
- func NotifyWorkingDirectory(host string, paths ...string) string
- func PanDown(n int) string
- func PanUp(n int) string
- func Parameter(p int, hasMore bool) (s int)
- func PopKittyKeyboard(n int) string
- func PrimaryDeviceAttributes(attrs ...int) string
- func PushKittyKeyboard(flags int) string
- func PutParser(p *Parser)
- func QueryKeyModifierOptions(pp int) string
- func REP(n int) string
- func RM(modes ...Mode) string
- func ReadStyleColor(params Params, co *color.Color) (n int)
- func RepeatPreviousCharacter(n int) string
- func ReportMode(mode Mode, value ModeSetting) string
- func RequestClipboard(c byte) string
- func RequestMode(m Mode) string
- func RequestPresentationStateReport(n int) string
- func RequestTermcap(caps ...string) string
- func RequestTerminfo(caps ...string) string
- func ResetClipboard(c byte) string
- func ResetHyperlink(params ...string) string
- func ResetKeyModifierOptions(pp int) string
- func ResetMode(modes ...Mode) string
- func SCS(gset byte, charset byte) string
- func SD(n int) string
- func SGR(ps ...Attr) string
- func SM(modes ...Mode) string
- func SU(n int) string
- func ScreenPassthrough(seq string, limit int) string
- func ScrollDown(n int) string
- func ScrollUp(n int) string
- func SecondaryDeviceAttributes(attrs ...int) string
- func SelectCharacterSet(gset byte, charset byte) string
- func SelectGraphicRendition(ps ...Attr) string
- func SetBackgroundColor(c color.Color) string
- func SetClipboard(c byte, d string) string
- func SetCursorColor(c color.Color) string
- func SetCursorPosition(col, row int) stringdeprecated
- func SetCursorStyle(style int) string
- func SetForegroundColor(c color.Color) string
- func SetHyperlink(uri string, params ...string) string
- func SetIconName(s string) string
- func SetIconNameWindowTitle(s string) string
- func SetKeyModifierOptions(pp int, pv int) string
- func SetLeftRightMargins(left, right int) string
- func SetMode(modes ...Mode) string
- func SetPointerShape(shape string) string
- func SetPrimaryClipboard(d string) string
- func SetScrollingRegion(t, b int) stringdeprecated
- func SetSystemClipboard(d string) string
- func SetTopBottomMargins(top, bot int) string
- func SetWindowTitle(s string) string
- func StringWidth(s string) int
- func StringWidthWc(s string) int
- func Strip(s string) string
- func TBC(n int) string
- func TabClear(n int) string
- func TabStopReport(stops ...int) string
- func TertiaryDeviceAttributes(unitID string) string
- func TmuxPassthrough(seq string) string
- func Truncate(s string, length int, tail string) string
- func TruncateLeft(s string, n int, prefix string) string
- func TruncateLeftWc(s string, n int, prefix string) string
- func TruncateWc(s string, length int, tail string) string
- func VPA(row int) string
- func VPR(n int) string
- func VerticalPositionAbsolute(row int) string
- func VerticalPositionRelative(n int) string
- func WindowOp(p int, ps ...int) string
- func Wordwrap(s string, limit int, breakpoints string) string
- func WordwrapWc(s string, limit int, breakpoints string) string
- func Wrap(s string, limit int, breakpoints string) string
- func WrapWc(s string, limit int, breakpoints string) string
- func WriteKittyGraphics(w io.Writer, m image.Image, o *kitty.Options) error
- func XParseColor(s string) color.Color
- func XTGETTCAP(caps ...string) string
- func XTMODKEYS(p int, vs ...int) string
- func XTQMODKEYS(pp int) string
- func XTWINOPS(p int, ps ...int) string
- type ANSIMode
- type ANSIStatusReport
- type Attr
- type BasicColor
- type Cmd
- type Color
- type Colorizer
- type DECMode
- type DECStatusReport
- type ExtendedColor
- type Handler
- type HexColorizer
- type Method
- func (m Method) Cut(s string, left, right int) string
- func (m Method) DecodeSequence(data []byte, state byte, p *Parser) (seq []byte, width, n int, newState byte)
- func (m Method) DecodeSequenceInString(data string, state byte, p *Parser) (seq string, width, n int, newState byte)
- func (m Method) Hardwrap(s string, length int, preserveSpace bool) string
- func (m Method) StringWidth(s string) int
- func (m Method) Truncate(s string, length int, tail string) string
- func (m Method) TruncateLeft(s string, length int, prefix string) string
- func (m Method) Wordwrap(s string, length int, breakpoints string) string
- func (m Method) Wrap(s string, length int, breakpoints string) string
- type Mode
- type ModeSetting
- type Modes
- func (m Modes) Delete(mode Mode)
- func (m Modes) Get(mode Mode) ModeSetting
- func (m Modes) IsPermanentlyReset(mode Mode) bool
- func (m Modes) IsPermanentlySet(mode Mode) bool
- func (m Modes) IsReset(mode Mode) bool
- func (m Modes) IsSet(mode Mode) bool
- func (m Modes) PermanentlyReset(modes ...Mode)
- func (m Modes) PermanentlySet(modes ...Mode)
- func (m Modes) Reset(modes ...Mode)
- func (m Modes) Set(modes ...Mode)
- type MouseButton
- type Param
- type Params
- type Parser
- func (p *Parser) Advance(b byte) parser.Action
- func (p *Parser) Command() int
- func (p *Parser) Control() byte
- func (p *Parser) Data() []byte
- func (p *Parser) Param(i, def int) (int, bool)
- func (p *Parser) Params() Params
- func (p *Parser) Parse(b []byte)
- func (p *Parser) Reset()
- func (p *Parser) Rune() rune
- func (p *Parser) SetDataSize(size int)
- func (p *Parser) SetHandler(h Handler)
- func (p *Parser) SetParamsSize(size int)
- func (p *Parser) State() parser.State
- func (p *Parser) StateName() string
- type State
- type StatusReport
- type Style
- func (s Style) BackgroundColor(c Color) Style
- func (s Style) Bold() Style
- func (s Style) Conceal() Style
- func (s Style) CurlyUnderline() Style
- func (s Style) DashedUnderline() Style
- func (s Style) DefaultBackgroundColor() Style
- func (s Style) DefaultForegroundColor() Style
- func (s Style) DefaultUnderlineColor() Style
- func (s Style) DottedUnderline() Style
- func (s Style) DoubleUnderline() Style
- func (s Style) Faint() Style
- func (s Style) ForegroundColor(c Color) Style
- func (s Style) Italic() Style
- func (s Style) NoBlink() Style
- func (s Style) NoBold() Style
- func (s Style) NoConceal() Style
- func (s Style) NoItalic() Style
- func (s Style) NoReverse() Style
- func (s Style) NoStrikethrough() Style
- func (s Style) NoUnderline() Style
- func (s Style) NormalIntensity() Style
- func (s Style) RapidBlink() Style
- func (s Style) Reset() Style
- func (s Style) Reverse() Style
- func (s Style) SlowBlink() Style
- func (s Style) Strikethrough() Style
- func (s Style) String() string
- func (s Style) Styled(str string) string
- func (s Style) Underline() Style
- func (s Style) UnderlineColor(c Color) Style
- func (s Style) UnderlineStyle(u UnderlineStyle) Style
- type TrueColor
- type UnderlineStyle
- type XRGBAColorizer
- type XRGBColorizer
Constants ¶
const ( // SP is the space character (Char: \x20). SP = 0x20 // DEL is the delete character (Caret: ^?, Char: \x7f). DEL = 0x7F )
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
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
const ( SystemClipboard = 'c' PrimaryClipboard = 'p' )
Clipboard names.
const ( RequestNameVersion = "\x1b[>q" 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
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
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
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
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
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
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
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
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
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
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
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
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
const ( EnableCursorKeys = "\x1b[?1h" DisableCursorKeys = "\x1b[?1l" )
Deprecated: use SetCursorKeysMode and ResetCursorKeysMode instead.
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
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
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
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
const ( ShowCursor = SetTextCursorEnableMode HideCursor = ResetTextCursorEnableMode )
These are aliases for SetTextCursorEnableMode and ResetTextCursorEnableMode.
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.
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
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
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
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
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.
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.
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.
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
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.
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
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.
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
const ( ReportFocusMode = DECMode(1004) EnableReportFocus = "\x1b[?1004h" DisableReportFocus = "\x1b[?1004l" RequestReportFocus = "\x1b[?1004$p" )
Deprecated: use SetFocusEventMode, ResetFocusEventMode, and RequestFocusEventMode instead.
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
const ( MouseSgrExtMode = DECMode(1006) EnableMouseSgrExt = "\x1b[?1006h" DisableMouseSgrExt = "\x1b[?1006l" RequestMouseSgrExt = "\x1b[?1006$p" )
Deprecated: use SgrExtMouseMode SetSgrExtMouseMode, ResetSgrExtMouseMode, and RequestSgrExtMouseMode instead.
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
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
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
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
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
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
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.
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
const ( EnableBracketedPaste = "\x1b[?2004h" DisableBracketedPaste = "\x1b[?2004l" RequestBracketedPaste = "\x1b[?2004$p" )
Deprecated: use SetBracketedPasteMode, ResetBracketedPasteMode, and RequestBracketedPasteMode instead.
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
const ( SyncdOutputMode = DECMode(2026) EnableSyncdOutput = "\x1b[?2026h" DisableSyncdOutput = "\x1b[?2026l" RequestSyncdOutput = "\x1b[?2026$p" )
Deprecated: use SynchronizedOutputMode, SetSynchronizedOutputMode, and ResetSynchronizedOutputMode, and RequestSynchronizedOutputMode instead.
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
const ( EnableGraphemeClustering = "\x1b[?2027h" DisableGraphemeClustering = "\x1b[?2027l" RequestGraphemeClustering = "\x1b[?2027$p" )
Deprecated: use SetGraphemeClusteringMode, ResetGraphemeClusteringMode, and RequestGraphemeClusteringMode instead.
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.
const ( EnableWin32Input = "\x1b[?9001h" DisableWin32Input = "\x1b[?9001l" RequestWin32Input = "\x1b[?9001$p" )
Deprecated: use SetWin32InputMode, ResetWin32InputMode, and RequestWin32InputMode instead.
const ( MouseNone MouseButton = iota MouseButton1 MouseButton2 MouseButton3 MouseButton4 MouseButton5 MouseButton6 MouseButton7 MouseButton8 MouseButton9 MouseButton10 MouseButton11 MouseLeft = MouseButton1 MouseMiddle = MouseButton2 MouseRight = MouseButton3 MouseWheelUp = MouseButton4 MouseWheelDown = MouseButton5 MouseWheelLeft = MouseButton6 MouseWheelRight = MouseButton7 MouseBackward = MouseButton8 MouseForward = MouseButton9 MouseRelease = MouseNone )
Mouse event buttons
This is based on X11 mouse button codes.
1 = left button 2 = middle button (pressing the scroll wheel) 3 = right button 4 = turn scroll wheel up 5 = turn scroll wheel down 6 = push scroll wheel left 7 = push scroll wheel right 8 = 4th button (aka browser backward button) 9 = 5th button (aka browser forward button) 10 11
Other buttons are not supported.
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
const ( EraseScreenBelow = "\x1b[J" EraseScreenAbove = "\x1b[1J" EraseEntireScreen = "\x1b[2J" EraseEntireDisplay = "\x1b[3J" )
EraseDisplay constants. These are the possible values for the EraseDisplay function.
const ( EraseLineRight = "\x1b[K" EraseLineLeft = "\x1b[1K" EraseEntireLine = "\x1b[2K" )
EraseLine constants. These are the possible values for the EraseLine function.
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
const ( // ResizeWindowWinOp is a window operation that resizes the terminal // window. ResizeWindowWinOp = 4 // RequestWindowSizeWinOp is a window operation that requests a report of // the size of the terminal window in pixels. The response is in the form: // CSI 4 ; height ; width t RequestWindowSizeWinOp = 14 // RequestCellSizeWinOp is a window operation that requests a report of // the size of the terminal cell size in pixels. The response is in the form: // CSI 6 ; height ; width t RequestCellSizeWinOp = 16 )
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
const Blur = "\x1b[O"
Blur is an escape sequence to notify the terminal that it has lost focus. This is used with FocusEventMode.
const BracketedPasteEnd = "\x1b[201~"
BracketedPasteEnd is the control sequence to disable bracketed paste mode.
const BracketedPasteStart = "\x1b[200~"
BracketedPasteStart is the control sequence to enable bracketed paste mode.
const CUB1 = "\x1b[D"
CUB1 is a sequence for moving the cursor left one cell.
const CUD1 = "\x1b[B"
CUD1 is a sequence for moving the cursor down one cell.
const CUF1 = "\x1b[C"
CUF1 is a sequence for moving the cursor right one cell.
const CUU1 = "\x1b[A"
CUU1 is a sequence for moving the cursor up one cell.
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.
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)`.
const CursorLeft1 = CUB1
CursorLeft1 is a sequence for moving the cursor left one cell.
This is equivalent to CursorLeft(1).
Deprecated: use CUB1 instead.
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.
const CursorRight1 = CUF1
CursorRight1 is a sequence for moving the cursor right one cell.
This is equivalent to CursorRight(1).
Deprecated: use CUF1 instead.
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.
const DisableKittyKeyboard = "\x1b[>u"
DisableKittyKeyboard is a sequence to push zero into the terminal Kitty Keyboard stack to disable the protocol.
This is equivalent to PushKittyKeyboard(0).
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.
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.
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.
const Focus = "\x1b[I"
Focus is an escape sequence to notify the terminal that it has focus. This is used with FocusEventMode.
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.
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
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)`.
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.
const LS1R = "\x1b~"
Locking Shift 1 Right (LS1R) shifts G1 into GR character set.
const LS2 = "\x1bn"
Locking Shift 2 (LS2) shifts G2 into GL character set.
const LS2R = "\x1b}"
Locking Shift 2 Right (LS2R) shifts G2 into GR character set.
const LS3 = "\x1bo"
Locking Shift 3 (LS3) shifts G3 into GL character set.
const LS3R = "\x1b|"
Locking Shift 3 Right (LS3R) shifts G3 into GR character set.
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.
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
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
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
Deprecated: use RequestCursorPositionReport instead.
const RequestCursorPositionReport = "\x1b[6n"
RequestCursorPositionReport 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
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
Deprecated: use RequestExtendedCursorPositionReport instead.
const RequestExtendedCursorPositionReport = "\x1b[?6n"
RequestExtendedCursorPositionReport (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
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
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/
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.
const RequestPrimaryClipboard = "\x1b]52;p;?\x07"
RequestPrimaryClipboard is a sequence for requesting the primary clipboard.
This is equivalent to RequestClipboard(PrimaryClipboard).
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
const RequestSecondaryDeviceAttributes = "\x1b[>c"
RequestSecondaryDeviceAttributes is a control sequence that requests the terminal's secondary device attributes (DA2).
CSI > c
See https://vt100.net/docs/vt510-rm/DA2.html
const RequestSystemClipboard = "\x1b]52;c;?\x07"
RequestSystemClipboard is a sequence for requesting the system clipboard.
This is equivalent to RequestClipboard(SystemClipboard).
const RequestTertiaryDeviceAttributes = "\x1b[=c"
RequestTertiaryDeviceAttributes is a control sequence that requests the terminal's tertiary device attributes (DA3).
CSI = c
See https://vt100.net/docs/vt510-rm/DA3.html
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.
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
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
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
const ResetPrimaryClipboard = "\x1b]52;p;\x07"
ResetPrimaryClipboard is a sequence for resetting the primary clipboard.
This is equivalent to ResetClipboard(PrimaryClipboard).
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
const ResetSystemClipboard = "\x1b]52;c;\x07"
ResetSystemClipboard is a sequence for resetting the system clipboard.
This is equivalent to ResetClipboard(SystemClipboard).
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.
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.
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 ¶
var ( // KittyGraphicsTempDir is the directory where temporary files are stored. // This is used in [WriteKittyGraphics] along with [os.CreateTemp]. KittyGraphicsTempDir = "" // KittyGraphicsTempPattern is the pattern used to create temporary files. // This is used in [WriteKittyGraphics] along with [os.CreateTemp]. // The Kitty Graphics protocol requires the file path to contain the // substring "tty-graphics-protocol". KittyGraphicsTempPattern = "tty-graphics-protocol-*" )
Functions ¶
func ByteToGraphemeRange ¶ added in v0.8.0
ByteToGraphemeRange takes start and stop byte positions and converts them to grapheme-aware char positions. You can use this with Truncate, TruncateLeft, and Cut.
func CPR ¶ added in v0.5.0
CPR is an alias for CursorPositionReport.
func Command ¶ added in v0.5.0
Command packs a command with the given prefix, intermediate, and final. A zero byte means the sequence does not have a prefix or intermediate.
Prefixes are in the range of 0x3C-0x3F that is one of `<=>?`.
Intermediates are in the range of 0x20-0x2F that is anything in `!"#$%&'()*+,-./`.
Final bytes are in the range of 0x40-0x7E that is anything in the range `@A–Z[\]^_`a–z{|}~`.
func CursorBackward ¶ added in v0.5.0
CursorBackward (CUB) returns a sequence for moving the cursor left n cells.
CSI n D ¶
func CursorBackwardTab ¶ added in v0.5.0
CursorBackwardTab (CBT) returns a sequence for moving the cursor to the previous tab stop n times.
Default is 1.
CSI n Z
func CursorForward ¶ added in v0.5.0
CursorForward (CUF) returns a sequence for moving the cursor right n cells.
CSI n C ¶
func CursorHorizontalAbsolute ¶ added in v0.5.0
CursorHorizontalAbsolute (CHA) returns a sequence for moving the cursor to the given column.
Default is 1.
CSI n G
func CursorHorizontalForwardTab ¶ added in v0.5.0
CursorHorizontalForwardTab (CHT) returns a sequence for moving the cursor to the next tab stop n times.
Default is 1.
CSI n I
func CursorInformationReport ¶ added in v0.5.0
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.
func CursorLeft
deprecated
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 ¶
CursorNextLine (CNL) returns a sequence for moving the cursor to the beginning of the next line n times.
CSI n E
func CursorPosition ¶ added in v0.5.0
CursorPosition (CUP) returns a sequence for setting the cursor to the given row and column.
Default is 1,1.
CSI n ; m H
func CursorPositionReport ¶ added in v0.5.0
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.
func CursorPreviousLine ¶
CursorPreviousLine (CPL) returns a sequence for moving the cursor to the beginning of the previous line n times.
CSI n F
func CursorRight
deprecated
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 Cut ¶ added in v0.7.0
Cut the string, without adding any prefix or tail strings. This function is aware of ANSI escape codes and will not break them, and accounts for wide-characters (such as East-Asian characters and emojis). Note that the [left] parameter is inclusive, while [right] isn't. This treats the text as a sequence of graphemes.
func CutWc ¶ added in v0.8.0
CutWc the string, without adding any prefix or tail strings. This function is aware of ANSI escape codes and will not break them, and accounts for wide-characters (such as East-Asian characters and emojis). Note that the [left] parameter is inclusive, while [right] isn't. This treats the text as a sequence of wide characters and runes.
func DA1 ¶ added in v0.5.0
DA1 is an alias for PrimaryDeviceAttributes.
func DA2 ¶ added in v0.5.0
DA2 is an alias for SecondaryDeviceAttributes.
func DA3 ¶ added in v0.5.0
DA3 is an alias for TertiaryDeviceAttributes.
func DECCIR ¶ added in v0.5.0
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 DECRQPSR ¶ added in v0.5.0
DECRQPSR is an alias for RequestPresentationStateReport.
func DECSCUSR ¶ added in v0.5.0
DECSCUSR is an alias for SetCursorStyle.
func DECSLRM ¶ added in v0.5.0
DECSLRM is an alias for SetLeftRightMargins.
func DECSTBM ¶ added in v0.5.0
DECSTBM is an alias for SetTopBottomMargins.
func DECTABSR ¶ added in v0.5.0
DECTABSR is an alias for TabStopReport.
func DECXCPR ¶ added in v0.5.0
DECXCPR is an alias for ExtendedCursorPositionReport.
func DSR ¶ added in v0.5.0
func DSR(status StatusReport) 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 prefix characters. In the case of a OSC sequence, the cmd will be the OSC command number. Use Cmd and Param types to unpack command intermediates and prefixes as well as parameters.
Zero Cmd 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 Cmd in the most significant byte, the prefix 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 prefixes. The command byte is always the least significant byte i.e. [Cmd & 0xff]. Use the Cmd type to unpack the command, intermediate, and prefix bytes. Note that we only collect the last prefix 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 Param 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:] }
This function treats the text as a sequence of grapheme clusters.
func DecodeSequenceWc ¶ added in v0.8.0
func DecodeSequenceWc[T string | []byte](b T, state byte, p *Parser) (seq T, width int, n int, newState byte)
DecodeSequenceWc 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 prefix characters. In the case of a OSC sequence, the cmd will be the OSC command number. Use Cmd and Param types to unpack command intermediates and prefixes as well as parameters.
Zero Cmd 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 Cmd in the most significant byte, the prefix 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 prefixes. The command byte is always the least significant byte i.e. [Cmd & 0xff]. Use the Cmd type to unpack the command, intermediate, and prefix bytes. Note that we only collect the last prefix 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 Param 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 := DecodeSequenceWc(input, state, p) log.Printf("seq: %q, width: %d", seq, width) state = newState input = input[n:] }
This function treats the text as a sequence of wide characters and runes.
func DeleteCharacter ¶ added in v0.5.0
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
func DeleteLine ¶
DeleteLine (DL) deletes n lines at the current cursor position. Existing lines are moved up.
CSI Pn M
func DeviceStatusReport ¶ added in v0.5.0
func DeviceStatusReport(statues ...StatusReport) 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.
func EncodeMouseButton ¶ added in v0.8.0
func EncodeMouseButton(b MouseButton, motion, shift, alt, ctrl bool) (m byte)
EncodeMouseButton returns a byte representing a mouse button. The button is a bitmask of the following leftmost values:
The first two bits are the button number: 0 = left button, wheel up, or button no. 8 aka (backwards) 1 = middle button, wheel down, or button no. 9 aka (forwards) 2 = right button, wheel left, or button no. 10 3 = release event, wheel right, or button no. 11
The third bit indicates whether the shift key was pressed.
The fourth bit indicates the alt key was pressed.
The fifth bit indicates the control key was pressed.
The sixth bit indicates motion events. Combined with button number 3, i.e. release event, it represents a drag event.
The seventh bit indicates a wheel event.
The eighth bit indicates additional buttons.
If button is MouseNone, and motion is false, this returns a release event. If button is undefined, this function returns 0xff.
func EraseCharacter ¶ added in v0.5.0
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
func EraseDisplay ¶
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
func EraseLine ¶
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
func Execute ¶
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
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.
func FirstGraphemeCluster ¶ added in v0.2.0
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 HVP ¶ added in v0.5.0
HVP is an alias for HorizontalVerticalPosition.
func Hardwrap ¶
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. This treats the text as a sequence of graphemes.
func HardwrapWc ¶ added in v0.8.0
HardwrapWc 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. This treats the text as a sequence of wide characters and runes.
func HasApcPrefix ¶ added in v0.2.0
HasApcPrefix returns true if the given byte slice has an APC prefix.
func HasCsiPrefix ¶ added in v0.2.0
HasCsiPrefix returns true if the given byte slice has a CSI prefix.
func HasDcsPrefix ¶ added in v0.2.0
HasDcsPrefix returns true if the given byte slice has a DCS prefix.
func HasEscPrefix ¶ added in v0.2.0
HasEscPrefix returns true if the given byte slice has an ESC prefix.
func HasOscPrefix ¶ added in v0.2.0
HasOscPrefix returns true if the given byte slice has an OSC prefix.
func HasPmPrefix ¶ added in v0.2.0
HasPmPrefix returns true if the given byte slice has a PM prefix.
func HasSosPrefix ¶ added in v0.2.0
HasSosPrefix returns true if the given byte slice has a SOS prefix.
func HasStPrefix ¶ added in v0.2.0
HasStPrefix returns true if the given byte slice has a ST prefix.
func HorizontalPositionAbsolute ¶ added in v0.5.0
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 `
func HorizontalPositionRelative ¶ added in v0.5.0
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
func HorizontalVerticalPosition ¶ added in v0.5.0
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.
func ITerm2 ¶ added in v0.7.0
ITerm2 returns a sequence that uses the iTerm2 proprietary protocol. Use the iterm2 package for a more convenient API.
OSC 1337 ; key = value ST
Example:
ITerm2(iterm2.File{...})
See https://iterm2.com/documentation-escape-codes.html See https://iterm2.com/documentation-images.html
func InsertCharacter ¶ added in v0.5.0
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 @
func InsertLine ¶
InsertLine (IL) inserts n blank lines at the current cursor position. Existing lines are moved down.
CSI Pn L
func KeyModifierOptions ¶ added in v0.5.0
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.
func KittyGraphics ¶ added in v0.8.0
KittyGraphics returns a sequence that encodes the given image in the Kitty graphics protocol.
APC G [comma separated options] ; [base64 encoded payload] ST
func KittyKeyboard ¶ added in v0.2.0
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
deprecated
added in
v0.2.0
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
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
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
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
Notify sends a desktop notification using iTerm's OSC 9.
OSC 9 ; Mc ST OSC 9 ; Mc BEL
Where Mc is the notification body.
func NotifyWorkingDirectory ¶ added in v0.5.2
NotifyWorkingDirectory returns a sequence that notifies the terminal of the current working directory.
OSC 7 ; Pt BEL
Where Pt is a URL in the format "file://[host]/path". Set host to "localhost" if this is a path on the local computer.
See: https://wezfurlong.org/wezterm/shell-integration.html#osc-7-escape-sequence-to-set-the-working-directory See: https://iterm2.com/documentation-escape-codes.html#:~:text=RemoteHost%20and%20CurrentDir%3A-,OSC%207,-%3B%20%5BPs%5D%20ST
func Parameter ¶ added in v0.5.0
Parameter packs an escape code parameter with the given parameter and whether this parameter has following sub-parameters.
func PopKittyKeyboard ¶
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
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.
func PushKittyKeyboard ¶
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
QueryKeyModifierOptions (XTQMODKEYS) requests xterm key modifier options.
Default is 0.
CSI ? Pp m
func ReadStyleColor ¶ added in v0.8.0
ReadStyleColor decodes a color from a slice of parameters. It returns the number of parameters read and the color. This function is used to read SGR color parameters following the ITU T.416 standard.
It supports reading the following color types:
- 0: implementation defined
- 1: transparent
- 2: RGB direct color
- 3: CMY direct color
- 4: CMYK direct color
- 5: indexed color
- 6: RGBA direct color (WezTerm extension)
The parameters can be separated by semicolons (;) or colons (:). Mixing separators is not allowed.
The specs supports defining a color space id, a color tolerance value, and a tolerance color space id. However, these values have no effect on the returned color and will be ignored.
This implementation includes a few modifications to the specs:
- Support for legacy color values separated by semicolons (;) with respect to RGB, and indexed colors
- Support ignoring and omitting the color space id (second parameter) with respect to RGB colors
- Support ignoring and omitting the 6th parameter with respect to RGB and CMY colors
- Support reading RGBA colors
func RepeatPreviousCharacter ¶ added in v0.5.0
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
func RequestClipboard ¶
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
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
func RequestPresentationStateReport ¶ added in v0.5.0
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
func RequestTermcap ¶
RequestTermcap is an alias for XTGETTCAP.
func RequestTerminfo ¶ added in v0.5.0
RequestTerminfo is an alias for XTGETTCAP.
func ResetClipboard ¶
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 ¶
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
ResetKeyModifierOptions resets xterm key modifier options. This is an alias for KeyModifierOptions.
func ResetMode ¶ added in v0.5.0
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 function will returns two escape sequences.
ANSI format:
CSI Pd ; ... ; Pd l
DEC format:
CSI ? Pd ; ... ; Pd l
func ScreenPassthrough ¶
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 ¶
ScrollDown (SD) scrolls the screen down n lines. New lines are added at the top of the screen.
CSI Pn T
func ScrollUp ¶
ScrollUp (SU) scrolls the screen up n lines. New lines are added at the bottom of the screen.
CSI Pn S
func SecondaryDeviceAttributes ¶ added in v0.5.0
SecondaryDeviceAttributes (DA2) is a control sequence that reports the terminal's secondary device attributes.
CSI > c CSI > 0 c CSI > Ps ; ... c
func SelectCharacterSet ¶ added in v0.5.0
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)
func SelectGraphicRendition ¶ added in v0.5.0
Select Graphic Rendition (SGR) is a command that sets display attributes.
Default is 0.
CSI Ps ; Ps ... m
func SetBackgroundColor ¶
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 ¶
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 ¶
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
deprecated
added in
v0.4.0
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
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 ¶
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 ¶
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 ¶
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 ¶
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
SetKeyModifierOptions sets xterm key modifier options. This is an alias for KeyModifierOptions.
func SetLeftRightMargins ¶ added in v0.5.0
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
func SetMode ¶ added in v0.5.0
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 function will returns two escape sequences.
ANSI format:
CSI Pd ; ... ; Pd h
DEC format:
CSI ? Pd ; ... ; Pd h
func SetPointerShape ¶ added in v0.2.2
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 ¶
SetPrimaryClipboard returns a sequence for setting the primary clipboard.
This is equivalent to SetClipboard(PrimaryClipboard, d).
func SetScrollingRegion
deprecated
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 ¶
SetSystemClipboard returns a sequence for setting the system clipboard.
This is equivalent to SetClipboard(SystemClipboard, d).
func SetTopBottomMargins ¶ added in v0.5.0
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
func SetWindowTitle ¶
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 ¶
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. This treats the text as a sequence of grapheme clusters.
func StringWidthWc ¶ added in v0.8.0
StringWidthWc 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. This treats the text as a sequence of wide characters and runes.
func TabClear ¶ added in v0.5.0
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
func TabStopReport ¶ added in v0.5.0
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.
func TertiaryDeviceAttributes ¶ added in v0.5.0
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.
func TmuxPassthrough ¶
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 ¶
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-Asian characters and emojis). This treats the text as a sequence of graphemes.
func TruncateLeft ¶ added in v0.6.0
TruncateLeft truncates a string from the left side by removing n characters, adding a prefix to the beginning if the string is longer than n. This function is aware of ANSI escape codes and will not break them, and accounts for wide-characters (such as East-Asian characters and emojis). This treats the text as a sequence of graphemes.
func TruncateLeftWc ¶ added in v0.8.0
TruncateLeftWc truncates a string from the left side by removing n characters, adding a prefix to the beginning if the string is longer than n. This function is aware of ANSI escape codes and will not break them, and accounts for wide-characters (such as East-Asian characters and emojis). This treats the text as a sequence of wide characters and runes.
func TruncateWc ¶ added in v0.8.0
TruncateWc 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-Asian characters and emojis). This treats the text as a sequence of wide characters and runes.
func VerticalPositionAbsolute ¶ added in v0.5.0
VerticalPositionAbsolute (VPA) returns a sequence for moving the cursor to the given row.
Default is 1.
CSI n d
func VerticalPositionRelative ¶ added in v0.5.0
VerticalPositionRelative (VPR) returns a sequence for moving the cursor down n rows relative to the current position.
Default is 1.
CSI n e
func WindowOp ¶ added in v0.7.0
WindowOp (XTWINOPS) is a sequence that manipulates the terminal window.
CSI Ps ; Ps ; Ps t
Ps is a semicolon-separated list of parameters. See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps;Ps;Ps-t.1EB0
func Wordwrap ¶
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.
This treats the text as a sequence of graphemes.
func WordwrapWc ¶ added in v0.8.0
WordwrapWc 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.
This treats the text as a sequence of wide characters and runes.
func Wrap ¶
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.
This treats the text as a sequence of graphemes.
func WrapWc ¶ added in v0.8.0
WrapWc 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.
This treats the text as a sequence of wide characters and runes.
func WriteKittyGraphics ¶ added in v0.8.0
WriteKittyGraphics writes an image using the Kitty Graphics protocol with the given options to w. It chunks the written data if o.Chunk is true.
You can omit m and use nil when rendering an image from a file. In this case, you must provide a file path in o.File and use o.Transmission = kitty.File. You can also use o.Transmission = kitty.TempFile to write the image to a temporary file. In that case, the file path is ignored, and the image is written to a temporary file that is automatically deleted by the terminal.
func XParseColor ¶ added in v0.5.1
XParseColor is a helper function that parses a string into a color.Color. It provides a similar interface to the XParseColor function in Xlib. It supports the following formats:
- #RGB
- #RRGGBB
- rgb:RRRR/GGGG/BBBB
- rgba:RRRR/GGGG/BBBB/AAAA
If the string is not a valid color, nil is returned.
func XTGETTCAP ¶ added in v0.5.0
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
XTMODKEYS is an alias for KeyModifierOptions.
func XTQMODKEYS ¶ added in v0.5.0
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.
type ANSIStatusReport ¶ added in v0.8.0
type ANSIStatusReport int //nolint:revive
ANSIReport represents an ANSI terminal status report.
func (ANSIStatusReport) StatusReport ¶ added in v0.8.0
func (s ANSIStatusReport) StatusReport() int
Report returns the status report identifier.
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 )
type Cmd ¶ added in v0.2.0
type Cmd int
Cmd represents a sequence command. This is used to pack/unpack a sequence command with its intermediate and prefix characters. Those are commonly found in CSI and DCS sequences.
func (Cmd) Intermediate ¶ added in v0.2.0
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.
type 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
Colorizer is a color.Color interface that can be formatted as a string.
type DECStatusReport ¶ added in v0.8.0
type DECStatusReport int
DECStatusReport represents a DEC terminal status report.
func (DECStatusReport) StatusReport ¶ added in v0.8.0
func (s DECStatusReport) StatusReport() int
Status returns the status report identifier.
type ExtendedColor ¶
type ExtendedColor uint8
ExtendedColor is an ANSI 256 (8-bit) color with a value from 0 to 255.
type Handler ¶ added in v0.8.0
type Handler struct { // Print is called when a printable rune is encountered. Print func(r rune) // Execute is called when a control character is encountered. Execute func(b byte) // HandleCsi is called when a CSI sequence is encountered. HandleCsi func(cmd Cmd, params Params) // HandleEsc is called when an ESC sequence is encountered. HandleEsc func(cmd Cmd) // HandleDcs is called when a DCS sequence is encountered. HandleDcs func(cmd Cmd, params Params, data []byte) // HandleOsc is called when an OSC sequence is encountered. HandleOsc func(cmd int, data []byte) // HandlePm is called when a PM sequence is encountered. HandlePm func(data []byte) // HandleApc is called when an APC sequence is encountered. HandleApc func(data []byte) // HandleSos is called when a SOS sequence is encountered. HandleSos func(data []byte) }
Handler handles actions performed by the parser. It is used to handle ANSI escape sequences, control characters, and runes.
type HexColorizer ¶ added in v0.5.0
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 Method ¶ added in v0.8.0
type Method uint8
Method is a type that represents the how the renderer should calculate the display width of cells.
func (Method) Cut ¶ added in v0.8.0
Cut the string, without adding any prefix or tail strings. This function is aware of ANSI escape codes and will not break them, and accounts for wide-characters (such as East-Asian characters and emojis). Note that the [left] parameter is inclusive, while [right] isn't.
func (Method) DecodeSequence ¶ added in v0.8.0
func (m Method) DecodeSequence(data []byte, state byte, p *Parser) (seq []byte, width, 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 prefix characters. In the case of a OSC sequence, the cmd will be the OSC command number. Use Cmd and Param types to unpack command intermediates and prefixes as well as parameters.
Zero Cmd 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 Cmd in the most significant byte, the prefix 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 prefixes. The command byte is always the least significant byte i.e. [Cmd & 0xff]. Use the Cmd type to unpack the command, intermediate, and prefix bytes. Note that we only collect the last prefix 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 Param 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 (Method) DecodeSequenceInString ¶ added in v0.8.0
func (m Method) DecodeSequenceInString(data string, state byte, p *Parser) (seq string, width, n int, newState byte)
DecodeSequenceInString 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 prefix characters. In the case of a OSC sequence, the cmd will be the OSC command number. Use Cmd and Param types to unpack command intermediates and prefixes as well as parameters.
Zero Cmd 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 Cmd in the most significant byte, the prefix 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 prefixes. The command byte is always the least significant byte i.e. [Cmd & 0xff]. Use the Cmd type to unpack the command, intermediate, and prefix bytes. Note that we only collect the last prefix 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 Param 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 := DecodeSequenceInString(input, state, p) log.Printf("seq: %q, width: %d", seq, width) state = newState input = input[n:] }
func (Method) Hardwrap ¶ added in v0.8.0
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. This treats the text as a sequence of graphemes.
func (Method) StringWidth ¶ added in v0.8.0
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 (Method) Truncate ¶ added in v0.8.0
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-Asian characters and emojis).
func (Method) TruncateLeft ¶ added in v0.8.0
TruncateLeft truncates a string to a given length, adding a prefix to the beginning 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-Asian characters and emojis).
func (Method) Wordwrap ¶ added in v0.8.0
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 (Method) Wrap ¶ added in v0.8.0
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.
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 Modes ¶ added in v0.6.0
type Modes map[Mode]ModeSetting
Modes represents the terminal modes that can be set or reset. By default, all modes are ModeNotRecognized.
func NewModes ¶ added in v0.6.0
func NewModes() Modes
NewModes creates a new Modes map. By default, all modes are ModeNotRecognized.
func (Modes) Delete ¶ added in v0.6.0
Delete deletes a terminal mode. This has the same effect as setting the mode to ModeNotRecognized.
func (Modes) Get ¶ added in v0.6.0
func (m Modes) Get(mode Mode) ModeSetting
Get returns the setting of a terminal mode. If the mode is not set, it returns ModeNotRecognized.
func (Modes) IsPermanentlyReset ¶ added in v0.6.0
IsPermanentlyReset returns true if the mode is set to ModePermanentlyReset.
func (Modes) IsPermanentlySet ¶ added in v0.6.0
IsPermanentlySet returns true if the mode is set to ModePermanentlySet.
func (Modes) IsReset ¶ added in v0.6.0
IsReset returns true if the mode is set to ModeReset or ModePermanentlyReset.
func (Modes) IsSet ¶ added in v0.6.0
IsSet returns true if the mode is set to ModeSet or ModePermanentlySet.
func (Modes) PermanentlyReset ¶ added in v0.6.0
PermanentlyReset sets a terminal mode to ModePermanentlyReset.
func (Modes) PermanentlySet ¶ added in v0.6.0
PermanentlySet sets a terminal mode to ModePermanentlySet.
type MouseButton ¶ added in v0.6.0
type MouseButton byte
MouseButton represents the button that was pressed during a mouse message.
func (MouseButton) String ¶ added in v0.6.0
func (b MouseButton) String() string
String returns a string representation of the mouse button.
type Param ¶ added in v0.2.0
type Param int
Param 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.
type Params ¶
type Params []Param
Params represents a list of packed parameters.
func (Params) ForEach ¶ added in v0.8.0
ForEach iterates over the parameters and calls the given function for each parameter. If a parameter is part of a sub-parameter, it will be called with hasMore set to true. Use def to set a default value for missing parameters.
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() *Parser
NewParser returns a new parser with the default settings. 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 ¶
Advance advances the parser using the given byte. It returns the action performed by the parser.
func (*Parser) Command ¶ added in v0.8.0
Command returns the packed command of the last dispatched sequence. Use Cmd to unpack the command.
func (*Parser) Control ¶ added in v0.8.0
Control returns the last dispatched sequence as a control code.
func (*Parser) Param ¶ added in v0.5.0
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) Parse ¶
Parse parses the given dispatcher and byte buffer. Deprecated: Loop over the buffer and call Parser.Advance instead.
func (*Parser) SetDataSize ¶ added in v0.5.0
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) SetHandler ¶ added in v0.8.0
SetHandler sets the handler for the parser.
func (*Parser) SetParamsSize ¶ added in v0.5.0
SetParamsSize sets the size of the parameters buffer. This is used when constructing CSI and DCS sequences.
type State ¶ added in v0.2.0
type State = byte
State represents the state of the ANSI escape sequence parser used by DecodeSequence.
ANSI escape sequence states used by DecodeSequence.
type StatusReport ¶ added in v0.8.0
type StatusReport interface { // StatusReport returns the status report identifier. StatusReport() int }
StatusReport represents a terminal status report.
type Style ¶
type Style []string
Style represents an ANSI SGR (Select Graphic Rendition) style.
func (Style) BackgroundColor ¶
BackgroundColor appends the background color style attribute to the style.
func (Style) CurlyUnderline ¶
CurlyUnderline appends the curly underline style attribute to the style. This is a convenience method for UnderlineStyle(CurlyUnderlineStyle).
func (Style) DashedUnderline ¶
DashedUnderline appends the dashed underline style attribute to the style. This is a convenience method for UnderlineStyle(DashedUnderlineStyle).
func (Style) DefaultBackgroundColor ¶
DefaultBackgroundColor appends the default background color style attribute to the style.
func (Style) DefaultForegroundColor ¶
DefaultForegroundColor appends the default foreground color style attribute to the style.
func (Style) DefaultUnderlineColor ¶
DefaultUnderlineColor appends the default underline color style attribute to the style.
func (Style) DottedUnderline ¶
DottedUnderline appends the dotted underline style attribute to the style. This is a convenience method for UnderlineStyle(DottedUnderlineStyle).
func (Style) DoubleUnderline ¶
DoubleUnderline appends the double underline style attribute to the style. This is a convenience method for UnderlineStyle(DoubleUnderlineStyle).
func (Style) ForegroundColor ¶
ForegroundColor appends the foreground color style attribute to the style.
func (Style) NoConceal ¶ added in v0.1.2
NoConceal appends the no conceal style attribute to the style.
func (Style) NoStrikethrough ¶
NoStrikethrough appends the no strikethrough style attribute to the style.
func (Style) NoUnderline ¶
NoUnderline appends the no underline style attribute to the style.
func (Style) NormalIntensity ¶
NormalIntensity appends the normal intensity style attribute to the style.
func (Style) RapidBlink ¶
RapidBlink appends the rapid blink style attribute to the style.
func (Style) Strikethrough ¶
Strikethrough appends the strikethrough style attribute to the style.
func (Style) String ¶
String returns the ANSI SGR (Select Graphic Rendition) style sequence for the given style.
func (Style) UnderlineColor ¶
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)
type UnderlineStyle ¶ added in v0.3.0
type UnderlineStyle = byte
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
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
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.
Source Files
¶
- ansi.go
- ascii.go
- background.go
- c0.go
- c1.go
- charset.go
- clipboard.go
- color.go
- ctrl.go
- cursor.go
- cwd.go
- doc.go
- focus.go
- graphics.go
- hyperlink.go
- iterm2.go
- keypad.go
- kitty.go
- method.go
- mode.go
- modes.go
- mouse.go
- notification.go
- parser.go
- parser_decode.go
- parser_handler.go
- parser_sync.go
- passthrough.go
- paste.go
- reset.go
- screen.go
- sgr.go
- status.go
- style.go
- termcap.go
- title.go
- truncate.go
- util.go
- width.go
- winop.go
- wrap.go
- xterm.go