go-vise

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

commit 18a95521a7cfe8ff26641132d893ae47fe821890
parent e568a958ec4698066e520f7283560704a3147dec
Author: lash <dev@holbrook.no>
Date:   Thu, 12 Dec 2024 13:06:12 +0000

Add menu separator access in engine config

Diffstat:
Mengine/config.go | 2++
Mengine/db.go | 3+++
Mvm/runner.go | 13++++++++++++-
3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/engine/config.go b/engine/config.go @@ -22,6 +22,8 @@ type Config struct { StateDebug bool // EngineDebug activates the engine debug output EngineDebug bool + // MenuSeparator sets the string to use for separating menu selectors and menu descriptors in the renderer + MenuSeparator string } // String implements the string interface. diff --git a/engine/db.go b/engine/db.go @@ -269,6 +269,9 @@ func(en *DefaultEngine) setupVm() { szr = render.NewSizer(en.cfg.OutputSize) } en.vm = vm.NewVm(en.st, en.rs, en.ca, szr) + if en.cfg.MenuSeparator != "" { + en.vm = en.vm.WithMenuSeparator(en.cfg.MenuSeparator) + } } func(en *DefaultEngine) empty(ctx context.Context) error { diff --git a/vm/runner.go b/vm/runner.go @@ -45,7 +45,8 @@ type Vm struct { ca cache.Memory // Loaded content. mn *render.Menu // Menu component of page. sizer *render.Sizer // Apply size constraints to output. - pg *render.Page // Render outputs with menues to size constraints. + pg *render.Page // Render outputs with menues to size constraints + menuSeparator string // Passed to Menu.WithSeparator if not empty } // NewVm creates a new Vm. @@ -62,9 +63,19 @@ func NewVm(st *state.State, rs resource.Resource, ca cache.Memory, sizer *render return vmi } +// WithMenuSeparator is a chainable function that sets the separator string to use +// in the menu renderer. +func(vmi *Vm) WithMenuSeparator(sep string) *Vm { + vmi.menuSeparator = sep + return vmi +} + // Reset re-initializes sub-components for output rendering. func(vmi *Vm) Reset() { vmi.mn = render.NewMenu() + if vmi.menuSeparator != "" { + vmi.mn = vmi.mn.WithSeparator(vmi.menuSeparator) + } vmi.pg.Reset() vmi.pg = vmi.pg.WithMenu(vmi.mn) if vmi.sizer != nil {