Compare commits

...

3 Commits

Author SHA1 Message Date
Jeff Carr 68f23a5866 gui API updates
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-02-15 03:28:16 -06:00
Jeff Carr 4c40ea1a7b more on new gui
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-24 22:07:03 -06:00
Jeff Carr c4d78beac6 new gui versions
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-24 22:02:08 -06:00
11 changed files with 86 additions and 143 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
*.swp *.swp
go.*
wit-new-machine wit-new-machine
/files/* /files/*
/*.deb /*.deb

View File

@ -6,9 +6,18 @@ VERSION = $(shell cat resources/VERSION)
# export GO111MODULE="off" # export GO111MODULE="off"
build: build:
-cp ~/go/src/go.wit.com/gui/toolkits/*.so plugins/ -mkdir plugins
-cp ~/go/src/go.wit.com/toolkits/*.so plugins/
go build -v go build -v
./wit-new-machine --debugging ./wit-new-machine
goimports:
goimports -w *.go
redomod:
rm -f go.*
GO111MODULE= go mod init
GO111MODULE= go mod tidy
nocui: nocui:
./wit-new-machine --gui-toolkit nocui ./wit-new-machine --gui-toolkit nocui

11
apt.go
View File

@ -1,14 +1,17 @@
package main package main
import ( import (
"log" "log"
"os" "os"
"go.wit.com/gui"
) )
func aptTab() { func aptTab() {
aptTab := mainWindow.NewTab("apt") aptTab := gui.RawWindow("apt")
box := aptTab.NewBox("aptBox", false) box := aptTab.NewBox("aptBox", false)
box.NewButton("apt sources", func () { box.NewButton("apt sources", func() {
if _, err := os.Stat("/etc/apt/sources.list.d/wit.list"); err == nil { if _, err := os.Stat("/etc/apt/sources.list.d/wit.list"); err == nil {
log.Println("apt sources are already configured") log.Println("apt sources are already configured")
} else { } else {
@ -25,7 +28,7 @@ func aptTab() {
} }
}) })
box.NewButton("apt-file", func () { box.NewButton("apt-file", func() {
myGui.CloseToolkit("gocui") myGui.CloseToolkit("gocui")
doCmd("apt install apt-file") doCmd("apt install apt-file")
doCmd("apt-file update") doCmd("apt-file update")
@ -34,7 +37,7 @@ func aptTab() {
os.Exit(0) os.Exit(0)
}) })
box.NewButton("install defaults", func () { box.NewButton("install defaults", func() {
myGui.CloseToolkit("gocui") myGui.CloseToolkit("gocui")
doCmd("apt install lsof bash-completion libpam-systemd dbus rbd-nbd golang-go git screen vim " + doCmd("apt install lsof bash-completion libpam-systemd dbus rbd-nbd golang-go git screen vim " +
"ethstatus iftop ethtool sysstat traceroute whois devscripts automake libtool devscripts " + "ethstatus iftop ethtool sysstat traceroute whois devscripts automake libtool devscripts " +

28
args.go
View File

@ -1,28 +0,0 @@
package main
/*
this enables command line options from other packages like 'gui' and 'log'
*/
import (
"go.wit.com/log"
"go.wit.com/arg"
"go.wit.com/gui/debugger"
)
var argGui ArgsGui
// This struct can be used with the go-arg package
type ArgsGui struct {
Test bool `arg:"--test" help:"enable all logging"`
}
func init() {
arg.MustParse(&argGui)
if debugger.ArgDebug() {
log.Log(true, "INIT() gui debug == true")
} else {
log.Log(true, "INIT() gui debug == false")
}
}

26
debugger.go Normal file
View File

@ -0,0 +1,26 @@
package main
/*
enables GUI options and the debugger in your application
*/
import (
"go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/debugger"
"go.wit.com/log"
)
var args struct {
}
func init() {
arg.MustParse(&args)
if debugger.ArgDebug() {
log.Info("cmd line --debugger == true")
go func() {
log.Sleep(2)
debugger.DebugWindow()
}()
}
}

21
go.mod
View File

@ -1,21 +0,0 @@
module git.wit.org/jcarr/wit-new-machine
go 1.21.4
require (
github.com/alexflint/go-arg v1.4.3
go.wit.com/gui/gui v0.9.8
go.wit.com/log v0.0.0-20240102010317-907893ba7b4b
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a
)
require (
github.com/alexflint/go-scalar v1.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9 // indirect
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/image v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
)

39
go.sum
View File

@ -1,39 +0,0 @@
github.com/alexflint/go-arg v1.4.3 h1:9rwwEBpMXfKQKceuZfYcwuc/7YY7tWJbFsgG5cAU/uo=
github.com/alexflint/go-arg v1.4.3/go.mod h1:3PZ/wp/8HuqRZMUUgu7I+e1qcpUbvmS258mRXkFH4IA=
github.com/alexflint/go-scalar v1.1.0 h1:aaAouLLzI9TChcPXotr6gUhq+Scr8rl0P9P4PnltbhM=
github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
go.wit.com/gui/gui v0.9.8 h1:oMqM4sfucMnZxh9e2F0DKxNTuVxl2JZGXcuTRnGW+xI=
go.wit.com/gui/gui v0.9.8/go.mod h1:H2+uDT6qoQ8UkV6QUNIC1MQsgy6/aAop0zWBHnwACso=
go.wit.com/log v0.0.0-20240102010317-907893ba7b4b h1:YqDB6AChqjmt5jYN4F79UrjIDoUt58pfCgXJwp+G2wg=
go.wit.com/log v0.0.0-20240102010317-907893ba7b4b/go.mod h1:GmsggfsKrqdZdAj26fEOlcTz6qEIazbV33uyuuktvB8=
go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9 h1:UEX2EzLQPzLTfy/kUFQD7OXtvKn8wk/+jpDOkbl4ff4=
go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9/go.mod h1:qBpgJXThMMT15vym7/E4Ur9y8oOo2nP7t2RP52QHUNw=
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 h1:3AGKexOYqL+ztdWdkB1bDwXgPBuTS/S8A4WzuTvJ8Cg=
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0=
golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4=
golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a h1:sYbmY3FwUWCBTodZL1S3JUuOvaW6kM2o+clDzzDNBWg=
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a/go.mod h1:Ede7gF0KGoHlj822RtphAHK1jLdrcuRBZg0sF1Q+SPc=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

31
gui.go
View File

@ -1,11 +1,12 @@
package main package main
import ( import (
"time"
"os"
"io/ioutil" "io/ioutil"
"os"
"time"
"go.wit.com/gui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/gui"
"go.wit.com/gui/debugger"
) )
var myGui *gui.Node var myGui *gui.Node
@ -29,17 +30,17 @@ var resolv *gui.Node
func writeRes(indir string, outdir string, name string) { func writeRes(indir string, outdir string, name string) {
tmp, _ := res.ReadFile(indir + name) tmp, _ := res.ReadFile(indir + name)
ioutil.WriteFile(outdir + name, tmp, 0644) ioutil.WriteFile(outdir+name, tmp, 0644)
} }
// myGui = gui.New().LoadToolkit("gocui") // myGui = gui.New().LoadToolkit("gocui")
func drawWindow() { func drawWindow() {
var g *gui.Node var g *gui.Node
mainWindow = myGui.NewWindow("wit new machine setup").SetText("wit new machine setup") mainWindow = myGui.NewWindow("wit new machine setup").SetText("wit new machine setup")
mainWindow.Custom = customExit mainWindow.Custom = customExit
newTab := mainWindow.NewTab("mainTab") newTab := gui.NewWindow("mainTab")
//////////////////// General GUI debugging ///////////////////////// //////////////////// General GUI debugging /////////////////////////
g = newTab.NewGroup("Debug") g = newTab.NewGroup("Debug")
@ -57,14 +58,14 @@ func drawWindow() {
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
rn := newTab.NewGroup("Local Linux Settings") rn := newTab.NewGroup("Local Linux Settings")
rn.NewButton("purge rc-only", func () { rn.NewButton("purge rc-only", func() {
xterm("cd ~/jcarr/setup; make reset-purge-rc-only-packages") xterm("cd ~/jcarr/setup; make reset-purge-rc-only-packages")
}) })
rn.NewButton("install kvm", func () { rn.NewButton("install kvm", func() {
xterm("cd ~/jcarr/setup; make setup-packages-kvm") xterm("cd ~/jcarr/setup; make setup-packages-kvm")
}) })
rn.NewButton("ttyS0", func () { rn.NewButton("ttyS0", func() {
myGui.CloseToolkit("gocui") myGui.CloseToolkit("gocui")
// systemctl enable serial-getty@ttyS0.service // systemctl enable serial-getty@ttyS0.service
// cp ttyS0.conf /etc/init/ // cp ttyS0.conf /etc/init/
@ -89,20 +90,16 @@ func drawWindow() {
} }
os.Exit(0) os.Exit(0)
}) })
rn.NewButton("git config", func () { rn.NewButton("git config", func() {
myGui.CloseToolkit("gocui") myGui.CloseToolkit("gocui")
doCmd("git config pull.rebase false") doCmd("git config pull.rebase false")
os.Exit(0) os.Exit(0)
}) })
rn.NewButton("DebugWindow()", func () {
debugger.DebugWindow(myGui)
})
rn.NewLabel("Not yet working stuff") rn.NewLabel("Not yet working stuff")
rn.NewButton("resolv.conf", func () { rn.NewButton("resolv.conf", func() {
s := resolv.GetText() s := resolv.String()
log.Println("supposed to make the resolv.conf window\n\n", s) log.Println("supposed to make the resolv.conf window\n\n", s)
}) })

17
main.go
View File

@ -1,16 +1,15 @@
package main package main
import ( import (
"bytes"
"embed"
"os" "os"
"os/exec" "os/exec"
"embed"
"strings" "strings"
"bytes"
"go.wit.com/arg" "go.wit.com/dev/alexflint/arg"
"go.wit.com/gui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/gui"
"go.wit.com/gui/debugger"
) )
var GITCOMMIT string // this is passed in as an ldflag var GITCOMMIT string // this is passed in as an ldflag
@ -22,7 +21,6 @@ var username string
var hostname string var hostname string
var geom string = "120x30+500+500" var geom string = "120x30+500+500"
//go:embed resources //go:embed resources
var res embed.FS var res embed.FS
@ -55,15 +53,10 @@ func main() {
myGui = gui.New().Default() myGui = gui.New().Default()
drawWindow() drawWindow()
if debugger.ArgDebug() {
log.Sleep(2)
debugger.DebugWindow(myGui)
}
gui.Watchdog() gui.Watchdog()
} }
func closeWindow(n *gui.Node) { func closeWindow(n *gui.Node) {
log.Println("Just closing the window and nothing else.", n.Name) log.Println("Just closing the window and nothing else.", n.String())
// os.Exit(0) // os.Exit(0)
} }

20
os.go
View File

@ -1,16 +1,18 @@
package main package main
import "log" import (
import "strings" "errors"
import "os" "io/ioutil"
import "os/exec" "log"
import "io/ioutil" "os"
import "errors" "os/exec"
"strings"
)
func runSimpleCommand(s string) { func runSimpleCommand(s string) {
cmd := strings.TrimSpace(s) // this is like 'chomp' in perl cmd := strings.TrimSpace(s) // this is like 'chomp' in perl
cmd = strings.TrimSuffix(cmd, "\n") // this is like 'chomp' in perl cmd = strings.TrimSuffix(cmd, "\n") // this is like 'chomp' in perl
cmdArgs := strings.Fields(cmd) cmdArgs := strings.Fields(cmd)
runLinuxCommand(cmdArgs) runLinuxCommand(cmdArgs)
} }

View File

@ -1,7 +1,7 @@
package main package main
import ( import (
"go.wit.com/gui/gui" "go.wit.com/gui"
) )
// setup a new machine // setup a new machine
@ -12,46 +12,46 @@ var commandEntry *gui.Node
func setupNewMachine(cur *gui.Node) { func setupNewMachine(cur *gui.Node) {
var w, g *gui.Node var w, g *gui.Node
w = cur.NewTab("Setup Machine") w = myGui.NewWindow("Setup Machine")
g = w.NewGroup("ssh things") g = w.NewGroup("ssh things")
g.NewButton("ssh localhost", func () { g.NewButton("ssh localhost", func() {
// ssh -t == force pseudo tty allocation // ssh -t == force pseudo tty allocation
command = "ssh -t " + username + "@" + hostname + " 'ssh -v localhost'" command = "ssh -t " + username + "@" + hostname + " 'ssh -v localhost'"
commandEntry.SetText(command) commandEntry.SetText(command)
}) })
g.NewButton("copy authorized_keys", func () { g.NewButton("copy authorized_keys", func() {
command = "scp ~/jcarr/.ssh/authorized_keys " + username + "@[" + hostname + "]:.ssh" + "/" command = "scp ~/jcarr/.ssh/authorized_keys " + username + "@[" + hostname + "]:.ssh" + "/"
commandEntry.SetText(command) commandEntry.SetText(command)
}) })
g.NewButton("sudo ssh localhost", func () { g.NewButton("sudo ssh localhost", func() {
// ssh -t == force pseudo tty allocation // ssh -t == force pseudo tty allocation
command = "ssh -t " + username + "@" + hostname + " 'sudo ssh -v localhost'" command = "ssh -t " + username + "@" + hostname + " 'sudo ssh -v localhost'"
commandEntry.SetText(command) commandEntry.SetText(command)
}) })
g.NewButton("sudo cp authorized_keys", func () { g.NewButton("sudo cp authorized_keys", func() {
command = "ssh -t " + username + "@" + hostname + " 'sudo cp /home/jcarr/.ssh/authorized_keys /root/.ssh/ ' " command = "ssh -t " + username + "@" + hostname + " 'sudo cp /home/jcarr/.ssh/authorized_keys /root/.ssh/ ' "
commandEntry.SetText(command) commandEntry.SetText(command)
}) })
g.NewLabel("install go 1.19") g.NewLabel("install go 1.19")
g.NewButton("wget 1.19", func () { g.NewButton("wget 1.19", func() {
command = "ssh -t " + "jcarr" + "@" + hostname + " 'wget https://go.dev/dl/go1.19.linux-amd64.tar.gz' " command = "ssh -t " + "jcarr" + "@" + hostname + " 'wget https://go.dev/dl/go1.19.linux-amd64.tar.gz' "
xtermHold.Set(true) xtermHold.SetChecked(true)
xterm(command) xterm(command)
}) })
g.NewLabel("install sid") g.NewLabel("install sid")
g.NewButton("replace /etc/apt/sources", func () { g.NewButton("replace /etc/apt/sources", func() {
commandEntry.SetText(command) commandEntry.SetText(command)
}) })
g.NewButton("apt update", func () { g.NewButton("apt update", func() {
// command = "ssh -t " + 'root' + "@" + hostname + " 'cp /home/jcarr/.ssh/authorized_keys /root/.ssh/ ' " // command = "ssh -t " + 'root' + "@" + hostname + " 'cp /home/jcarr/.ssh/authorized_keys /root/.ssh/ ' "
commandEntry.SetText(command) commandEntry.SetText(command)
}) })
g.NewLabel("build myself") g.NewLabel("build myself")
g.NewButton("setup go", func () { g.NewButton("setup go", func() {
// ssh -t == force pseudo tty allocation // ssh -t == force pseudo tty allocation
command = "ssh -t " + "jcarr" + "@" + hostname + " 'go get -u -v go.wit.com/jcarr/control-panel-dns ; bash'" command = "ssh -t " + "jcarr" + "@" + hostname + " 'go get -u -v go.wit.com/jcarr/control-panel-dns ; bash'"
commandEntry.SetText(command) commandEntry.SetText(command)