2015-04-16 17:01:37 -04:00
|
|
|
package ansiterm
|
|
|
|
|
2016-04-25 18:55:12 -04:00
|
|
|
type csiEntryState struct {
|
|
|
|
baseState
|
2015-04-16 17:01:37 -04:00
|
|
|
}
|
|
|
|
|
2016-04-25 18:55:12 -04:00
|
|
|
func (csiState csiEntryState) Handle(b byte) (s state, e error) {
|
2015-04-16 17:01:37 -04:00
|
|
|
logger.Infof("CsiEntry::Handle %#x", b)
|
|
|
|
|
2016-04-25 18:55:12 -04:00
|
|
|
nextState, err := csiState.baseState.Handle(b)
|
2015-04-16 17:01:37 -04:00
|
|
|
if nextState != nil || err != nil {
|
|
|
|
return nextState, err
|
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
2016-04-25 18:55:12 -04:00
|
|
|
case sliceContains(alphabetics, b):
|
|
|
|
return csiState.parser.ground, nil
|
|
|
|
case sliceContains(csiCollectables, b):
|
|
|
|
return csiState.parser.csiParam, nil
|
|
|
|
case sliceContains(executors, b):
|
2015-04-16 17:01:37 -04:00
|
|
|
return csiState, csiState.parser.execute()
|
|
|
|
}
|
|
|
|
|
|
|
|
return csiState, nil
|
|
|
|
}
|
|
|
|
|
2016-04-25 18:55:12 -04:00
|
|
|
func (csiState csiEntryState) Transition(s state) error {
|
2015-04-16 17:01:37 -04:00
|
|
|
logger.Infof("CsiEntry::Transition %s --> %s", csiState.Name(), s.Name())
|
2016-04-25 18:55:12 -04:00
|
|
|
csiState.baseState.Transition(s)
|
2015-04-16 17:01:37 -04:00
|
|
|
|
|
|
|
switch s {
|
2016-04-25 18:55:12 -04:00
|
|
|
case csiState.parser.ground:
|
2015-04-16 17:01:37 -04:00
|
|
|
return csiState.parser.csiDispatch()
|
2016-04-25 18:55:12 -04:00
|
|
|
case csiState.parser.csiParam:
|
2015-04-16 17:01:37 -04:00
|
|
|
switch {
|
2016-04-25 18:55:12 -04:00
|
|
|
case sliceContains(csiParams, csiState.parser.context.currentChar):
|
2015-04-16 17:01:37 -04:00
|
|
|
csiState.parser.collectParam()
|
2016-04-25 18:55:12 -04:00
|
|
|
case sliceContains(intermeds, csiState.parser.context.currentChar):
|
2015-04-16 17:01:37 -04:00
|
|
|
csiState.parser.collectInter()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-25 18:55:12 -04:00
|
|
|
func (csiState csiEntryState) Enter() error {
|
2015-04-16 17:01:37 -04:00
|
|
|
csiState.parser.clear()
|
|
|
|
return nil
|
|
|
|
}
|