csi_entry_state.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package ansiterm
  2. type csiEntryState struct {
  3. baseState
  4. }
  5. func (csiState csiEntryState) Handle(b byte) (s state, e error) {
  6. csiState.parser.logf("CsiEntry::Handle %#x", b)
  7. nextState, err := csiState.baseState.Handle(b)
  8. if nextState != nil || err != nil {
  9. return nextState, err
  10. }
  11. switch {
  12. case sliceContains(alphabetics, b):
  13. return csiState.parser.ground, nil
  14. case sliceContains(csiCollectables, b):
  15. return csiState.parser.csiParam, nil
  16. case sliceContains(executors, b):
  17. return csiState, csiState.parser.execute()
  18. }
  19. return csiState, nil
  20. }
  21. func (csiState csiEntryState) Transition(s state) error {
  22. csiState.parser.logf("CsiEntry::Transition %s --> %s", csiState.Name(), s.Name())
  23. csiState.baseState.Transition(s)
  24. switch s {
  25. case csiState.parser.ground:
  26. return csiState.parser.csiDispatch()
  27. case csiState.parser.csiParam:
  28. switch {
  29. case sliceContains(csiParams, csiState.parser.context.currentChar):
  30. csiState.parser.collectParam()
  31. case sliceContains(intermeds, csiState.parser.context.currentChar):
  32. csiState.parser.collectInter()
  33. }
  34. }
  35. return nil
  36. }
  37. func (csiState csiEntryState) Enter() error {
  38. csiState.parser.clear()
  39. return nil
  40. }