summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-13 09:52:59 -0500
committerJeff Carr <[email protected]>2025-10-13 09:52:59 -0500
commitc1c74f51f8ec5a3346508394a12279e2f6cd73bd (patch)
tree82eedd77cef68fa6a4d891774156dd3409d3ac6e
parentb60a841021e44552b6413b4fcc4a79c4b8e39357 (diff)
seems to do something. notsure.
-rw-r--r--gui.go110
1 files changed, 110 insertions, 0 deletions
diff --git a/gui.go b/gui.go
new file mode 100644
index 0000000..131bc74
--- /dev/null
+++ b/gui.go
@@ -0,0 +1,110 @@
+package fhelp
+
+// initializes logging and command line options
+
+import (
+ "os"
+
+ "go.wit.com/dev/alexflint/arg"
+ "go.wit.com/gui"
+ "go.wit.com/log"
+)
+
+var argGui ArgsGui
+
+/*
+This struct can be used with the go-arg package. These
+are the generic default command line arguments for the 'GUI' package
+*/
+type ArgsGui struct {
+ GuiFhelp *GuiEmptyCmd `arg:"subcommand:guifhelp" help:"open the gui"`
+ GuiPlugin string `arg:"--gui" help:"select the plugin (andlabs,gocui,etc)"`
+ GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"`
+}
+
+type GuiEmptyCmd struct {
+}
+
+/*
+used for command line options.
+This allows you to control the toolkit settings from the command line
+
+ --debugger # opens the debugger
+ --gui andlabs # loads the GTK toolkit on linux or Cocoa on mac
+ --gui gocui # runs your program in the terminal in ncurses-like mode
+*/
+/*
+func ArgToolkit() string {
+ return argGui.GuiPlugin
+}
+
+ func init() {
+ arg.Register(&argGui)
+ }
+
+ // this should never happen because this is before go-args MustParse()
+ if argGui.GuiPluginHack != "" {
+ // does os.Exec() and does not return
+ gui.TestPluginAndExit()
+ }
+*/
+
+// after go-args MustParse & user configuration
+// the gui package can pull out the final settings and init() the GO Plugin GUI Toolkit
+func postMustParse(s string) string {
+ switch s {
+ case "PluginHack":
+ case "VERBOSE":
+ if argGui.GuiVerbose == true {
+ return "true"
+ }
+ return "false"
+ case "DEFAULT":
+ if argGui.GuiPlugin != "" {
+ return argGui.GuiPlugin
+ }
+ return "gocui"
+ case "FILE":
+ return "someplugin"
+ default:
+ return ""
+ }
+ return "unknown"
+}
+
+var prepGui *GuiPrep
+
+type GuiPrep struct {
+ rootn *gui.Node
+ hidden bool // don't update the toolkits when it's hidden
+ Auto func([]string)
+}
+
+func Gui() *GuiPrep {
+ if len(os.Args) > 1 && os.Args[1] == "--gui-check-plugin" {
+ gui.TestPluginAndExitNew(os.Args[2])
+ os.Exit(0)
+ }
+ arg.Register(&argGui)
+
+ prepGui = new(GuiPrep)
+ prepGui.rootn = gui.PreInit(postMustParse)
+ return prepGui
+}
+
+func (g *GuiPrep) Start() error {
+ // me.myGui.InitEmbed(resources)
+ if pname, err := g.rootn.Default(); err != nil {
+ if !BuildPlugin("gocui") {
+ log.Info("You can't run the forge GUI since the plugins did not build", pname)
+ return nil
+ }
+ if err := g.rootn.LoadToolkitNew("gocui"); err != nil {
+ log.Info("The plugins built, but still failed to load", pname)
+ return err
+ }
+ } else {
+ log.Info("The plugins built and loaded!", pname)
+ }
+ return nil
+}