WIP add profile menu example
This commit is contained in:
5
examples/compile.bash
Normal file
5
examples/compile.bash
Normal file
@@ -0,0 +1,5 @@
|
||||
for f in $(ls $1); do
|
||||
b=$(basename $f)
|
||||
b=${b%.*}
|
||||
go run ./dev/asm $1/$b.vis > $1/$b.bin
|
||||
done
|
||||
2
examples/profile/entry_name
Normal file
2
examples/profile/entry_name
Normal file
@@ -0,0 +1,2 @@
|
||||
Name is currently: {{.myname}}
|
||||
Enter new name.
|
||||
6
examples/profile/entry_name.vis
Normal file
6
examples/profile/entry_name.vis
Normal file
@@ -0,0 +1,6 @@
|
||||
LOAD myname 32
|
||||
MAP myname
|
||||
MOUT 0 "abort"
|
||||
HALT
|
||||
INCMP 0 _
|
||||
INCMP * entry_name_save
|
||||
0
examples/profile/entry_name_save
Normal file
0
examples/profile/entry_name_save
Normal file
3
examples/profile/entry_name_save.vis
Normal file
3
examples/profile/entry_name_save.vis
Normal file
@@ -0,0 +1,3 @@
|
||||
LOAD entry_name_save 0
|
||||
RELOAD myname
|
||||
MOVE _
|
||||
58
examples/profile/main.go
Normal file
58
examples/profile/main.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
testdataloader "github.com/peteole/testdata-loader"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/engine"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.defalsify.org/vise/state"
|
||||
)
|
||||
|
||||
var (
|
||||
baseDir = testdataloader.GetBasePath()
|
||||
scriptDir = path.Join(baseDir, "examples", "profile")
|
||||
)
|
||||
|
||||
func nameSave(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
||||
fp := path.Join(scriptDir, "myname.txt")
|
||||
err := ioutil.WriteFile(fp, input, 0600)
|
||||
return resource.Result{}, err
|
||||
}
|
||||
|
||||
func main() {
|
||||
var dir string
|
||||
var root string
|
||||
var size uint
|
||||
var sessionId string
|
||||
flag.UintVar(&size, "s", 0, "max size of output")
|
||||
flag.StringVar(&root, "root", "root", "entry point symbol")
|
||||
flag.StringVar(&sessionId, "session-id", "default", "session id")
|
||||
flag.Parse()
|
||||
fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir)
|
||||
|
||||
st := state.NewState(0)
|
||||
rs := resource.NewFsResource(scriptDir)
|
||||
rs.AddLocalFunc("entry_name_save", nameSave)
|
||||
ca := cache.NewCache()
|
||||
cfg := engine.Config{
|
||||
Root: "root",
|
||||
SessionId: sessionId,
|
||||
OutputSize: uint32(size),
|
||||
}
|
||||
ctx := context.Background()
|
||||
en := engine.NewEngine(cfg, &st, &rs, ca, ctx)
|
||||
|
||||
err := engine.Loop(&en, os.Stdin, os.Stdout, ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "loop exited with error: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
1
examples/profile/myname.txt
Normal file
1
examples/profile/myname.txt
Normal file
@@ -0,0 +1 @@
|
||||
inky
|
||||
1
examples/profile/root
Normal file
1
examples/profile/root
Normal file
@@ -0,0 +1 @@
|
||||
Please input profile data
|
||||
3
examples/profile/root.vis
Normal file
3
examples/profile/root.vis
Normal file
@@ -0,0 +1,3 @@
|
||||
DOWN entry_name 0 "name"
|
||||
DOWN entry_email 1 "email"
|
||||
DOWN entry_sex 2 "sex"
|
||||
Reference in New Issue
Block a user