diff --git a/main.go b/main.go index 57b2f55..c3b8687 100644 --- a/main.go +++ b/main.go @@ -2,64 +2,24 @@ package main import ( - "io/ioutil" - "strings" + "os/user" "go.wit.com/log" "go.wit.com/gui/gui" "go.wit.com/gui/gadgets" "go.wit.com/gui/gadgets/repostatus" - "go.wit.com/apps/control-panel-dns/smartwindow" ) -var myGui *gui.Node - -var allrepos []*repo - -type repo struct { - path string - lasttagrev string - lasttag string - tags []string - - pLabel *gui.Node // path label - bLabel *gui.Node // branch label - lastLabel *gui.Node // last tagged version label - vLabel *gui.Node // version label - // tagsDrop *gui.Node // list of all tags - 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 - - cButton *gui.Node // commit button - pButton *gui.Node // push button - - status *repostatus.RepoStatus -} - func main() { myGui = gui.New().Default() repoworld() - /* - for i, r := range allrepos { - log.Warn("scannning", i, r.path) - r.scan() - } - */ - gui.Watchdog() } -func (r *repo) getPath() string { - return r.path -} - -func addRepo(grid *gui.Node, path string) { +func addRepo(grid *gui.Node, path string, master string, devel string, user string) { newRepo := new(repo) if repostatus.VerifyLocalGoRepo(path) { @@ -74,43 +34,16 @@ func addRepo(grid *gui.Node, path string) { newRepo.bLabel = grid.NewLabel("") newRepo.lastLabel = grid.NewLabel("") newRepo.vLabel = grid.NewLabel("") - // newRepo.tagsDrop = grid.NewDropdown("tags") newRepo.masterVersion = grid.NewLabel("") newRepo.develVersion = grid.NewLabel("") newRepo.jcarrVersion = grid.NewLabel("") newRepo.dirtyLabel = grid.NewLabel("") - /* - newRepo.cButton = grid.NewButton("status", func () { - log.Println("repo status for", newRepo.path) - newRepo.scan() - if newRepo.status == nil { - newRepo.status = repostatus.New(myGui, newRepo.path) - newRepo.status.Vertical() - newRepo.status.Horizontal() - newRepo.status.Make() - newRepo.status.Draw() - newRepo.status.Draw2() - } - newRepo.status.Toggle() - }) - */ newRepo.pButton = grid.NewButton("rescan", func () { 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") @@ -135,6 +68,9 @@ func addRepo(grid *gui.Node, path string) { newRepo.status.Horizontal() newRepo.status.Make() newRepo.status.Make2() + newRepo.status.SetMasterName(master) + newRepo.status.SetDevelName(devel) + newRepo.status.SetUserName(user) newRepo.status.Update() newRepo.newScan() allrepos = append(allrepos, newRepo) @@ -156,96 +92,22 @@ func repoworld() { // grid.NewLabel("tags") grid.NewLabel("master") grid.NewLabel("devel") - grid.NewLabel("jcarr") + grid.NewLabel("user") grid.NewLabel("Status") grid.NewLabel("commit") grid.NewLabel("Toggle()") grid.NewLabel("Draw()") repos := myrepolist() - for _, repo := range repos { - log.Warn("repo =", repo) - addRepo(grid, repo) + for _, line := range repos { + log.Warn("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(grid, path, mbranch, dbranch, ubranch) } win.Draw() } - -// This creates a window -func hellosmart() { - win := smartwindow.New() - win.SetParent(myGui) - win.InitWindow() - win.Title("hellosmart test") - 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 myrepolist() []string { - content, _ := ioutil.ReadFile("/home/jcarr/.config/myrepolist") - out := string(content) - out = strings.TrimSpace(out) - lines := strings.Split(out, "\n") - return lines -} - -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 -} diff --git a/repolist.go b/repolist.go new file mode 100644 index 0000000..fae362f --- /dev/null +++ b/repolist.go @@ -0,0 +1,114 @@ +// This is a simple example +package main + +import ( + "io/ioutil" + "strings" + + "go.wit.com/log" + + "go.wit.com/gui/gadgets/repostatus" + "go.wit.com/apps/control-panel-dns/smartwindow" +) + +func (r *repo) getPath() string { + return r.path +} + +func RemoveFirstElement(slice []string) (string, []string) { + if len(slice) == 0 { + return "", slice // Return the original slice if it's empty + } + return slice[0], slice[1:] // Return the slice without the first element +} + +// returns path, master branch name, devel branch name, user branch name +func splitLine(line string) (string, string, string, string) { + var path, master, devel, user string + parts := strings.Split(line, " ") + path, parts = RemoveFirstElement(parts) + master, parts = RemoveFirstElement(parts) + devel, parts = RemoveFirstElement(parts) + user, parts = RemoveFirstElement(parts) + // path, master, devel, user := strings.Split(line, " ") + return path, master, devel, user +} + +// This creates a window +func hellosmart() { + win := smartwindow.New() + win.SetParent(myGui) + win.InitWindow() + win.Title("hellosmart test") + 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 myrepolist() []string { + content, _ := ioutil.ReadFile("/home/jcarr/.config/myrepolist") + out := string(content) + out = strings.TrimSpace(out) + lines := strings.Split(out, "\n") + return lines +} + +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 +} diff --git a/structs.go b/structs.go new file mode 100644 index 0000000..b56cbc1 --- /dev/null +++ b/structs.go @@ -0,0 +1,42 @@ +// This is a simple example +package main + +import ( +// "os/user" +// "io/ioutil" +// "strings" + +// "go.wit.com/log" + + "go.wit.com/gui/gui" +// "go.wit.com/gui/gadgets" + "go.wit.com/gui/gadgets/repostatus" +// "go.wit.com/apps/control-panel-dns/smartwindow" +) + +var myGui *gui.Node + +var allrepos []*repo + +type repo struct { + path string + lasttagrev string + lasttag string + tags []string + + pLabel *gui.Node // path label + bLabel *gui.Node // branch label + lastLabel *gui.Node // last tagged version label + vLabel *gui.Node // version label + // tagsDrop *gui.Node // list of all tags + 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 + + cButton *gui.Node // commit button + pButton *gui.Node // push button + + status *repostatus.RepoStatus +}