2015-04-16 17:01:37 -04:00
|
|
|
package ansiterm
|
|
|
|
|
2016-04-25 18:55:12 -04:00
|
|
|
type escapeState struct {
|
|
|
|
baseState
|
2015-04-16 17:01:37 -04:00
|
|
|
}
|
|
|
|
|
2016-04-25 18:55:12 -04:00
|
|
|
func (escState escapeState) Handle(b byte) (s state, e error) {
|
2017-10-02 03:46:20 -04:00
|
|
|
escState.parser.logf("escapeState::Handle %#x", b)
|
2016-04-25 18:55:12 -04:00
|
|
|
nextState, err := escState.baseState.Handle(b)
|
2015-04-16 17:01:37 -04:00
|
|
|
if nextState != nil || err != nil {
|
|
|
|
return nextState, err
|
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case b == ANSI_ESCAPE_SECONDARY:
|
2016-04-25 18:55:12 -04:00
|
|
|
return escState.parser.csiEntry, nil
|
2015-04-16 17:01:37 -04:00
|
|
|
case b == ANSI_OSC_STRING_ENTRY:
|
2016-04-25 18:55:12 -04:00
|
|
|
return escState.parser.oscString, nil
|
|
|
|
case sliceContains(executors, b):
|
2015-04-16 17:01:37 -04:00
|
|
|
return escState, escState.parser.execute()
|
2016-04-25 18:55:12 -04:00
|
|
|
case sliceContains(escapeToGroundBytes, b):
|
|
|
|
return escState.parser.ground, nil
|
|
|
|
case sliceContains(intermeds, b):
|
|
|
|
return escState.parser.escapeIntermediate, nil
|
2015-04-16 17:01:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return escState, nil
|
|
|
|
}
|
|
|
|
|
2016-04-25 18:55:12 -04:00
|
|
|
func (escState escapeState) Transition(s state) error {
|
2017-10-02 03:46:20 -04:00
|
|
|
escState.parser.logf("Escape::Transition %s --> %s", escState.Name(), s.Name())
|
2016-04-25 18:55:12 -04:00
|
|
|
escState.baseState.Transition(s)
|
2015-04-16 17:01:37 -04:00
|
|
|
|
|
|
|
switch s {
|
2016-04-25 18:55:12 -04:00
|
|
|
case escState.parser.ground:
|
2015-04-16 17:01:37 -04:00
|
|
|
return escState.parser.escDispatch()
|
2016-04-25 18:55:12 -04:00
|
|
|
case escState.parser.escapeIntermediate:
|
2015-04-16 17:01:37 -04:00
|
|
|
return escState.parser.collectInter()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-25 18:55:12 -04:00
|
|
|
func (escState escapeState) Enter() error {
|
2015-04-16 17:01:37 -04:00
|
|
|
escState.parser.clear()
|
|
|
|
return nil
|
|
|
|
}
|