2015-04-16 17:01:37 -04:00
|
|
|
package ansiterm
|
|
|
|
|
2016-04-25 18:55:12 -04:00
|
|
|
type csiParamState struct {
|
|
|
|
baseState
|
2015-04-16 17:01:37 -04:00
|
|
|
}
|
|
|
|
|
2016-04-25 18:55:12 -04:00
|
|
|
func (csiState csiParamState) Handle(b byte) (s state, e error) {
|
2015-04-16 17:01:37 -04:00
|
|
|
logger.Infof("CsiParam::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):
|
2015-04-16 17:01:37 -04:00
|
|
|
csiState.parser.collectParam()
|
|
|
|
return csiState, nil
|
2016-04-25 18:55:12 -04:00
|
|
|
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 csiParamState) Transition(s state) error {
|
2015-04-16 17:01:37 -04:00
|
|
|
logger.Infof("CsiParam::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()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|