From 1acd29f3b6d2ebbbade5e96f6a463704f4a0c366 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 4 Nov 2021 08:20:46 -0500 Subject: [PATCH] GOOD: add flags, start using vim-go Signed-off-by: Jeff Carr --- flags.go | 14 ++++++++++++++ flags_web.go | 8 ++++++++ main.go | 26 ++++++++++++++++++++++---- window-packages.go | 43 +++++++++++++++++++++++-------------------- 4 files changed, 67 insertions(+), 24 deletions(-) create mode 100644 flags.go create mode 100644 flags_web.go diff --git a/flags.go b/flags.go new file mode 100644 index 0000000..465b478 --- /dev/null +++ b/flags.go @@ -0,0 +1,14 @@ +//go:build !js || !wasm +// +build !js !wasm + +package main + +import ( + "flag" +) + +func parseFlags(g *game) { + flag.IntVar(&g.w, "width", 100, "Enable width mode") + flag.IntVar(&g.h, "noclip", 50, "Enable noclip mode") + flag.Parse() +} diff --git a/flags_web.go b/flags_web.go new file mode 100644 index 0000000..eca2841 --- /dev/null +++ b/flags_web.go @@ -0,0 +1,8 @@ +//go:build js && wasm +// +build js,wasm + +package main + +func parseFlags(g *game) { + g.disableEsc = true +} diff --git a/main.go b/main.go index d1f6862..a41d40e 100644 --- a/main.go +++ b/main.go @@ -1,17 +1,17 @@ package main -import origlog "log" - import ( - "git.wit.org/jcarr/log" + origlog "log" "os" "time" + "git.wit.org/jcarr/log" "git.wit.org/wit/gui" -// "github.com/davecgh/go-spew/spew" "github.com/gobuffalo/packr" ) +// "github.com/davecgh/go-spew/spew" + var GITCOMMIT string // this is passed in as an ldflag var GOVERSION string // this is passed in as an ldflag var VERSION string // this is passed in as an ldflag @@ -39,6 +39,12 @@ func customExit(n *gui.Node) { os.Exit(0) } +type game struct { + w, h int + + levelNum int +} + func main() { log.Println("starting my Control Panel") log.Println("GOVERSION =", GOVERSION) @@ -46,6 +52,13 @@ func main() { log.Println("packr ./resources box") + g := &game{ + w: 5, + h: 20, + } + + parseFlags(g) + // This puts all the files in that directory in the binary // This directory includes the default config file if there is not already one packrBox = packr.NewBox("./resources") @@ -65,6 +78,11 @@ func main() { // only os.Exit() on close of the main Window // TODO: Change to only exit from systray(?) func initGUI() { + g := &gui.GuiConfig{ + Exit: customExit, + Stretchy: false, + } + log.Println("g =", g) gui.Config.Exit = customExit gui.Config.Stretchy = false mainWindow(nil) diff --git a/window-packages.go b/window-packages.go index aacd9f0..6bf3079 100644 --- a/window-packages.go +++ b/window-packages.go @@ -1,18 +1,21 @@ package main -import "log" -import "os" -import "bufio" -import "strings" -import "errors" -import "git.wit.org/wit/gui" +import ( + "bufio" + "errors" + "log" + "os" + "strings" + + "git.wit.org/wit/gui" +) func aptPackagesWindow(w *gui.Node) { var aptoutput *gui.Node var aptNode *gui.Node var filename string - if (w == nil) { + if w == nil { gui.Config.Title = "apt configuration and package installer" gui.Config.Width = 1600 gui.Config.Height = 800 @@ -23,15 +26,15 @@ func aptPackagesWindow(w *gui.Node) { tab := w.AddTab("apt", nil) // populateNEW(tab, "new") -////////////// filename ///////////////////////// + ////////////// filename ///////////////////////// gNode := tab.AddGroup("Options") - gNode.AddButton("default packages", func (*gui.Node) { + gNode.AddButton("default packages", func(*gui.Node) { log.Println("STARTED HOSTNAME") aptNode.SetText("bin/install-default-packages.sh") filename = "bin/install-default-packages.sh" b, _ := packrBox.FindString(filename) - if (aptoutput != nil) { + if aptoutput != nil { aptoutput.SetText(b) } log.Println("ENDED GetText() HOSTNAME =", filename) @@ -39,12 +42,12 @@ func aptPackagesWindow(w *gui.Node) { gNode.CreateFontButton("fonts") - gNode.AddButton("Configure apt-file", func (*gui.Node) { + gNode.AddButton("Configure apt-file", func(*gui.Node) { log.Println("STARTED HOSTNAME") aptNode.SetText("bin/apt-file.sh") filename = "bin/apt-file.sh" b, _ := packrBox.FindString(filename) - if (aptoutput != nil) { + if aptoutput != nil { aptoutput.SetText(b) } log.Println("ENDED GetText() HOSTNAME =", filename) @@ -62,22 +65,22 @@ func aptPackagesWindow(w *gui.Node) { aptNode = gNode.AddComboBox("test", tmp...) aptNode.SetText(filename) - aptNode.OnChanged = func () { + aptNode.OnChanged = func() { log.Println("STARTED HOSTNAME") filename = aptNode.GetText() b, _ := packrBox.FindString(filename) - if (aptoutput != nil) { + if aptoutput != nil { aptoutput.SetText(b) } log.Println("ENDED GetText() HOSTNAME =", filename) } -////////////// connect ///////////////////////// + ////////////// connect ///////////////////////// gNode = tab.AddGroup("") - gNode.AddButton("Run Script", func (*gui.Node) { - sudo( func() error { - log.Println("set resolv.conf to",filename) + gNode.AddButton("Run Script", func(*gui.Node) { + sudo(func() error { + log.Println("set resolv.conf to", filename) b, _ := packrBox.FindString(filename) // spew.Dump(b) b = aptoutput.GetText() @@ -98,8 +101,8 @@ func aptPackagesWindow(w *gui.Node) { }) gui.Config.Stretchy = true - gNode.AddButton("set output", func (*gui.Node) { - if (aptoutput != nil) { + gNode.AddButton("set output", func(*gui.Node) { + if aptoutput != nil { aptoutput.SetText("wow") aptoutput.SetMargined(false) }