From 8ab09243500576460a9e5b12cae0b997933d6577 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 9 Sep 2025 06:16:41 -0500 Subject: [PATCH] more fun with new GUI code --- argv.go | 38 ++++++++++++++++++++++++++++++++------ doGui.go | 5 ----- event.proto | 8 ++++---- exit.go | 5 +++-- main.go | 30 +++++++++++++++++------------- structs.go | 5 ++++- 6 files changed, 60 insertions(+), 31 deletions(-) diff --git a/argv.go b/argv.go index f434ca3..deffbb2 100644 --- a/argv.go +++ b/argv.go @@ -9,18 +9,25 @@ package main */ import ( + "fmt" + "os" + "go.wit.com/log" ) var argv args type args struct { - Verbose bool `arg:"--verbose" help:"talk more"` - Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"` - UseME bool `arg:"--me" help:"use /me to connect"` - Port int `arg:"--port" default:"2522" help:"port to run on"` - URL string `arg:"--url" help:"url to use"` - Config string `arg:"--config" help:"config file (default is ~/.config/cloud/gus.text"` + Gui *EmptyCmd `arg:"subcommand:gui" help:"open the gui"` + Verbose bool `arg:"--verbose" help:"talk more"` + Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"` + UseME bool `arg:"--me" help:"use /me to connect"` + Port int `arg:"--port" default:"2522" help:"port to run on"` + URL string `arg:"--url" help:"url to use"` + Config string `arg:"--config" help:"config file (default is ~/.config/cloud/gus.text"` +} + +type EmptyCmd struct { } func (args) Version() string { @@ -48,3 +55,22 @@ func init() { INFO = log.NewFlag("INFO", false, full, short, "general gus") WARN = log.NewFlag("WARN", true, full, short, "bad things") } + +/* + handles shell autocomplete +*/ + +func (a args) DoAutoComplete(argv []string) { + switch argv[0] { + case "playback": + fmt.Println("long --uuid purge last submit") + case "clean": + fmt.Println("") + default: + if argv[0] == ARGNAME { + // list the subcommands here + fmt.Println("--json interact playback clean") + } + } + os.Exit(0) +} diff --git a/doGui.go b/doGui.go index 77f308a..07e863b 100644 --- a/doGui.go +++ b/doGui.go @@ -9,7 +9,6 @@ import ( "os" "time" - "go.wit.com/gui" "go.wit.com/lib/gadgets" "go.wit.com/log" ) @@ -28,10 +27,6 @@ func refresh() { } func doGui() { - me.myGui = gui.New() - me.myGui.InitEmbed(resources) - me.myGui.Default() - win := gadgets.RawBasicWindow("gus: (squirl your way around networks)") win.Make() win.Show() diff --git a/event.proto b/event.proto index 169a069..6b17526 100644 --- a/event.proto +++ b/event.proto @@ -5,10 +5,10 @@ package gus; import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp enum GusEventType { - Connect = 0; // a socket connect attempt - Disconnect = 1; // a socket closed - Enable = 2; // listening on a port was enabled - Disable = 3; // listening on a port was disabled + Connect = 0; // a socket connect attempt + Disconnect = 1; // a socket closed + Enable = 2; // listening on a port was enabled + Disable = 3; // listening on a port was disabled } message GusSocket { diff --git a/exit.go b/exit.go index 320778f..a3a431e 100644 --- a/exit.go +++ b/exit.go @@ -6,6 +6,7 @@ package main import ( "os" + "go.wit.com/gui" "go.wit.com/log" ) @@ -13,12 +14,12 @@ func okExit(note string) { if note != "" { log.Info("gus exit:", note, "ok") } - me.myGui.Close() + gui.StandardExit() os.Exit(0) } func badExit(err error) { log.Info("gus failed: ", err) - me.myGui.Close() + gui.StandardExit() os.Exit(-1) } diff --git a/main.go b/main.go index 1819e1b..4c507bf 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,7 @@ import ( "github.com/google/uuid" "go.wit.com/dev/alexflint/arg" - "go.wit.com/gui" + "go.wit.com/lib/gui/prep" "go.wit.com/log" timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) @@ -26,16 +26,19 @@ import ( var VERSION string var BUILDTIME string +var ARGNAME string = "gus" + //go:embed resources/* var resources embed.FS func main() { - var pp *arg.Parser - gui.InitArg() - pp = arg.MustParse(&argv) + me = new(gusconf) + prep.Bash(ARGNAME, argv.DoAutoComplete) // this line should be: prep.Bash(argv) + me.myGui = prep.Gui() // prepares the GUI package for go-args + me.pp = arg.MustParse(&argv) - if pp == nil { - pp.WriteHelp(os.Stdout) + if me.pp == nil { + me.pp.WriteHelp(os.Stdout) os.Exit(0) } log.Info("tmp hack", uuid.New().String()) @@ -66,16 +69,17 @@ func main() { os.Exit(0) } - if gui.NoGui() { - startGus() - startHTTP() - os.Exit(0) + startGus() + + if argv.Gui != nil { + me.myGui.Start() // loads the GUI toolkit + doGui() // start making our forge GUI } - startGus() + startHTTP() + os.Exit(0) + // debug() // sits here forever // go NewWatchdog() - go startHTTP() - doGui() } func startGus() { diff --git a/structs.go b/structs.go index 372fa87..63d1c53 100644 --- a/structs.go +++ b/structs.go @@ -7,15 +7,18 @@ import ( sync "sync" "time" + "go.wit.com/dev/alexflint/arg" "go.wit.com/gui" "go.wit.com/lib/gadgets" + "go.wit.com/lib/gui/prep" ) var me *gusconf // this app's variables type gusconf struct { - myGui *gui.Node // the base of the gui + pp *arg.Parser // for parsing the command line args. Yay to alexf lint! + myGui *prep.GuiPrep // the base of the gui portmaps *Portmaps // the portmap window portwin *stdTableWin // the portwin window events *Events // the event log