* simv2: wip * simulation: exec adapter start/stop * simulation: add node status to exec adapter * simulation: initial simulation code * simulation: exec adapter, configure path to executable * simulation: initial docker adapter * simulation: wip kubernetes adapter * simulation: kubernetes adapter proxy * simulation: implement GetAll/StartAll/StopAll * simulation: kuberentes adapter - set env vars and resource limits * simulation: discovery test * simulation: remove port definitions within docker adapter * simulation: simplify wait for healthy loop * simulation: get nat ip addr from interface * simulation: pull docker images automatically * simulation: NodeStatus -> NodeInfo * simulation: move discovery test to example dir * simulation: example snapshot usage * simulation: add goclient specific simulation * simulation: add peer connections to snapshot * simulation: close rpc client * simulation: don't export kubernetes proxy server * simulation: merge simulation code * simulation: don't export nodemap * simulation: rename SimulationSnapshot -> Snapshot * simulation: linting fixes * simulation: add k8s available helper func * simulation: vendor * simulation: fix 'no non-test Go files' when building * simulation: remove errors from interface methods where non were returned * simulation: run getHealthInfo check in parallel
72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
package ansiterm
|
|
|
|
type stateID int
|
|
|
|
type state interface {
|
|
Enter() error
|
|
Exit() error
|
|
Handle(byte) (state, error)
|
|
Name() string
|
|
Transition(state) error
|
|
}
|
|
|
|
type baseState struct {
|
|
name string
|
|
parser *AnsiParser
|
|
}
|
|
|
|
func (base baseState) Enter() error {
|
|
return nil
|
|
}
|
|
|
|
func (base baseState) Exit() error {
|
|
return nil
|
|
}
|
|
|
|
func (base baseState) Handle(b byte) (s state, e error) {
|
|
|
|
switch {
|
|
case b == CSI_ENTRY:
|
|
return base.parser.csiEntry, nil
|
|
case b == DCS_ENTRY:
|
|
return base.parser.dcsEntry, nil
|
|
case b == ANSI_ESCAPE_PRIMARY:
|
|
return base.parser.escape, nil
|
|
case b == OSC_STRING:
|
|
return base.parser.oscString, nil
|
|
case sliceContains(toGroundBytes, b):
|
|
return base.parser.ground, nil
|
|
}
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
func (base baseState) Name() string {
|
|
return base.name
|
|
}
|
|
|
|
func (base baseState) Transition(s state) error {
|
|
if s == base.parser.ground {
|
|
execBytes := []byte{0x18}
|
|
execBytes = append(execBytes, 0x1A)
|
|
execBytes = append(execBytes, getByteRange(0x80, 0x8F)...)
|
|
execBytes = append(execBytes, getByteRange(0x91, 0x97)...)
|
|
execBytes = append(execBytes, 0x99)
|
|
execBytes = append(execBytes, 0x9A)
|
|
|
|
if sliceContains(execBytes, base.parser.context.currentChar) {
|
|
return base.parser.execute()
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type dcsEntryState struct {
|
|
baseState
|
|
}
|
|
|
|
type errorState struct {
|
|
baseState
|
|
}
|