vt

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReverseIndex  = ESC + "M"
	SaveCursor    = ESC + "7"
	RestoreCursor = ESC + "8"
)

Simple Cursor Positioning

View Source
const (
	CursorUpFmt                        = CSI + "%dA"
	CursorDownFmt                      = CSI + "%dB"
	CursorRightFmt                     = CSI + "%dC"
	CursorLeftFmt                      = CSI + "%dD"
	CursorNextLineFmt                  = CSI + "%dE"
	CursorPrevLineFmt                  = CSI + "%dF"
	CursorHorizontalLineFmt            = CSI + "%dG"
	CursorVerticalLineFmt              = CSI + "%dd"
	CursorPositionFmt                  = CSI + "%d;%dH"
	CursorHorizontalVerticalPostionFmt = CSI + "%d;%df"
	SaveCursorAnsi                     = CSI + "s"
	RestoreCursorAnsi                  = CSI + "u"
)

Cursor Positioning

View Source
const (
	CursorBlink   = CSI + "?12h"
	CursorNoBlink = CSI + "?12l"
	CursorShow    = CSI + "?25h"
	CursorHide    = CSI + "?25l"
)

Cursor Visibility

View Source
const (
	CursorShapeDefault        = CSI + "0 q"
	CursorShapeBlockBlink     = CSI + "1 q"
	CursorShapeBlock          = CSI + "2 q"
	CursorShapeUnderlineBlink = CSI + "3 q"
	CursorShapeUnderline      = CSI + "4 q"
	CursorShapeBarBlink       = CSI + "5 q"
	CursorShapeBar            = CSI + "6 q"
)

Cursor Shape

View Source
const (
	KeypadApplicationMode = ESC + "="
	KeypadNumericMode     = ESC + ">"
)

Mode Changes See: https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#mode-changes

View Source
const (
	PasteBegin = CSI + "200~"
	PasteEnd   = CSI + "201~"
)
View Source
const (
	QueryCursorPosition   = CSI + "6n"
	QueryDeviceAttributes = CSI + "0c"
	QueryTerminalName     = CSI + ">q"

	QueryOSCFmt      = OSC + "%d;?" + BEL
	QueryFgColor     = OSC + "10;?" + BEL
	QueryBgColor     = OSC + "11;?" + BEL
	QueryCursorColor = OSC + "12;?" + BEL
)

Query State See: https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#query-state

View Source
const (
	SGRFmt   = CSI + "%dm"
	SGRReset = CSI + "0m"
)

Text Formatting See: https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-formatting

View Source
const (
	FgColor256Fmt = "38;5;%d"
	BgColor256Fmt = "48;5;%d"

	FgColorRGBFmt = "38;2;%d;%d;%d"
	BgColorRGBFmt = "48;2;%d;%d;%d"
)

Extended Colors

View Source
const (
	InsertCharFmt = CSI + "%d@"
	DeleteCharFmt = CSI + "%dP"
	EraseCharFmt  = CSI + "%dX"
	InsertLineFmt = CSI + "%dL"
	DeleteLineFmt = CSI + "%dM"

	EraseLineFromCursor = CSI + "0K"
	EraseLineFromStart  = CSI + "1K"
	EraseEntireLine     = CSI + "2K"

	EraseScreenToBottom = CSI + "0J"
	EraseEntireScreen   = CSI + "2J"
)

Text Modification See: https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-modification

View Source
const (
	ESC = "\x1b"
	CSI = ESC + "["
	OSC = ESC + "]"
	DCS = ESC + "P"
	SS3 = ESC + "O"
	ST  = ESC + "\\"
	BEL = "\a"
)

See: https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

View Source
const (
	DefaultEscapeTimeout = 20 * time.Millisecond
)
View Source
const (
	EscByte byte = 0x1B
)
View Source
const (
	ModifyScreenColorsFmt = OSC + "4;%d;rgb:%02x/%02x/%02x" + ST
)

Screen Colors

View Source
const (
	SetWindowTitleFmt = OSC + "2;%s" + ST
)
View Source
const (
	SoftReset = CSI + "!p"
)

Variables

View Source
var ErrInvalidSeq = fmt.Errorf("the sequence is invalid")
View Source
var SequenceToKey = map[string]Key{}/* 153 elements not displayed */

Functions

func EnterMode

func EnterMode(w io.Writer, m Mode) (restore func() error, err error)

func Events

func Events(reader iox.ContextReader) (func(ctx context.Context), <-chan any)

func ExitMode

func ExitMode(w io.Writer, m Mode) (restore func() error, err error)

func FormatSGR

func FormatSGR[T constraints.Integer](p ...T) string

func IsCSIFinalByte

func IsCSIFinalByte(b byte) bool

func IsESCFinalByte

func IsESCFinalByte(b byte) bool

func ScanCSI

func ScanCSI(ctx context.Context, i *InputBuffer) (next ScanFn, seq Sequence, err error)

func ScanDCS

func ScanDCS(ctx context.Context, i *InputBuffer) (next ScanFn, seq Sequence, err error)

func ScanInitial

func ScanInitial(ctx context.Context, i *InputBuffer) (next ScanFn, seq Sequence, err error)

func ScanInvalid

func ScanInvalid(ctx context.Context, i *InputBuffer) (next ScanFn, seq Sequence, err error)

func ScanMeta

func ScanMeta(ctx context.Context, i *InputBuffer) (next ScanFn, seq Sequence, err error)

func ScanOSC

func ScanOSC(ctx context.Context, i *InputBuffer) (next ScanFn, seq Sequence, err error)

func ScanPaste

func ScanPaste(ctx context.Context, i *InputBuffer) (next ScanFn, seq Sequence, err error)

func ScanSS3

func ScanSS3(ctx context.Context, i *InputBuffer) (next ScanFn, seq Sequence, err error)

func ScanUtf8

func ScanUtf8(ctx context.Context, i *InputBuffer) (next ScanFn, seq Sequence, err error)

Types

type Attr

type Attr uint32
const (
	AttrReset Attr = iota
	AttrBold
	AttrFaint
	AttrItalic
	AttrUnderline
	AttrBlinkSlow
	AttrBlinkRapid
	AttrReverseVideo
	AttrConceal
	AttrStrikethrough
)

SGR Parameter Codes

func (Attr) String

func (i Attr) String() string

type BgBrightColor

type BgBrightColor uint32
const (
	BgBrightBlack BgBrightColor = iota + 100
	BgBrightRed
	BgBrightGreen
	BgBrightYellow
	BgBrightBlue
	BgBrightMagenta
	BgBrightCyan
	BgBrightWhite
)

Background Colors (Bright/High Intensity)

func (BgBrightColor) String

func (i BgBrightColor) String() string

type BgColor

type BgColor uint32
const (
	BgBlack BgColor = iota + 40
	BgRed
	BgGreen
	BgYellow
	BgBlue
	BgMagenta
	BgCyan
	BgWhite

	BgDefault
)

Background Colors (40-47)

func (BgColor) String

func (i BgColor) String() string

type Color

type Color int
const (
	ColorBlack Color = iota
	ColorRed
	ColorGreen
	ColorYellow
	ColorBlue
	ColorMagenta
	ColorCyan
	ColorWhite

	ColorReset
)

type FgBrightColor

type FgBrightColor uint32
const (
	FgBrightBlack FgBrightColor = iota + 90
	FgBrightRed
	FgBrightGreen
	FgBrightYellow
	FgBrightBlue
	FgBrightMagenta
	FgBrightCyan
	FgBrightWhite
)

Foreground Colors (Bright/High Intensity)

func (FgBrightColor) String

func (i FgBrightColor) String() string

type FgColor

type FgColor uint32
const (
	FgBlack FgColor = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite

	FgDefault
)

Foreground Colors (30-37)

func (FgColor) String

func (i FgColor) String() string

type InputBuffer

type InputBuffer struct {
	*bufiox.ContextReader
	BurstTimeout time.Duration
}

func (*InputBuffer) PeekBurst

func (i *InputBuffer) PeekBurst(ctx context.Context, n int) ([]byte, error)

type Key

type Key int
const (
	KeyUnknown Key = iota

	KeyTab
	KeyShiftTab

	KeyUp
	KeyDown
	KeyRight
	KeyLeft

	KeyHome
	KeyEnd

	KeyCtrlUp
	KeyCtrlDown
	KeyCtrlRight
	KeyCtrlLeft

	KeyAltUp
	KeyAltDown
	KeyAltRight
	KeyAltLeft

	KeyShiftUp
	KeyShiftDown
	KeyShiftRight
	KeyShiftLeft

	KeySpace
	KeyEnter
	KeyBackspace
	KeyPause
	KeyEsc
	KeyInsert
	KeyDelete
	KeyPageUp
	KeyPageDown

	KeyCtrlEnter
	KeyCtrlBackspace

	KeyF1
	KeyF2
	KeyF3
	KeyF4
	KeyF5
	KeyF6
	KeyF7
	KeyF8
	KeyF9
	KeyF10
	KeyF11
	KeyF12

	KeyA
	KeyB
	KeyC
	KeyD
	KeyE
	KeyF
	KeyG
	KeyH
	KeyI
	KeyJ
	KeyK
	KeyL
	KeyM
	KeyN
	KeyO
	KeyP
	KeyQ
	KeyR
	KeyS
	KeyT
	KeyU
	KeyV
	KeyW
	KeyX
	KeyY
	KeyZ

	KeyCtrlA
	KeyCtrlB
	KeyCtrlC
	KeyCtrlD
	KeyCtrlE
	KeyCtrlF
	KeyCtrlG
	KeyCtrlH
	KeyCtrlI
	KeyCtrlJ
	KeyCtrlK
	KeyCtrlL
	KeyCtrlM
	KeyCtrlN
	KeyCtrlO
	KeyCtrlP
	KeyCtrlQ
	KeyCtrlR
	KeyCtrlS
	KeyCtrlT
	KeyCtrlU
	KeyCtrlV
	KeyCtrlW
	KeyCtrlX
	KeyCtrlY
	KeyCtrlZ

	KeyShiftA
	KeyShiftB
	KeyShiftC
	KeyShiftD
	KeyShiftE
	KeyShiftF
	KeyShiftG
	KeyShiftH
	KeyShiftI
	KeyShiftJ
	KeyShiftK
	KeyShiftL
	KeyShiftM
	KeyShiftN
	KeyShiftO
	KeyShiftP
	KeyShiftQ
	KeyShiftR
	KeyShiftS
	KeyShiftT
	KeyShiftU
	KeyShiftV
	KeyShiftW
	KeyShiftX
	KeyShiftY
	KeyShiftZ

	KeyAltA
	KeyAltB
	KeyAltC
	KeyAltD
	KeyAltE
	KeyAltF
	KeyAltG
	KeyAltH
	KeyAltI
	KeyAltJ
	KeyAltK
	KeyAltL
	KeyAltM
	KeyAltN
	KeyAltO
	KeyAltP
	KeyAltQ
	KeyAltR
	KeyAltS
	KeyAltT
	KeyAltU
	KeyAltV
	KeyAltW
	KeyAltX
	KeyAltY
	KeyAltZ

	KeyAlt0
	KeyAlt1
	KeyAlt2
	KeyAlt3
	KeyAlt4
	KeyAlt5
	KeyAlt6
	KeyAlt7
	KeyAlt8
	KeyAlt9
)

func (Key) Equivalents

func (k Key) Equivalents() []Key

func (Key) Normalize

func (k Key) Normalize() Key

func (Key) String

func (i Key) String() string

type KeyEvent

type KeyEvent struct {
	Key  Key
	Rune rune
}

func (KeyEvent) IsKey

func (e KeyEvent) IsKey(keys ...Key) bool

func (KeyEvent) IsRune

func (e KeyEvent) IsRune(r rune) bool

type Mode

type Mode int
const (
	ModeCursorKeys      Mode = 1
	ModeShowCursor      Mode = 25
	ModeMouseAll        Mode = 1003
	ModeAlternateScreen Mode = 1049
	ModeBracketedPaste  Mode = 2004
)

func (Mode) Disable

func (m Mode) Disable() string

func (Mode) Enable

func (m Mode) Enable() string

type PasteEvent

type PasteEvent struct {
	Bytes []byte
}

type ScanFn

type ScanFn func(ctx context.Context, i *InputBuffer) (next ScanFn, seq Sequence, err error)

type Sequence

type Sequence struct {
	Data []byte
	Type SequenceType
}

func (Sequence) Is

func (s Sequence) Is(types ...SequenceType) bool

type SequenceScanner

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

func NewSequenceScanner

func NewSequenceScanner(r iox.ContextReader, f ScanFn) *SequenceScanner

func (*SequenceScanner) Err

func (s *SequenceScanner) Err() error

func (*SequenceScanner) ScanContext

func (s *SequenceScanner) ScanContext(ctx context.Context) bool

func (*SequenceScanner) Sequence

func (s *SequenceScanner) Sequence() Sequence

func (*SequenceScanner) SetBurstTimeout

func (s *SequenceScanner) SetBurstTimeout(d time.Duration)

type SequenceType

type SequenceType int
const (
	SeqUnknown SequenceType = iota
	SeqEscape
	SeqUTF8
	SeqCSI
	SeqOSC
	SeqDCS
	SeqSS3
	SeqMeta
	SeqPaste
)

func (SequenceType) String

func (i SequenceType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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