GOOD: add flags, start using vim-go

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-11-04 08:20:46 -05:00
parent 0f8ed0da1f
commit 1acd29f3b6
4 changed files with 67 additions and 24 deletions

14
flags.go Normal file
View File

@ -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()
}

8
flags_web.go Normal file
View File

@ -0,0 +1,8 @@
//go:build js && wasm
// +build js,wasm
package main
func parseFlags(g *game) {
g.disableEsc = true
}

26
main.go
View File

@ -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)

View File

@ -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)
}