File: csi_entry_state.go

package info (click to toggle)
golang-github-azure-go-ansiterm 0.0~git20160622.0.fa152c5-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 252 kB
  • sloc: makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,162 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package ansiterm

type csiEntryState struct {
	baseState
}

func (csiState csiEntryState) Handle(b byte) (s state, e error) {
	logger.Infof("CsiEntry::Handle %#x", b)

	nextState, err := csiState.baseState.Handle(b)
	if nextState != nil || err != nil {
		return nextState, err
	}

	switch {
	case sliceContains(alphabetics, b):
		return csiState.parser.ground, nil
	case sliceContains(csiCollectables, b):
		return csiState.parser.csiParam, nil
	case sliceContains(executors, b):
		return csiState, csiState.parser.execute()
	}

	return csiState, nil
}

func (csiState csiEntryState) Transition(s state) error {
	logger.Infof("CsiEntry::Transition %s --> %s", csiState.Name(), s.Name())
	csiState.baseState.Transition(s)

	switch s {
	case csiState.parser.ground:
		return csiState.parser.csiDispatch()
	case csiState.parser.csiParam:
		switch {
		case sliceContains(csiParams, csiState.parser.context.currentChar):
			csiState.parser.collectParam()
		case sliceContains(intermeds, csiState.parser.context.currentChar):
			csiState.parser.collectInter()
		}
	}

	return nil
}

func (csiState csiEntryState) Enter() error {
	csiState.parser.clear()
	return nil
}