2023-04-02 11:11:09 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"git.defalsify.org/festive/engine"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var dir string
|
|
|
|
var root string
|
|
|
|
flag.StringVar(&dir, "d", ".", "resource dir to read from")
|
|
|
|
flag.StringVar(&root, "root", "root", "entry point symbol")
|
|
|
|
flag.Parse()
|
|
|
|
fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
en := engine.NewDefaultEngine(dir)
|
2023-04-02 11:20:25 +02:00
|
|
|
err := en.Init(root, ctx)
|
2023-04-02 11:11:09 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "cannot init: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2023-04-06 10:14:53 +02:00
|
|
|
b := bytes.NewBuffer(nil)
|
|
|
|
en.WriteResult(b)
|
|
|
|
fmt.Println(b.String())
|
|
|
|
|
2023-04-02 11:11:09 +02:00
|
|
|
running := true
|
|
|
|
for running {
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
in, err := reader.ReadString('\n')
|
|
|
|
if err != nil {
|
2023-04-02 11:20:25 +02:00
|
|
|
fmt.Fprintf(os.Stderr, "cannot read input: %v\n", err)
|
2023-04-02 11:11:09 +02:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
in = strings.TrimSpace(in)
|
2023-04-06 11:08:40 +02:00
|
|
|
running, err = en.Exec([]byte(in), ctx)
|
2023-04-02 11:11:09 +02:00
|
|
|
if err != nil {
|
2023-04-06 11:55:11 +02:00
|
|
|
fmt.Fprintf(os.Stderr, "unexpected termination: %v\n", err)
|
2023-04-02 11:11:09 +02:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
b := bytes.NewBuffer(nil)
|
|
|
|
en.WriteResult(b)
|
|
|
|
fmt.Println(b.String())
|
|
|
|
}
|
|
|
|
}
|