aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/shell/shell.go
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2025-06-26 00:54:29 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2025-06-26 01:01:43 -0400
commit0232433a2ddd64c270a4d049f5ae9895245ee058 (patch)
treeff2c813f166bc4ea69e556f8e6895d6a6bf7226d /pkg/shell/shell.go
parent173788333e6b14a1b2bdbb127874988bb62bce8d (diff)
Add improved line editing to debug shell
Improved line editing include moveable cursor and command history
Diffstat (limited to 'pkg/shell/shell.go')
-rw-r--r--pkg/shell/shell.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/pkg/shell/shell.go b/pkg/shell/shell.go
new file mode 100644
index 0000000..19a4223
--- /dev/null
+++ b/pkg/shell/shell.go
@@ -0,0 +1,50 @@
+package shell
+
+import (
+ "fmt"
+ "os"
+
+ "golang.org/x/term"
+)
+
+var commands = []string{
+ "help",
+ "clear",
+ "let",
+ "del",
+ "slice",
+ "rematch",
+ "repattern",
+ "tokenize",
+ "opt_simplify", "opt_tighten", "opt_flatten", "opt_sort", "opt_tidy", "opt_contradictions", "opt_compact", "opt_strictEq",
+ "parse",
+ "compile",
+}
+
+func (inter *Interpreter) Run() error {
+ oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
+ if err != nil {
+ panic(err)
+ }
+ defer term.Restore(int(os.Stdin.Fd()), oldState)
+ inter.term = term.NewTerminal(os.Stdin, "atlasi> ")
+ inter.term.SetPrompt(
+ string(inter.term.Escape.Yellow) + "atlasi> " +
+ string(inter.term.Escape.Reset),
+ )
+
+ for {
+ line, err := inter.term.ReadLine()
+ if err != nil {
+ return err
+ }
+ tokens := inter.Tokenize(line)
+ fatal, err := inter.Eval(inter.term, tokens)
+ if fatal {
+ return err
+ } else if err != nil {
+ fmt.Fprintln(inter.term, string(inter.term.Escape.Red), "Error:",
+ string(inter.term.Escape.Reset), err)
+ }
+ }
+}