go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit ca4e9e963a6280fc31ec16135231ab8be21efefa
parent 5f04698d0a851950b404cc6821b6575a58ca5ff8
Author: lash <dev@holbrook.no>
Date:   Mon, 10 Apr 2023 17:38:23 +0100

WIP add menu render to sizer context

Diffstat:
Mgo/render/menu.go | 5+++++
Mgo/render/page.go | 31++++++++++++++++++++++++-------
Mgo/render/size_test.go | 31++++++++++++++++++++++++-------
Mgo/testdata/testdata.go | 4++--
Mgo/vm/runner.go | 5++++-
5 files changed, 59 insertions(+), 17 deletions(-)

diff --git a/go/render/menu.go b/go/render/menu.go @@ -52,6 +52,11 @@ func(m *Menu) WithOutputSize(outputSize uint16) *Menu { return m } +// GetOutputSize returns the defined heuristic menu size. +func(m *Menu) GetOutputSize() uint32 { + return uint32(m.outputSize) +} + // WithBrowseConfig defines the criteria for page browsing. func(m *Menu) WithBrowseConfig(cfg BrowseConfig) *Menu { m.browse = cfg diff --git a/go/render/page.go b/go/render/page.go @@ -95,7 +95,7 @@ func(pg *Page) Map(key string) error { return err } } - log.Printf("page map is now: %v", pg.cacheMap) + log.Printf("mapped %s", key) return nil } @@ -192,6 +192,15 @@ func(pg *Page) prepare(sym string, values map[string]string, idx uint16) (map[st return nil, err } + if pg.menu != nil { + r, err := pg.menu.Render(idx) + if err != nil { + return nil, err + } + log.Printf("appending %s for menu", r) + s += r + } + remaining, ok := pg.sizer.Check(s) if !ok { return nil, fmt.Errorf("capacity exceeded") @@ -255,12 +264,6 @@ func(pg *Page) render(sym string, values map[string]string, idx uint16) (string, } log.Printf("rendered %v bytes for template", len(s)) r += s - if pg.sizer != nil { - _, ok = pg.sizer.Check(r) - if !ok { - return "", fmt.Errorf("limit exceeded: %v", pg.sizer) - } - } s, err = pg.menu.Render(idx) if err != nil { return "", err @@ -275,6 +278,20 @@ func(pg *Page) render(sym string, values map[string]string, idx uint16) (string, return "", fmt.Errorf("limit exceeded: %v", pg.sizer) } } +// s, err = pg.menu.Render(idx) +// if err != nil { +// return "", err +// } +// log.Printf("rendered %v bytes for menu", len(s)) +// if len(s) > 0 { +// r += "\n" + s +// } +// if pg.sizer != nil { +// _, ok = pg.sizer.Check(r) +// if !ok { +// return "", fmt.Errorf("limit exceeded: %v", pg.sizer) +// } +// } return r, nil } diff --git a/go/render/size_test.go b/go/render/size_test.go @@ -88,17 +88,34 @@ func TestSizeLimit(t *testing.T) { pg := NewPage(ca, rs).WithMenu(mn).WithSizer(szr) ca.Push() st.Down("test") - ca.Add("foo", "inky", 4) - ca.Add("bar", "pinky", 10) - ca.Add("baz", "blinky", 0) - pg.Map("foo") - pg.Map("bar") - pg.Map("baz") + err := ca.Add("foo", "inky", 4) + if err != nil { + t.Fatal(err) + } + err = ca.Add("bar", "pinky", 10) + if err != nil { + t.Fatal(err) + } + err = ca.Add("baz", "blinky", 0) + if err != nil { + t.Fatal(err) + } + err = pg.Map("foo") + if err != nil { + t.Fatal(err) + } + err = pg.Map("bar") + if err != nil { + t.Fatal(err) + } + err = pg.Map("baz") + if err != nil { + t.Fatal(err) + } mn.Put("1", "foo the foo") mn.Put("2", "go to bar") - var err error _, err = pg.Render("small", 0) if err != nil { t.Fatal(err) diff --git a/go/testdata/testdata.go b/go/testdata/testdata.go @@ -110,11 +110,11 @@ func baz() error { func long() error { b := []byte{} - b = vm.NewLine(b, vm.LOAD, []string{"longdata"}, []byte{0x00}, nil) - b = vm.NewLine(b, vm.MAP, []string{"longdata"}, nil, nil) b = vm.NewLine(b, vm.MOUT, []string{"0", "back"}, nil, nil) b = vm.NewLine(b, vm.MNEXT, []string{"00", "nexxt"}, nil, nil) b = vm.NewLine(b, vm.MPREV, []string{"11", "prevv"}, nil, nil) + b = vm.NewLine(b, vm.LOAD, []string{"longdata"}, []byte{0x00}, nil) + b = vm.NewLine(b, vm.MAP, []string{"longdata"}, nil, nil) b = vm.NewLine(b, vm.HALT, nil, nil, nil) b = vm.NewLine(b, vm.INCMP, []string{"0", "_"}, nil, nil) diff --git a/go/vm/runner.go b/go/vm/runner.go @@ -178,6 +178,7 @@ func(vm *Vm) RunCatch(b []byte, ctx context.Context) ([]byte, error) { if r { log.Printf("catch at flag %v, moving to %v", sig, sym) //bitField, d) vm.st.Down(sym) + vm.Reset() b = []byte{} } return b, nil @@ -195,6 +196,7 @@ func(vm *Vm) RunCroak(b []byte, ctx context.Context) ([]byte, error) { } if r { log.Printf("croak at flag %v, purging and moving to top", sig) + vm.Reset() vm.st.Reset() vm.pg.Reset() vm.ca.Reset() @@ -258,6 +260,7 @@ func(vm *Vm) RunMove(b []byte, ctx context.Context) ([]byte, error) { } log.Printf("loaded additional code: %x", code) b = append(b, code...) + vm.Reset() return b, nil } @@ -313,6 +316,7 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) { if err != nil { return b, err } + vm.Reset() code, err := vm.rs.GetCode(target) if err != nil { @@ -392,7 +396,6 @@ func(vm *Vm) Render() (string, error) { if err != nil { return "", err } - vm.Reset() return r, nil }