summaryrefslogtreecommitdiff
path: root/main.go
blob: 84407af0563c7d3a93e42ac5838286387afce0d0 (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
// This is a simple example
package main

import (
	"embed"
	"os/user"
	"strings"

	"go.wit.com/log"

	"go.wit.com/gui"
	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/gui/repostatus"
)

//go:embed resources/*
var resToolkit embed.FS

func main() {
	me = new(autoType)
	me.allrepos = make(map[*repo]string)

	me.myGui = gui.New()
	me.myGui.InitEmbed(resToolkit)
	// me.myGui.LoadToolkit("nocui")
	me.myGui.Default()

	autotypistWindow()
	repoworld()

	// keeps the app alive
	// TODO: rescan the status of the repos every so often?
	gui.Watchdog()
}

func addRepo(grid *gui.Node, path string, master string, devel string, user string) {
	newRepo := new(repo)

	path = strings.Trim(path, "/") // trim any extranous '/' chars put in the config file by the user
	if path == "" {
		log.Warn("addRepo() got empty path", path, master, devel, user)
		return
	}

	if repostatus.VerifyLocalGoRepo(path) {
		log.Verbose("newRepo actually exists", newRepo.getPath())
	} else {
		log.Warn("repostatus.VerifyLocalGoRepo() failed for for", path, master, devel, user)
		return
	}

	newRepo.path = path
	newRepo.pLabel = grid.NewLabel(path).SetProgName("path")

	newRepo.lastTag = grid.NewLabel("").SetProgName("lastTag")

	newRepo.masterVersion = grid.NewLabel("").SetProgName("masterVersion")
	newRepo.develVersion = grid.NewLabel("").SetProgName("develVersion")
	newRepo.userVersion = grid.NewLabel("").SetProgName("userVersion")

	newRepo.dirtyLabel = grid.NewLabel("")
	newRepo.goSumStatus = grid.NewLabel("?")

	newRepo.vLabel = grid.NewLabel("").SetProgName("current")

	newRepo.statusButton = grid.NewButton("Configure", func() {
		if newRepo.status == nil {
			log.Warn("status window doesn't exist")
			return
		}
		log.Warn("status window exists. trying TestDraw() here")
		newRepo.status.Toggle()
		/// newRepo.status.Update()
	})

	// newRepo.status = repostatus.New(me.myGui, newRepo.path)
	newRepo.status = repostatus.NewRepoStatusWindow(newRepo.path)
	newRepo.hidden = false
	newRepo.status.SetMainWorkingName(me.mainBranch.String())
	newRepo.status.SetDevelWorkingName(me.develBranch.String())
	newRepo.status.SetUserWorkingName(me.userBranch.String())
	/*
		newRepo.status.SetDevelBranchName(devel)
		newRepo.status.SetUserBranchName(user)
		newRepo.status.Update()
		newRepo.newScan()
	*/
	me.allrepos[newRepo] = path
}

func autotypistWindow() {
	win := me.myGui.NewWindow("autotypist for GO & git. it types faster than you can.")
	box := win.NewBox("bw hbox", true)

	globalDisplayOptions(box)
	globalBuildOptions(box)
	globalTestingOptions(box)
	globalResetOptions(box)

}

// This creates a window
func repoworld() {
	reposwin = gadgets.NewBasicWindow(me.myGui, "All git repositories in ~/go/src/")
	reposwin.Make()

	reposbox = reposwin.Box().NewBox("bw vbox", false)
	reposwin.Draw()
	reposwin.Custom = func() {
		log.Warn("GOT HERE: main() gadgets.NewBasicWindow() close")
		log.Warn("Should I do something special here?")
	}

	reposgroup = reposbox.NewGroup("go repositories (read from ~/.config/myrepolist)")
	reposgrid = reposgroup.NewGrid("test", 9, 1)

	reposgrid.NewLabel("") // path goes here

	reposgrid.NewLabel("last tag").SetProgName("last tag")

	reposgrid.NewLabel("master version")
	reposgrid.NewLabel("devel version")
	reposgrid.NewLabel("user version")

	reposgrid.NewLabel("Status")
	reposgrid.NewLabel("go.sum")

	reposgrid.NewLabel("Current Version").SetProgName("Current Version")

	reposgrid.NewLabel("Show()")

	repos := myrepolist()
	for _, line := range repos {
		log.Verbose("repo =", line)
		path, mbranch, dbranch, ubranch := splitLine(line)
		if mbranch == "" {
			mbranch = "master"
		}
		if dbranch == "" {
			dbranch = "devel"
		}
		usr, _ := user.Current()
		if ubranch == "" {
			ubranch = usr.Username
		}
		addRepo(reposgrid, path, mbranch, dbranch, ubranch)
	}
}