diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2022-08-23 22:09:14 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2022-08-23 22:09:14 +0100 |
commit | ececdecdaf6c6f6295d31a92f0663d703e7760dd (patch) | |
tree | 4b747448e546b8fdcb0c0196d981f32369c636f8 /main/command.go | |
download | stred-go-ececdecdaf6c6f6295d31a92f0663d703e7760dd.tar |
Initial commit
No parsing yet, but the execution is not bad
Commands:
- Print value
- Toggle terminal (switch between array and map)
- Filter command
Filters:
- Path filter
Path filters are compiled from a regex like AST
Diffstat (limited to 'main/command.go')
-rw-r--r-- | main/command.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/main/command.go b/main/command.go new file mode 100644 index 0000000..560d3c3 --- /dev/null +++ b/main/command.go @@ -0,0 +1,38 @@ +package main + +type PrintValueCommand struct {} +func (cmd PrintValueCommand) exec(state *ProgramState) { + state.out <- state.space +} + +type ToggleTerminalCommand struct {} +func (cmd ToggleTerminalCommand) exec(state *ProgramState) { + terminal, isTerminal := state.space.value.(TerminalValue) + if !isTerminal { + return + } + switch terminal { + case ArrayBegin: + state.space.value = MapBegin + case ArrayEnd: + state.space.value = MapEnd + case MapBegin: + state.space.value = ArrayBegin + case MapEnd: + state.space.value = ArrayEnd + } +} + +type FilteredCommand struct { + filter Filter + command Command +} +func (cmd FilteredCommand) exec(state *ProgramState) { + if cmd.filter.exec(state) { + cmd.command.exec(state) + } +} + +type Command interface { + exec(*ProgramState) +}
\ No newline at end of file |