<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/command.go
diff options
context:
space:
mode:
Diffstat (limited to 'main/command.go')
-rw-r--r--main/command.go38
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