Source File
parser_handler.go
Belonging Package
github.com/charmbracelet/x/ansi
package ansiimport// Params represents a list of packed parameters.type Params []Param// Param returns the parameter at the given index and if it is part of a// sub-parameters. It 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 ( Params) (, int) (int, bool, bool) {if < 0 || >= len() {return , false, false}return [].Param(), [].HasMore(), true}// 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.func ( Params) ( int, func(, int, bool)) {for := range {(, [].Param(), [].HasMore())}}// ToParams converts a list of integers to a list of parameters.func ( []int) Params {return unsafe.Slice((*Param)(unsafe.Pointer(&[0])), len())}// Handler handles actions performed by the parser.// It is used to handle ANSI escape sequences, control characters, and runes.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)}// SetHandler sets the handler for the parser.func ( *Parser) ( Handler) {.handler =}
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64)