open-vault/vendor/github.com/Azure/go-ansiterm/escape_state.go

48 lines
1.1 KiB
Go
Raw Normal View History

2017-02-26 21:53:19 +00:00
package ansiterm
type escapeState struct {
baseState
}
func (escState escapeState) Handle(b byte) (s state, e error) {
2017-10-27 19:06:04 +00:00
escState.parser.logf("escapeState::Handle %#x", b)
2017-02-26 21:53:19 +00:00
nextState, err := escState.baseState.Handle(b)
if nextState != nil || err != nil {
return nextState, err
}
switch {
case b == ANSI_ESCAPE_SECONDARY:
return escState.parser.csiEntry, nil
case b == ANSI_OSC_STRING_ENTRY:
return escState.parser.oscString, nil
case sliceContains(executors, b):
return escState, escState.parser.execute()
case sliceContains(escapeToGroundBytes, b):
return escState.parser.ground, nil
case sliceContains(intermeds, b):
return escState.parser.escapeIntermediate, nil
}
return escState, nil
}
func (escState escapeState) Transition(s state) error {
2017-10-27 19:06:04 +00:00
escState.parser.logf("Escape::Transition %s --> %s", escState.Name(), s.Name())
2017-02-26 21:53:19 +00:00
escState.baseState.Transition(s)
switch s {
case escState.parser.ground:
return escState.parser.escDispatch()
case escState.parser.escapeIntermediate:
return escState.parser.collectInter()
}
return nil
}
func (escState escapeState) Enter() error {
escState.parser.clear()
return nil
}