2024-01-09 01:16:00 -06:00
|
|
|
// This is a simple example
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-09 10:21:58 -06:00
|
|
|
"io/ioutil"
|
|
|
|
"strings"
|
|
|
|
|
2024-01-09 02:00:51 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
|
2024-01-09 01:16:00 -06:00
|
|
|
"go.wit.com/gui/gui"
|
|
|
|
"go.wit.com/gui/gadgets"
|
2024-01-12 23:21:05 -06:00
|
|
|
"go.wit.com/gui/gadgets/repostatus"
|
2024-01-09 01:16:00 -06:00
|
|
|
"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
|
2024-01-09 08:35:07 -06:00
|
|
|
lasttagrev string
|
|
|
|
lasttag string
|
|
|
|
tags []string
|
2024-01-09 02:22:01 -06:00
|
|
|
|
|
|
|
pLabel *gui.Node // path label
|
|
|
|
bLabel *gui.Node // branch label
|
2024-01-09 08:35:07 -06:00
|
|
|
lastLabel *gui.Node // last tagged version label
|
2024-01-09 02:22:01 -06:00
|
|
|
vLabel *gui.Node // version label
|
2024-01-13 21:39:44 -06:00
|
|
|
// tagsDrop *gui.Node // list of all tags
|
2024-01-09 09:56:33 -06:00
|
|
|
dirtyLabel *gui.Node // git state (dirty or not?)
|
|
|
|
|
|
|
|
masterVersion *gui.Node // the master branch version
|
|
|
|
develVersion *gui.Node // the devel branch version
|
|
|
|
jcarrVersion *gui.Node // the jcarr branch version
|
2024-01-09 02:22:01 -06:00
|
|
|
|
|
|
|
cButton *gui.Node // commit button
|
|
|
|
pButton *gui.Node // push button
|
2024-01-09 11:55:18 -06:00
|
|
|
|
|
|
|
status *repostatus.RepoStatus
|
2024-01-09 02:22:01 -06:00
|
|
|
}
|
|
|
|
|
2024-01-09 01:16:00 -06:00
|
|
|
func main() {
|
|
|
|
myGui = gui.New().Default()
|
|
|
|
|
2024-01-10 19:44:38 -06:00
|
|
|
repoworld()
|
2024-01-13 21:39:44 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
for i, r := range allrepos {
|
|
|
|
log.Warn("scannning", i, r.path)
|
|
|
|
r.scan()
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2024-01-09 01:16:00 -06:00
|
|
|
gui.Watchdog()
|
|
|
|
}
|
|
|
|
|
2024-01-13 21:39:44 -06:00
|
|
|
func (r *repo) getPath() string {
|
|
|
|
return r.path
|
|
|
|
}
|
|
|
|
|
|
|
|
func addRepo(grid *gui.Node, path string) {
|
2024-01-09 02:22:01 -06:00
|
|
|
newRepo := new(repo)
|
|
|
|
|
2024-01-13 21:39:44 -06:00
|
|
|
if repostatus.VerifyLocalGoRepo(path) {
|
|
|
|
log.Warn("newRepo actually exists", newRepo.getPath())
|
|
|
|
} else {
|
|
|
|
log.Warn("newRepo does not exist", newRepo.getPath())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-09 02:22:01 -06:00
|
|
|
newRepo.path = path
|
|
|
|
newRepo.pLabel = grid.NewLabel(path)
|
2024-01-09 08:35:07 -06:00
|
|
|
newRepo.bLabel = grid.NewLabel("")
|
|
|
|
newRepo.lastLabel = grid.NewLabel("")
|
|
|
|
newRepo.vLabel = grid.NewLabel("")
|
2024-01-13 21:39:44 -06:00
|
|
|
// newRepo.tagsDrop = grid.NewDropdown("tags")
|
2024-01-09 09:56:33 -06:00
|
|
|
|
|
|
|
newRepo.masterVersion = grid.NewLabel("")
|
|
|
|
newRepo.develVersion = grid.NewLabel("")
|
|
|
|
newRepo.jcarrVersion = grid.NewLabel("")
|
|
|
|
newRepo.dirtyLabel = grid.NewLabel("")
|
2024-01-09 02:22:01 -06:00
|
|
|
|
2024-01-13 21:39:44 -06:00
|
|
|
/*
|
2024-01-09 11:55:18 -06:00
|
|
|
newRepo.cButton = grid.NewButton("status", func () {
|
|
|
|
log.Println("repo status for", newRepo.path)
|
2024-01-10 19:44:38 -06:00
|
|
|
newRepo.scan()
|
2024-01-09 11:55:18 -06:00
|
|
|
if newRepo.status == nil {
|
|
|
|
newRepo.status = repostatus.New(myGui, newRepo.path)
|
2024-01-11 15:57:08 -06:00
|
|
|
newRepo.status.Vertical()
|
|
|
|
newRepo.status.Horizontal()
|
2024-01-09 11:55:18 -06:00
|
|
|
newRepo.status.Make()
|
|
|
|
newRepo.status.Draw()
|
|
|
|
newRepo.status.Draw2()
|
|
|
|
}
|
|
|
|
newRepo.status.Toggle()
|
2024-01-09 02:00:51 -06:00
|
|
|
})
|
2024-01-13 21:39:44 -06:00
|
|
|
*/
|
2024-01-11 15:57:08 -06:00
|
|
|
newRepo.pButton = grid.NewButton("rescan", func () {
|
2024-01-13 21:39:44 -06:00
|
|
|
newRepo.newScan()
|
|
|
|
})
|
|
|
|
|
|
|
|
/*
|
|
|
|
grid.NewButton("Sierpiński", func () {
|
|
|
|
if newRepo.status != nil {
|
|
|
|
log.Warn("status window already exists")
|
|
|
|
}
|
|
|
|
newRepo.status = repostatus.New(myGui, newRepo.path)
|
|
|
|
newRepo.status.Horizontal()
|
|
|
|
newRepo.status.Make()
|
|
|
|
newRepo.status.Make2()
|
|
|
|
})
|
|
|
|
*/
|
|
|
|
grid.NewButton("Toggle()", func () {
|
|
|
|
if newRepo.status == nil {
|
|
|
|
log.Warn("status window doesn't exist")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Warn("status window exists. trying Update() here")
|
|
|
|
newRepo.status.Toggle()
|
|
|
|
})
|
|
|
|
grid.NewButton("TestDraw()", func () {
|
|
|
|
if newRepo.status == nil {
|
|
|
|
log.Warn("status window doesn't exist")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Warn("status window exists. trying TestDraw() here")
|
|
|
|
newRepo.status.TestDraw()
|
2024-01-09 02:00:51 -06:00
|
|
|
})
|
2024-01-10 19:44:38 -06:00
|
|
|
if path == "" {
|
|
|
|
newRepo.cButton.Hide()
|
|
|
|
newRepo.pButton.Hide()
|
|
|
|
}
|
2024-01-13 21:39:44 -06:00
|
|
|
newRepo.status = repostatus.New(myGui, newRepo.path)
|
|
|
|
newRepo.status.Horizontal()
|
|
|
|
newRepo.status.Make()
|
|
|
|
newRepo.status.Make2()
|
|
|
|
newRepo.status.Update()
|
|
|
|
newRepo.newScan()
|
2024-01-09 02:22:01 -06:00
|
|
|
allrepos = append(allrepos, newRepo)
|
2024-01-09 02:00:51 -06:00
|
|
|
}
|
|
|
|
|
2024-01-09 01:16:00 -06:00
|
|
|
// This creates a window
|
2024-01-10 19:44:38 -06:00
|
|
|
func repoworld() {
|
|
|
|
win := gadgets.NewBasicWindow(myGui, "git autotypist. it types faster than you can.")
|
2024-01-09 01:16:00 -06:00
|
|
|
|
2024-01-09 02:00:51 -06:00
|
|
|
box := win.Box().NewBox("bw vbox", false)
|
2024-01-11 15:57:08 -06:00
|
|
|
// box2 := win.Box().NewBox("bw vbox", false)
|
2024-01-10 19:44:38 -06:00
|
|
|
group := box.NewGroup("go repositories (read from ~/.config/myrepolist)")
|
2024-01-09 09:56:33 -06:00
|
|
|
grid := group.NewGrid("test", 11, 1)
|
2024-01-09 02:00:51 -06:00
|
|
|
|
2024-01-10 19:44:38 -06:00
|
|
|
grid.NewLabel("")
|
2024-01-09 08:35:07 -06:00
|
|
|
grid.NewLabel("branch")
|
|
|
|
grid.NewLabel("last tag")
|
2024-01-13 21:39:44 -06:00
|
|
|
grid.NewLabel("Current Version")
|
|
|
|
// grid.NewLabel("tags")
|
2024-01-09 09:56:33 -06:00
|
|
|
grid.NewLabel("master")
|
|
|
|
grid.NewLabel("devel")
|
|
|
|
grid.NewLabel("jcarr")
|
2024-01-10 19:44:38 -06:00
|
|
|
grid.NewLabel("Status")
|
2024-01-09 02:00:51 -06:00
|
|
|
grid.NewLabel("commit")
|
2024-01-13 21:39:44 -06:00
|
|
|
grid.NewLabel("Toggle()")
|
|
|
|
grid.NewLabel("Draw()")
|
2024-01-09 02:00:51 -06:00
|
|
|
|
2024-01-09 10:41:35 -06:00
|
|
|
repos := myrepolist()
|
|
|
|
for _, repo := range repos {
|
2024-01-09 10:21:58 -06:00
|
|
|
log.Warn("repo =", repo)
|
|
|
|
addRepo(grid, repo)
|
|
|
|
}
|
2024-01-09 11:55:18 -06:00
|
|
|
|
2024-01-11 15:57:08 -06:00
|
|
|
win.Draw()
|
2024-01-09 01:16:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// This creates a window
|
|
|
|
func hellosmart() {
|
|
|
|
win := smartwindow.New()
|
|
|
|
win.SetParent(myGui)
|
|
|
|
win.InitWindow()
|
2024-01-10 19:44:38 -06:00
|
|
|
win.Title("hellosmart test")
|
2024-01-09 01:16:00 -06:00
|
|
|
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 10:41:35 -06:00
|
|
|
|
|
|
|
func myrepolist() []string {
|
|
|
|
content, _ := ioutil.ReadFile("/home/jcarr/.config/myrepolist")
|
|
|
|
out := string(content)
|
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
lines := strings.Split(out, "\n")
|
|
|
|
return lines
|
|
|
|
}
|
2024-01-13 21:39:44 -06:00
|
|
|
|
|
|
|
func (r *repo) newScan() bool {
|
|
|
|
if r.status == nil {
|
|
|
|
log.Warn("repo.status = nil. not initialized for some reason")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// r.scan()
|
|
|
|
if repostatus.VerifyLocalGoRepo(r.getPath()) {
|
|
|
|
log.Warn("repo actually exists", r.getPath())
|
|
|
|
} else {
|
|
|
|
log.Warn("repo does not exist", r.getPath())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
mn := r.status.GetMasterName()
|
|
|
|
mv := r.status.GetMasterVersion()
|
|
|
|
r.masterVersion.Set(mn + " " + mv)
|
|
|
|
|
|
|
|
dn := r.status.GetDevelName()
|
|
|
|
dv := r.status.GetDevelVersion()
|
|
|
|
r.develVersion.Set(dn + " " + dv)
|
|
|
|
|
|
|
|
un := r.status.GetUserName()
|
|
|
|
uv := r.status.GetUserVersion()
|
|
|
|
r.jcarrVersion.Set(un + " " + uv)
|
|
|
|
|
|
|
|
cbname := r.status.GetCurrentBranchName()
|
|
|
|
cbversion := r.status.GetCurrentBranchVersion()
|
|
|
|
ltversion := r.status.GetLastTagVersion()
|
|
|
|
r.lastLabel.Set(cbname + " " + cbversion)
|
|
|
|
r.vLabel.Set(cbname + " " + ltversion)
|
|
|
|
|
|
|
|
if r.status.CheckDirty() {
|
|
|
|
log.Warn("CheckDirty() true")
|
|
|
|
r.dirtyLabel.Set("dirty")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.Warn("CheckDirty() no")
|
|
|
|
r.dirtyLabel.Set("not dirty")
|
|
|
|
|
|
|
|
if r.status.CheckBranches() {
|
|
|
|
log.Warn("Branches are Perfect")
|
|
|
|
r.dirtyLabel.SetText("PEFECT")
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
log.Warn("Branches are not Perfect")
|
|
|
|
r.dirtyLabel.SetText("merge")
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|