summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--argv.go1
-rw-r--r--doGui.go75
-rw-r--r--main.go71
-rw-r--r--structs.go3
4 files changed, 81 insertions, 69 deletions
diff --git a/argv.go b/argv.go
index 29a4240..500229e 100644
--- a/argv.go
+++ b/argv.go
@@ -17,6 +17,7 @@ var argv args
type args struct {
Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"`
List *EmptyCmd `arg:"subcommand:list" help:"list the repos"`
+ Gui *EmptyCmd `arg:"subcommand:gui" help:"show gui"`
Merge *EmptyCmd `arg:"subcommand:merge" help:"merge in new patchsets"`
Init *EmptyCmd `arg:"subcommand:init" help:"init the repo list"`
Port int `arg:"--port" default:"2520" help:"port to run on"`
diff --git a/doGui.go b/doGui.go
new file mode 100644
index 0000000..24ec444
--- /dev/null
+++ b/doGui.go
@@ -0,0 +1,75 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+// An app to submit patches for the 30 GO GUI repos
+
+import (
+ "time"
+
+ "go.wit.com/gui"
+ "go.wit.com/lib/fhelp"
+ "go.wit.com/lib/gadgets"
+ "go.wit.com/lib/gui/shell"
+ "go.wit.com/log"
+)
+
+func debug() {
+ defer func() {
+ if r := recover(); r != nil {
+ gui.Crash(r, "forge debug()")
+ }
+ }()
+ time.Sleep(2 * time.Second)
+ for {
+ now := time.Now()
+
+ doList()
+
+ log.Printf("finished a scan here in (%s)\n", shell.FormatDuration(time.Since(now)))
+ time.Sleep(90 * time.Second)
+ }
+}
+
+func doGui() {
+ if me.forge.Config.GetDefaultGui() == "" {
+ me.forge.Config.DefaultGui = "gocui"
+ me.forge.ConfigSave()
+ }
+ me.myGui = gui.New()
+ me.myGui.InitEmbed(resources)
+ me.myGui.SetAppDefaultPlugin(me.forge.Config.DefaultGui) // sets the default GUI plugin to use
+ if pname, err := me.myGui.Default(); err != nil {
+ if !fhelp.BuildPlugin("gocui") {
+ log.Info("You can't run the forge GUI since the plugins did not build", pname)
+ okExit("")
+ } else {
+ if err := me.myGui.LoadToolkitNew("gocui"); err != nil {
+ log.Info("The plugins built, but still failed to load", pname)
+ badExit(err)
+ }
+ log.Info("The plugins built and loaded!", pname)
+ }
+ }
+
+ mainWindow := gadgets.NewGenericWindow("forged: forge.wit.com", "Current Settings")
+ mainWindow.Custom = func() {
+ log.Warn("MAIN WINDOW CLOSE")
+ now := time.Now()
+ log.Printf("rill repos.Reload() took (%s)\n", shell.FormatDuration(time.Since(now)))
+ okExit("")
+ }
+ drawWindow(mainWindow)
+
+ // sits here forever
+ debug()
+}
+
+func drawWindow(win *gadgets.GenericWindow) {
+ grid := win.Group.RawGrid()
+
+ grid.NewButton("stats", func() {
+ doList()
+ })
+}
diff --git a/main.go b/main.go
index 995d55d..bdd834d 100644
--- a/main.go
+++ b/main.go
@@ -77,6 +77,9 @@ func main() {
}
if argv.Daemon == true {
+ if argv.Gui != nil {
+ go doGui()
+ }
mux := http.NewServeMux()
okHandlerFunc := http.HandlerFunc(okHandler)
@@ -104,74 +107,6 @@ func main() {
okExit("")
}
- /*
- // --- Best Practice: Create a custom http.Server ---
- server := &http.Server{
- Addr: p,
- Handler: mux,
-
- // ReadTimeout is the total time to read the entire request, including the body.
- // Increase this to a value that can accommodate your largest expected uploads.
- // For example, 5 minutes.
- ReadTimeout: 5 * time.Minute,
-
- // WriteTimeout is the maximum duration before timing out writes of the response.
- WriteTimeout: 10 * time.Second,
-
- // IdleTimeout is the maximum amount of time to wait for the
- // next request when keep-alives are enabled.
- IdleTimeout: 120 * time.Second,
- }
- */
-
- /*
- log.Println(argv.Version(), "HOSTNAME set to:", HOSTNAME)
- log.Println("Running on port", "http://localhost"+p)
- log.Println("Running on port", "http://localhost"+p+"/ipv6.png")
- // if err := http.ListenAndServe(p, nil); err != nil {
- if err := server.ListenAndServe(); err != nil {
- log.Fatalf("Could not start server: %s\n", err)
- }
- /*
- log.Info("Running in --daemon mode")
- http.HandleFunc("/", okHandler)
- // go https() // use caddy instead
- p := fmt.Sprintf(":%d", argv.Port)
- log.Println(argv.Version(), "HOSTNAME set to:", HOSTNAME)
- log.Println("Running on port", "http://localhost"+p)
- log.Println("Running on port", "http://localhost"+p+"/ipv6.png")
- err := http.ListenAndServe(p, nil)
- if err != nil {
- log.Println("Error starting server:", err)
- }
- return
- }
- */
log.Info("--daemon was not set. Just list the patches.")
// doList()
}
-
-func formatDuration(d time.Duration) string {
- seconds := int(d.Seconds()) % 60
- minutes := int(d.Minutes()) % 60
- hours := int(d.Hours()) % 24
- days := int(d.Hours()) / 24
-
- result := ""
- if days > 0 {
- result += fmt.Sprintf("%dd ", days)
- return result
- }
- if hours > 0 {
- result += fmt.Sprintf("%dh ", hours)
- return result
- }
- if minutes > 0 {
- result += fmt.Sprintf("%dm ", minutes)
- return result
- }
- if seconds > 0 {
- result += fmt.Sprintf("%ds", seconds)
- }
- return result
-}
diff --git a/structs.go b/structs.go
index 41fec14..a1f812c 100644
--- a/structs.go
+++ b/structs.go
@@ -5,6 +5,7 @@ package main
import (
"go.wit.com/dev/alexflint/arg"
+ "go.wit.com/gui"
"go.wit.com/lib/protobuf/forgepb"
)
@@ -14,5 +15,5 @@ var me *mainType
type mainType struct {
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
forge *forgepb.Forge // for holding the forge protobuf files
- // myGui *gui.Node // the gui toolkit handle
+ myGui *gui.Node // the gui toolkit handle
}