2024-01-09 01:16:00 -06:00
|
|
|
// This is a simple example
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-09 02:00:51 -06:00
|
|
|
"strings"
|
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
|
2024-01-09 01:16:00 -06:00
|
|
|
"go.wit.com/gui/gui"
|
|
|
|
"go.wit.com/gui/gadgets"
|
|
|
|
"go.wit.com/apps/control-panel-dns/smartwindow"
|
|
|
|
)
|
|
|
|
|
|
|
|
var myGui *gui.Node
|
|
|
|
|
2024-01-09 02:22:01 -06:00
|
|
|
var allrepos []*repo
|
|
|
|
|
|
|
|
type repo struct {
|
|
|
|
path string
|
|
|
|
|
|
|
|
pLabel *gui.Node // path label
|
|
|
|
bLabel *gui.Node // branch label
|
|
|
|
vLabel *gui.Node // version label
|
|
|
|
sLabel *gui.Node // git state (dirty or not?)
|
|
|
|
|
|
|
|
cButton *gui.Node // commit button
|
|
|
|
pButton *gui.Node // push button
|
|
|
|
}
|
|
|
|
|
2024-01-09 01:16:00 -06:00
|
|
|
func main() {
|
|
|
|
myGui = gui.New().Default()
|
|
|
|
|
|
|
|
helloworld()
|
|
|
|
|
|
|
|
// This is just a optional goroutine to watch that things are alive
|
|
|
|
gui.Watchdog()
|
|
|
|
}
|
|
|
|
|
2024-01-09 02:22:01 -06:00
|
|
|
func (r *repo) scan() {
|
|
|
|
log.Info("r.path", r.path)
|
|
|
|
b, out := run(r.path, "git", "describe --tags")
|
2024-01-09 02:00:51 -06:00
|
|
|
if b {
|
2024-01-09 02:22:01 -06:00
|
|
|
r.vLabel.SetText(out)
|
2024-01-09 02:00:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// cmd := "dig +noall +answer www.wit.com A"
|
|
|
|
// out = shell.Run(cmd)
|
2024-01-09 02:22:01 -06:00
|
|
|
}
|
2024-01-09 02:00:51 -06:00
|
|
|
|
2024-01-09 02:22:01 -06:00
|
|
|
func checkrepos() {
|
|
|
|
for i, r := range allrepos {
|
|
|
|
r.scan()
|
|
|
|
log.Info("scanned them all", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func addRepo(grid *gui.Node, path string) *repo {
|
|
|
|
newRepo := new(repo)
|
|
|
|
|
|
|
|
newRepo.path = path
|
|
|
|
newRepo.pLabel = grid.NewLabel(path)
|
|
|
|
newRepo.vLabel = grid.NewLabel("VER")
|
|
|
|
newRepo.bLabel = grid.NewLabel("jcarr")
|
|
|
|
newRepo.sLabel = grid.NewLabel("dirty")
|
|
|
|
|
|
|
|
newRepo.cButton = grid.NewButton("commit", func () {
|
|
|
|
log.Println("commit")
|
2024-01-09 02:00:51 -06:00
|
|
|
})
|
2024-01-09 02:22:01 -06:00
|
|
|
newRepo.cButton = grid.NewButton("push", func () {
|
|
|
|
log.Println("push")
|
2024-01-09 02:00:51 -06:00
|
|
|
})
|
2024-01-09 02:22:01 -06:00
|
|
|
allrepos = append(allrepos, newRepo)
|
|
|
|
return newRepo
|
2024-01-09 02:00:51 -06:00
|
|
|
}
|
|
|
|
|
2024-01-09 01:16:00 -06:00
|
|
|
// This creates a window
|
|
|
|
func helloworld() {
|
|
|
|
win := gadgets.NewBasicWindow(myGui, "helloworld golang wit/gui window")
|
|
|
|
|
2024-01-09 02:00:51 -06:00
|
|
|
box := win.Box().NewBox("bw vbox", false)
|
|
|
|
group := box.NewGroup("test")
|
|
|
|
grid := group.NewGrid("test", 6, 1)
|
|
|
|
|
|
|
|
grid.NewLabel("Repo")
|
|
|
|
grid.NewLabel("Version")
|
|
|
|
grid.NewLabel("Current branch")
|
|
|
|
grid.NewLabel("is dirty?")
|
|
|
|
grid.NewLabel("commit")
|
|
|
|
grid.NewLabel("push to")
|
|
|
|
|
2024-01-09 02:22:01 -06:00
|
|
|
newr := addRepo(grid, "go.wit.com/log")
|
|
|
|
newr.scan()
|
2024-01-09 02:00:51 -06:00
|
|
|
addRepo(grid, "go.wit.com/arg")
|
|
|
|
addRepo(grid, "go.wit.com/spew")
|
|
|
|
addRepo(grid, "go.wit.com/shell")
|
|
|
|
addRepo(grid, "")
|
|
|
|
addRepo(grid, "go.wit.com/gui/gadgets")
|
|
|
|
addRepo(grid, "go.wit.com/gui/gadgets")
|
|
|
|
|
2024-01-09 02:22:01 -06:00
|
|
|
box.NewButton("checkrepos()", func () {
|
|
|
|
checkrepos()
|
|
|
|
})
|
2024-01-09 02:00:51 -06:00
|
|
|
box.NewButton("hello", func () {
|
2024-01-09 01:16:00 -06:00
|
|
|
log.Println("world")
|
|
|
|
hellosmart()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// This creates a window
|
|
|
|
func hellosmart() {
|
|
|
|
win := smartwindow.New()
|
|
|
|
win.SetParent(myGui)
|
|
|
|
win.InitWindow()
|
|
|
|
win.Title("helloworld golang wit/gui window")
|
|
|
|
win.Vertical()
|
|
|
|
win.SetDraw(smartDraw)
|
|
|
|
win.Make()
|
|
|
|
|
2024-01-09 02:00:51 -06:00
|
|
|
win.Box().NewButton("test smartwindow", func () {
|
2024-01-09 01:16:00 -06:00
|
|
|
log.Println("smart")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func smartDraw(sw *smartwindow.SmartWindow) {
|
|
|
|
sw.Box().NewButton("hello", func () {
|
|
|
|
log.Println("smart")
|
|
|
|
})
|
|
|
|
}
|
2024-01-09 02:00:51 -06:00
|
|
|
|
|
|
|
func run(path string, thing string, cmdline string) (bool, string) {
|
|
|
|
parts := strings.Split(cmdline, " ")
|
|
|
|
// Create the command
|
|
|
|
cmd := exec.Command(thing, parts...)
|
|
|
|
|
|
|
|
// Set the working directory
|
|
|
|
cmd.Dir = "/home/jcarr/go/src/" + path
|
|
|
|
|
|
|
|
// Execute the command
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err, "cmd error'd out", parts)
|
|
|
|
return false, ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print the output
|
|
|
|
log.Info(string(output))
|
|
|
|
return true, string(output)
|
|
|
|
}
|