package ansi ¶
import "golazy.dev/lazytui/encoding/ansi"
Functions ¶
func Append ¶
Append appends op's ANSI byte representation to dst.
func Append(dst []byte, op Op) []byte
Types ¶
type CSIToken ¶
CSIToken contains a Control Sequence Introducer sequence.
type CSIToken struct {
Prefix string
Params []Param
Intermediates string
Final byte
Raw []byte
}
type ControlToken ¶
ControlToken contains a single C0/C1-style control byte.
type ControlToken struct {
Code codes.Control
}
type Decoder ¶
Decoder incrementally decodes ANSI and VT terminal streams.
type Decoder struct {
// contains filtered or unexported fields
}
{
var decoder Decoder
tokens, _ := decoder.Decode([]byte("\x1b[2JHi"))
for _, token := range tokens {
fmt.Printf("%T\n", token)
}
}
ansi.CSIToken
ansi.PrintToken
func (d *Decoder) Decode ¶
Decode consumes data and returns any complete tokens found.
func (d *Decoder) Decode(data []byte) ([]Token, error)
func (d *Decoder) Reset ¶
Reset clears the decoder state and drops buffered incomplete input.
func (d *Decoder) Reset()
type Encoder ¶
Encoder writes terminal operations to an io.Writer.
type Encoder struct{}
{
var buf bytes.Buffer
encoder := &Encoder{}
_ = encoder.Encode(&buf, SGR(codes.Bold, codes.FgRGB(1, 2, 3)))
_ = encoder.Encode(&buf, Print("Lazy"))
_ = encoder.Encode(&buf, SGR(codes.Reset))
fmt.Printf("%q\n", buf.String())
}
"\x1b[1;38;2;1;2;3mLazy\x1b[0m"
func (e *Encoder) Encode ¶
Encode writes op to w.
func (e *Encoder) Encode(w io.Writer, op Op) error
type EscapeToken ¶
EscapeToken contains an ESC sequence with a single final byte.
type EscapeToken struct {
Final byte
Raw []byte
}
type HyperlinkToken ¶
HyperlinkToken reports an OSC 8 hyperlink command. An empty URL ends the current hyperlink.
type HyperlinkToken struct {
Params string
URL string
Raw []byte
}
type MouseToken ¶
MouseToken reports an SGR mouse event.
type MouseToken struct {
Button int
Row int
Col int
Release bool
Raw []byte
}
type OSCTerminator ¶
OSCTerminator identifies how an OSC sequence was terminated.
type OSCTerminator uint8
type OSCToken ¶
OSCToken contains an Operating System Command sequence.
type OSCToken struct {
Command string
Data string
Terminator OSCTerminator
Raw []byte
}
type Op ¶
Op is an encodable terminal operation.
type Op interface {
// contains filtered or unexported methods
}
func CSI ¶
CSI returns an operation for a CSI sequence with numeric parameters.
func CSI(final byte, params ...int) Op
func CSIWithPrefix ¶
CSIWithPrefix returns a CSI operation with a private or extension prefix.
func CSIWithPrefix(prefix string, final byte, params ...int) Op
func Control ¶
Control returns an operation for a single control byte.
func Control(code codes.Control) Op
func CursorBack ¶
CursorBack moves the cursor left n columns.
func CursorBack(n int) Op
func CursorDown ¶
CursorDown moves the cursor down n rows.
func CursorDown(n int) Op
func CursorForward ¶
CursorForward moves the cursor right n columns.
func CursorForward(n int) Op
func CursorPosition ¶
CursorPosition moves the cursor to row and col, both 1-based.
func CursorPosition(row, col int) Op
func CursorUp ¶
CursorUp moves the cursor up n rows.
func CursorUp(n int) Op
func DisableMouse ¶
DisableMouse disables common xterm-compatible mouse tracking modes.
func DisableMouse() Op
func EnableMouse ¶
EnableMouse enables button-event mouse tracking with SGR coordinates.
func EnableMouse() Op
func EndHyperlink ¶
EndHyperlink ends the current OSC 8 hyperlink.
func EndHyperlink() Op
func EraseDisplay ¶
EraseDisplay erases part of the display according to mode.
func EraseDisplay(mode int) Op
func EraseLine ¶
EraseLine erases part of the current line according to mode.
func EraseLine(mode int) Op
func Escape ¶
Escape returns an operation for a simple ESC sequence.
func Escape(final byte) Op
func Hyperlink ¶
Hyperlink starts an OSC 8 hyperlink.
func Hyperlink(url string) Op
func OSC ¶
OSC returns an Operating System Command operation terminated with ST.
func OSC(command int, data string) Op
func Print ¶
Print returns an operation that writes printable text.
func Print(text string) Op
func RequestWindowSize ¶
RequestWindowSize asks an xterm-compatible terminal to report text-area size.
func RequestWindowSize() Op
func SGR ¶
SGR returns a Select Graphic Rendition operation.
func SGR(parts ...codes.SGR) Op
func Sequence ¶
Sequence returns an operation that writes each op in order.
func Sequence(ops ...Op) Op
func WindowSizeReport ¶
WindowSizeReport encodes an xterm-compatible text-area size report.
func WindowSizeReport(rows, cols int) Op
func WindowTitle ¶
WindowTitle sets the terminal window title.
func WindowTitle(title string) Op
type Param ¶
Param is a CSI parameter. Empty parameters are preserved as nil or empty slices so callers can apply command-specific defaults.
type Param []int
type PrintToken ¶
PrintToken contains printable text.
type PrintToken struct {
Text string
}
type Token ¶
Token is a decoded ANSI stream item.
type Token interface {
// contains filtered or unexported methods
}
type UnknownToken ¶
UnknownToken preserves a complete but unsupported or malformed sequence.
type UnknownToken struct {
Raw []byte
Reason string
}
type WindowSizeToken ¶
WindowSizeToken reports a terminal size from an xterm-compatible response.
type WindowSizeToken struct {
Rows int
Cols int
Raw []byte
}
type WindowTitleToken ¶
WindowTitleToken reports an OSC window title command.
type WindowTitleToken struct {
Title string
Raw []byte
}
Directories ¶
| Path | Synopsis |
|---|---|
| lazytui/encoding/ansi/codes | Package codes defines ANSI, ECMA-48, and common terminal extension codes. |
Package ansi encodes and decodes ANSI and VT terminal byte streams.
The package is deliberately protocol-level. It turns byte streams into tokens and tokens or operations into byte streams, but it does not mutate a terminal screen. Terminal emulation belongs in higher-level lazytui packages.