Documentation ¶
Index ¶
- Constants
- Variables
- func Command(cmd int) int
- func HasMore(params []int, i int) bool
- func Intermediate(cmd int) int
- func Len(params []int) int
- func Marker(cmd int) int
- func Param(params []int, i int) int
- func Range(params []int, fn func(i int, param int, hasMore bool) bool)
- func Subparams(params []int, i int) []int
- type Action
- type State
- type TransitionTable
- func (t TransitionTable) AddMany(codes []byte, state State, action Action, next State)
- func (t TransitionTable) AddOne(code byte, state State, action Action, next State)
- func (t TransitionTable) AddRange(start, end byte, state State, action Action, next State)
- func (t TransitionTable) SetDefault(action Action, state State)
- func (t TransitionTable) Transition(state State, code byte) (State, Action)
Constants ¶
const ( MarkerShift = 8 IntermedShift = 16 CommandMask = 0xff HasMoreFlag = math.MinInt32 ParamMask = ^HasMoreFlag MissingParam = ParamMask MissingCommand = MissingParam MaxParam = math.MaxUint16 // the maximum value a parameter can have )
Shift and masks for sequence parameters and intermediates.
const ( // MaxParamsSize is the maximum number of parameters a sequence can have. MaxParamsSize = 32 // DefaultParamValue is the default value used for missing parameters. DefaultParamValue = 0 )
const ( TransitionActionShift = 4 TransitionStateMask = 15 IndexStateShift = 8 // DefaultTableSize is the default size of the transition table. DefaultTableSize = 4096 )
Table values are generated like this:
index: currentState << IndexStateShift | charCode value: action << TransitionActionShift | nextState
Variables ¶
var ActionNames = []string{
"NoneAction",
"ClearAction",
"CollectAction",
"MarkerAction",
"DispatchAction",
"ExecuteAction",
"StartAction",
"PutAction",
"ParamAction",
"PrintAction",
}
nolint: unused
var StateNames = []string{
"GroundState",
"CsiEntryState",
"CsiIntermediateState",
"CsiParamState",
"DcsEntryState",
"DcsIntermediateState",
"DcsParamState",
"DcsStringState",
"EscapeState",
"EscapeIntermediateState",
"OscStringState",
"SosStringState",
"PmStringState",
"ApcStringState",
"Utf8State",
}
nolint: unused
var Table = GenerateTransitionTable()
Table is a DEC ANSI transition table.
Functions ¶
func Intermediate ¶
Intermediate returns the intermediate byte of the 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.
func Len ¶
Len returns the number of parameters in the sequence. This will return the number of parameters in the sequence, excluding any sub-parameters.
func Marker ¶
Marker returns the marker byte of the sequence. This is always gonna be one of the following '<' '=' '>' '?' and in the range of 0x3C-0x3F. Zero is returned if the sequence does not have a marker.
func Param ¶
Param returns the parameter at the given index. It returns -1 if the parameter does not exist.
Types ¶
type Action ¶
type Action = byte
Action is a DEC ANSI parser action.
const ( NoneAction Action = iota ClearAction CollectAction MarkerAction DispatchAction ExecuteAction StartAction // Start of a data string PutAction // Put into the data string ParamAction PrintAction IgnoreAction = NoneAction )
These are the actions that the parser can take.
type State ¶
type State = byte
State is a DEC ANSI parser state.
const ( GroundState State = iota CsiEntryState CsiIntermediateState CsiParamState DcsEntryState DcsIntermediateState DcsParamState DcsStringState EscapeState EscapeIntermediateState OscStringState SosStringState PmStringState ApcStringState // Utf8State is not part of the DEC ANSI standard. It is used to handle // UTF-8 sequences. Utf8State )
These are the states that the parser can be in.
type TransitionTable ¶
type TransitionTable []byte
TransitionTable is a DEC ANSI transition table. https://vt100.net/emu/dec_ansi_parser
func GenerateTransitionTable ¶
func GenerateTransitionTable() TransitionTable
GenerateTransitionTable generates a DEC ANSI transition table compatible with the VT500-series of terminals. This implementation includes a few modifications that include:
- A new Utf8State is introduced to handle UTF8 sequences.
- Osc and Dcs data accept UTF8 sequences by extending the printable range to 0xFF and 0xFE respectively.
- We don't ignore 0x3A (':') when building Csi and Dcs parameters and instead use it to denote sub-parameters.
- Support dispatching SosPmApc sequences.
func NewTransitionTable ¶
func NewTransitionTable(size int) TransitionTable
NewTransitionTable returns a new DEC ANSI transition table.
func (TransitionTable) AddMany ¶
func (t TransitionTable) AddMany(codes []byte, state State, action Action, next State)
AddMany adds many transitions.
func (TransitionTable) AddOne ¶
func (t TransitionTable) AddOne(code byte, state State, action Action, next State)
AddOne adds a transition.
func (TransitionTable) AddRange ¶
func (t TransitionTable) AddRange(start, end byte, state State, action Action, next State)
AddRange adds a range of transitions.
func (TransitionTable) SetDefault ¶
func (t TransitionTable) SetDefault(action Action, state State)
SetDefault sets default transition.
func (TransitionTable) Transition ¶
func (t TransitionTable) Transition(state State, code byte) (State, Action)
Transition returns the next state and action for the given state and byte.