ansi

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxIntermediate = 4
	MaxCSIParams    = 24
	InlineCSIParams = 12
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APC

type APC struct {
	Data string
}

func (APC) String

func (seq APC) String() string

type C0

type C0 rune

A C0 control code

func (C0) String

func (seq C0) String() string

type CSI

type CSI struct {
	Intermediate    [MaxIntermediate]rune
	NumIntermediate int
	Parameters      [InlineCSIParams]uint32
	ExtraParameters []uint32
	NumParameters   int
	ColonSeparators uint32
	Final           rune
}

A CSI Sequence

func (CSI) ColonAfter

func (seq CSI) ColonAfter(i int) bool

func (CSI) Command

func (seq CSI) Command() string

func (CSI) Intermediates

func (seq CSI) Intermediates() []rune

func (CSI) Param

func (seq CSI) Param(i int) int

func (CSI) ParamGroup

func (seq CSI) ParamGroup(i int) []uint32

func (CSI) ParamGroupAt

func (seq CSI) ParamGroupAt(i int) ([]uint32, int)

func (CSI) ParameterGroups

func (seq CSI) ParameterGroups() [][]int

func (CSI) Params

func (seq CSI) Params() []uint32

func (CSI) String

func (seq CSI) String() string

type DCS

type DCS struct {
	Final           rune
	Intermediate    [MaxIntermediate]rune
	NumIntermediate int
	Parameters      [InlineCSIParams]uint32
	ExtraParameters []uint32
	NumParameters   int
	Data            []rune
}

Sent at the beginning of a DCS passthrough sequence.

func (DCS) Intermediates

func (seq DCS) Intermediates() []rune

func (DCS) Params

func (seq DCS) Params() []uint32

func (DCS) String

func (seq DCS) String() string

type EOF

type EOF struct{}

Sent when the underlying PTY is closed

func (EOF) String

func (seq EOF) String() string

type ESC

type ESC struct {
	Intermediate    [MaxIntermediate]rune
	NumIntermediate int
	Final           rune
}

An escape sequence with intermediate characters

func (ESC) Intermediates

func (seq ESC) Intermediates() []rune

func (ESC) String

func (seq ESC) String() string

type OSC

type OSC struct {
	Payload     []rune
	InvalidUTF8 bool
}

An OSC sequence. The Payload is the raw runes received, and must be parsed externally

func (OSC) String

func (seq OSC) String() string

type Parser

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

https://vt100.net/emu/dec_ansi_parser

parser is an implementation of Paul Flo Williams' VT500-series parser, as seen [here](https://vt100.net/emu/dec_ansi_parser). The architecture is designed after Rob Pike's text/template parser, with a few modifications.

Many of the comments are directly from Paul Flo Williams description of the parser, licensed undo [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/)

func NewParser

func NewParser(r io.Reader, modes ...ParserMode) *Parser

func (*Parser) Close

func (p *Parser) Close()

func (*Parser) Next

func (p *Parser) Next() <-chan Sequence

Next returns the next Sequence. Sequences will be of the following types:

error Sent on any parsing error
Print Print the character to the screen
C0    Execute the C0 code
ESC   Execute the ESC sequence
CSI   Execute the CSI sequence
OSC   Execute the OSC sequence
DCS   Execute the DCS sequence
EOF   Sent at end of input

func (*Parser) WaitClose

func (p *Parser) WaitClose()

type ParserMode

type ParserMode int

ParserMode controls how ambiguous parser input is interpreted.

const (
	// ParserModeInput parses terminal input, where a bare ESC keypress must be
	// disambiguated from the start of a longer escape sequence.
	ParserModeInput ParserMode = iota
	// ParserModeOutput parses application output, where ESC always starts an
	// output control sequence and should not be emitted by a timer.
	ParserModeOutput
)

type Print

type Print struct {
	Grapheme string
	Width    int
}

A character which should be printed to the screen

func (Print) String

func (seq Print) String() string

type SS3

type SS3 rune

func (SS3) String

func (seq SS3) String() string

type Sequence

type Sequence interface{}

Sequence is the generic data type of items emitted from the parser. These can be control sequences, escape sequences, or printable characters.

Jump to

Keyboard shortcuts

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