summaryrefslogtreecommitdiff
path: root/main.go
blob: 1e406087bbc7de7f0ff3e2107b31c8d365b5c3e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// This is a simple example
package main

import 	(
	"strings"
	"os/exec"

	"go.wit.com/log"

	"go.wit.com/gui/gui"
	"go.wit.com/gui/gadgets"
	"go.wit.com/apps/control-panel-dns/smartwindow"
)

var myGui *gui.Node

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
}

func main() {
	myGui = gui.New().Default()

	helloworld()

	// This is just a optional goroutine to watch that things are alive
	gui.Watchdog()
}

func (r *repo) scan() {
	log.Info("r.path", r.path)
	b, out := run(r.path, "git", "describe --tags")
	if b {
		r.vLabel.SetText(out)
	}

	// cmd := "dig +noall +answer www.wit.com A"
	// out = shell.Run(cmd)
}

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")
	})
	newRepo.cButton = grid.NewButton("push", func () {
		log.Println("push")
	})
	allrepos = append(allrepos, newRepo)
	return newRepo
}

// This creates a window
func helloworld() {
	win := gadgets.NewBasicWindow(myGui, "helloworld golang wit/gui window")

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

	newr := addRepo(grid, "go.wit.com/log")
	newr.scan()
	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")

	box.NewButton("checkrepos()", func () {
		checkrepos()
	})
	box.NewButton("hello", func () {
		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()

	win.Box().NewButton("test smartwindow", func () {
		log.Println("smart")
	})
}

func smartDraw(sw *smartwindow.SmartWindow) {
	sw.Box().NewButton("hello", func () {
		log.Println("smart")
	})
}

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