2015-12-26 17:30:08 -05:00
|
|
|
package ansiterm
|
|
|
|
|
2016-07-08 20:49:32 -04:00
|
|
|
type escapeState struct {
|
|
|
|
baseState
|
2015-12-26 17:30:08 -05:00
|
|
|
}
|
|
|
|
|
2016-07-08 20:49:32 -04:00
|
|
|
func (escState escapeState) Handle(b byte) (s state, e error) {
|
|
|
|
logger.Infof("escapeState::Handle %#x", b)
|
|
|
|
nextState, err := escState.baseState.Handle(b)
|
2015-12-26 17:30:08 -05:00
|
|
|
if nextState != nil || err != nil {
|
|
|
|
return nextState, err
|
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case b == ANSI_ESCAPE_SECONDARY:
|
2016-07-08 20:49:32 -04:00
|
|
|
return escState.parser.csiEntry, nil
|
2015-12-26 17:30:08 -05:00
|
|
|
case b == ANSI_OSC_STRING_ENTRY:
|
2016-07-08 20:49:32 -04:00
|
|
|
return escState.parser.oscString, nil
|
|
|
|
case sliceContains(executors, b):
|
2015-12-26 17:30:08 -05:00
|
|
|
return escState, escState.parser.execute()
|
2016-07-08 20:49:32 -04:00
|
|
|
case sliceContains(escapeToGroundBytes, b):
|
|
|
|
return escState.parser.ground, nil
|
|
|
|
case sliceContains(intermeds, b):
|
|
|
|
return escState.parser.escapeIntermediate, nil
|
2015-12-26 17:30:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return escState, nil
|
|
|
|
}
|
|
|
|
|
2016-07-08 20:49:32 -04:00
|
|
|
func (escState escapeState) Transition(s state) error {
|
2015-12-26 17:30:08 -05:00
|
|
|
logger.Infof("Escape::Transition %s --> %s", escState.Name(), s.Name())
|
2016-07-08 20:49:32 -04:00
|
|
|
escState.baseState.Transition(s)
|
2015-12-26 17:30:08 -05:00
|
|
|
|
|
|
|
switch s {
|
2016-07-08 20:49:32 -04:00
|
|
|
case escState.parser.ground:
|
2015-12-26 17:30:08 -05:00
|
|
|
return escState.parser.escDispatch()
|
2016-07-08 20:49:32 -04:00
|
|
|
case escState.parser.escapeIntermediate:
|
2015-12-26 17:30:08 -05:00
|
|
|
return escState.parser.collectInter()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-07-08 20:49:32 -04:00
|
|
|
func (escState escapeState) Enter() error {
|
2015-12-26 17:30:08 -05:00
|
|
|
escState.parser.clear()
|
|
|
|
return nil
|
|
|
|
}
|