summaryrefslogtreecommitdiff
path: root/vendor/github.com/Azure/go-ansiterm/escape_state.go
blob: 6390abd231bac485a500b7ac96b8672b70cebe97 (plain)
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
package ansiterm

type escapeState struct {
	baseState
}

func (escState escapeState) Handle(b byte) (s state, e error) {
	escState.parser.logf("escapeState::Handle %#x", b)
	nextState, err := escState.baseState.Handle(b)
	if nextState != nil || err != nil {
		return nextState, err
	}

	switch {
	case b == ANSI_ESCAPE_SECONDARY:
		return escState.parser.csiEntry, nil
	case b == ANSI_OSC_STRING_ENTRY:
		return escState.parser.oscString, nil
	case sliceContains(executors, b):
		return escState, escState.parser.execute()
	case sliceContains(escapeToGroundBytes, b):
		return escState.parser.ground, nil
	case sliceContains(intermeds, b):
		return escState.parser.escapeIntermediate, nil
	}

	return escState, nil
}

func (escState escapeState) Transition(s state) error {
	escState.parser.logf("Escape::Transition %s --> %s", escState.Name(), s.Name())
	escState.baseState.Transition(s)

	switch s {
	case escState.parser.ground:
		return escState.parser.escDispatch()
	case escState.parser.escapeIntermediate:
		return escState.parser.collectInter()
	}

	return nil
}

func (escState escapeState) Enter() error {
	escState.parser.clear()
	return nil
}