From 7313c83e69d7307a8b673ce9b6623d88a5697984 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 29 Dec 2023 09:24:06 -0600 Subject: [PATCH] save 'universal' go-arg Signed-off-by: Jeff Carr --- args.go | 22 +++++++++++++++++ gadgets/basicEntry.go | 56 +++++++++++++++++++++++++++++++++++++++++++ main.go | 6 ++--- structs.go | 9 ------- 4 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 args.go create mode 100644 gadgets/basicEntry.go diff --git a/args.go b/args.go new file mode 100644 index 0000000..886880e --- /dev/null +++ b/args.go @@ -0,0 +1,22 @@ +package gui + +import ( + arg "github.com/alexflint/go-arg" +) + +var guiArg GuiArgs + +// This struct can be used with the go-arg package +type GuiArgs struct { + Gui string `arg:"--gui" help:"Use this gui toolkit [andlabs,gocui,nocui]"` + GuiDebug bool `arg:"--gui-debug" help:"open the GUI debugger"` + GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"` +} + +func init() { + arg.Register(&guiArg) +} + +func GetArg(a string) bool { + return guiArg.GuiDebug +} diff --git a/gadgets/basicEntry.go b/gadgets/basicEntry.go new file mode 100644 index 0000000..105347b --- /dev/null +++ b/gadgets/basicEntry.go @@ -0,0 +1,56 @@ +/* + A Labeled Single Line Entry widget: + + ----------------------------- + | | | + | Food: | | + | | | + ----------------------------- +*/ +package gadgets + +import ( + "go.wit.com/log" + "go.wit.com/gui" +) + +type BasicEntry struct { + parent *gui.Node // parent widget + l *gui.Node // label widget + v *gui.Node // value widget + + value string + label string + + Custom func() +} + +func (n *BasicEntry) Get() string { + return n.value +} + +func (n *BasicEntry) Set(value string) *BasicEntry { + log.Println("BasicEntry.Set() =", value) + if (n.v != nil) { + n.v.Set(value) + } + n.value = value + return n +} + +func NewBasicEntry(p *gui.Node, name string) *BasicEntry { + d := BasicEntry { + parent: p, + value: "", + } + + // various timeout settings + d.l = p.NewLabel(name) + d.v = p.NewEntryLine("") + d.v.Custom = func() { + d.value = d.v.S + log.Println("BasicEntry.Custom() user changed value to =", d.value) + } + + return &d +} diff --git a/main.go b/main.go index 84a7d52..09b2bc1 100644 --- a/main.go +++ b/main.go @@ -123,9 +123,9 @@ func New() *Node { // try to load andlabs, if that doesn't work, fall back to the console func (n *Node) Default() *Node { - if (GuiArg.Gui != "") { - log(logError, "New.Default() try toolkit =", GuiArg.Gui) - return n.LoadToolkit(GuiArg.Gui) + if (guiArg.Gui != "") { + log(logError, "New.Default() try toolkit =", guiArg.Gui) + return n.LoadToolkit(guiArg.Gui) } // if DISPLAY isn't set, return since gtk can't load // TODO: figure out how to check what to do in macos and mswindows diff --git a/structs.go b/structs.go index b9d4d89..406b11a 100644 --- a/structs.go +++ b/structs.go @@ -23,15 +23,6 @@ import ( var me guiConfig -var GuiArg GuiArgs - -// This struct can be used with the go-arg package -type GuiArgs struct { - Gui string `arg:"--gui" help:"Use this gui toolkit [andlabs,gocui,nocui]"` - GuiDebug bool `arg:"--gui-debug" help:"open the GUI debugger"` - GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"` -} - type guiConfig struct { initOnce sync.Once