From 4555b9f34d926f1a94691a1d2db5ed2d1520daa8 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 12 Feb 2024 15:24:35 -0600 Subject: [PATCH] add a git commit button. I used it for this commit --- args.go | 10 +++----- globalBuildOptions.go | 3 +-- globalDisplayOptions.go | 6 ++--- main.go | 15 ++++++----- nohup.out | 0 repolist.go | 45 ++++++++++++++++++++++++++------ structs.go | 8 +++--- summaryBox.go | 57 +++++++++++++++++++++++++++++++++++++++++ tagWindow.go | 7 ++--- 9 files changed, 119 insertions(+), 32 deletions(-) create mode 100644 nohup.out create mode 100644 summaryBox.go diff --git a/args.go b/args.go index 0711ba4..0f827c7 100644 --- a/args.go +++ b/args.go @@ -12,15 +12,11 @@ import ( "go.wit.com/log" ) -// GadgetDisplay string `arg:"env:DISPLAY"` -// GadgetTmpLog bool `arg:"--tmp-log" help:"automatically send STDOUT to /tmp"` -// GadgetVerboseDNS bool `arg:"--verbose" help:"debug your dns settings"` var args struct { DownloadAll bool `arg:"--download-all" help:"download everything from go.wit.com"` GitPull bool `arg:"--git-pull" help:"do git pull in every repository"` CheckoutUser bool `arg:"--switch-to-user-branch" help:"switch everything to your user branch"` CheckoutDevel bool `arg:"--switch-to-devel-branch" help:"switch everything to the devel branch"` - TmpLog bool `arg:"--tmp-log" help:"automatically send STDOUT to /tmp"` } func init() { @@ -28,7 +24,9 @@ func init() { if debugger.ArgDebug() { log.Info("cmd line --debugger == true") - } else { - log.Info("cmd line --debugger == false") + go func() { + log.Sleep(2) + debugger.DebugWindow() + }() } } diff --git a/globalBuildOptions.go b/globalBuildOptions.go index 4fd8ee7..44b6f8c 100644 --- a/globalBuildOptions.go +++ b/globalBuildOptions.go @@ -54,8 +54,7 @@ func quickCmd(fullpath string, cmd []string) bool { return true } -func globalBuildOptions(box *gui.Node) { - vbox := box.NewVerticalBox("DISPLAYVBOX") +func globalBuildOptions(vbox *gui.Node) { group1 := vbox.NewGroup("Global Build Options") grid := group1.NewGrid("buildOptions", 2, 1) diff --git a/globalDisplayOptions.go b/globalDisplayOptions.go index 4b83f21..c45a045 100644 --- a/globalDisplayOptions.go +++ b/globalDisplayOptions.go @@ -47,9 +47,7 @@ func globalDisplayShow() { } } -func globalDisplayOptions(box *gui.Node) { - vbox := box.NewVerticalBox("DISPLAYVBOX") - +func globalDisplayOptions(vbox *gui.Node) { group1 := vbox.NewGroup("Global Display Options") group1.NewButton("Show Repository Window", func() { @@ -123,7 +121,9 @@ func globalDisplayOptions(box *gui.Node) { } listallB.Enable() }) +} +func debuggerBox(vbox *gui.Node) { group2 := vbox.NewGroup("Debugger") group2.NewButton("logging Window", func() { logsettings.LogWindow() diff --git a/main.go b/main.go index 3e95eb9..fafd202 100644 --- a/main.go +++ b/main.go @@ -16,11 +16,6 @@ func main() { me = new(autoType) me.allrepos = make(map[string]*repo) - if args.TmpLog { - // send all log() output to a file in /tmp - log.SetTmp() - } - me.myGui = gui.New() me.myGui.InitEmbed(resToolkit) me.myGui.Default() @@ -28,8 +23,14 @@ func main() { me.autotypistWindow = me.myGui.NewWindow("autotypist for GO & git. it types faster than you can.") box := me.autotypistWindow.NewBox("bw hbox", true) - globalDisplayOptions(box) - globalBuildOptions(box) + vbox1 := box.NewVerticalBox("BOX1") + globalDisplayOptions(vbox1) + debuggerBox(vbox1) + + vbox2 := box.NewVerticalBox("BOX2") + globalBuildOptions(vbox2) + summaryBox(vbox2) + globalResetOptions(box) repolistWindow() diff --git a/nohup.out b/nohup.out new file mode 100644 index 0000000..e69de29 diff --git a/repolist.go b/repolist.go index 0af324e..23e4281 100644 --- a/repolist.go +++ b/repolist.go @@ -60,7 +60,9 @@ func (r *repo) Hide() { r.userVersion.Hide() r.dirtyLabel.Hide() - r.statusButton.Hide() + r.endBox.Hide() + // r.statusButton.Hide() + // r.diffButton.Hide() r.hidden = true } @@ -74,7 +76,9 @@ func (r *repo) Show() { r.userVersion.Show() r.dirtyLabel.Show() - r.statusButton.Show() + r.endBox.Show() + // r.statusButton.Show() + // r.diffButton.Show() r.hidden = false } @@ -113,15 +117,40 @@ func addRepo(grid *gui.Node, path string, master string, devel string, user stri newRepo.vLabel = grid.NewLabel("").SetProgName("current") - newRepo.statusButton = grid.NewButton("Configure", func() { + newRepo.endBox = grid.NewHorizontalBox("HBOX") + + newRepo.endBox.NewButton("Configure", func() { if newRepo.status == nil { - log.Warn("status window doesn't exist") + log.Warn("status window wasn't created") return } - log.Warn("status window exists. trying TestDraw() here") newRepo.status.Toggle() }) + newRepo.endBox.NewButton("show diff", func() { + me.reposwin.Disable() + newRepo.status.XtermNohup([]string{"git diff"}) + me.reposwin.Enable() + }) + + newRepo.endBox.NewButton("commit all", func() { + me.reposwin.Disable() + // restore anything staged so everything can be reviewed + newRepo.status.Xterm([]string{"git restore --staged ."}) + // newRepo.status.Xterm([]string{"git diff"}) + newRepo.status.Xterm([]string{"git add --all"}) + newRepo.status.XtermNohup([]string{"git diff --cached"}) + newRepo.status.Xterm([]string{"git commit -a"}) + if newRepo.status.CheckDirty() { + // commit was not done, restore diff + newRepo.status.Xterm([]string{"git restore --staged ."}) + } else { + newRepo.status.Update() + newRepo.newScan() + } + me.reposwin.Enable() + }) + newRepo.status = repostatus.NewRepoStatusWindow(newRepo.path) newRepo.hidden = false newRepo.status.SetMainWorkingName(master) @@ -146,7 +175,7 @@ func repolistWindow() { repoAllButtons(me.reposbox) me.reposgroup = me.reposbox.NewGroup("go repositories (read from ~/.config/myrepolist)") - me.reposgrid = me.reposgroup.NewGrid("test", 8, 1) + me.reposgrid = me.reposgroup.NewGrid("test", 0, 0) me.reposgrid.NewLabel("") // path goes here @@ -159,8 +188,7 @@ func repolistWindow() { me.reposgrid.NewLabel("Status") me.reposgrid.NewLabel("Current Version").SetProgName("Current Version") - - me.reposgrid.NewLabel("Show()") + me.reposgrid.NextRow() usr, _ := user.Current() @@ -178,6 +206,7 @@ func repolistWindow() { ubranch = usr.Username } addRepo(me.reposgrid, path, mbranch, dbranch, ubranch) + me.reposgrid.NextRow() } // TODO: figure out why this borks everything diff --git a/structs.go b/structs.go index 2b262dd..2cda697 100644 --- a/structs.go +++ b/structs.go @@ -15,9 +15,9 @@ type autoType struct { autotypistWindow *gui.Node - reposwin *gadgets.BasicWindow - reposbox *gui.Node - reposgrid *gui.Node + reposwin *gadgets.BasicWindow + reposbox *gui.Node + reposgrid *gui.Node reposgroup *gui.Node // #### autotypist Global Display Options @@ -83,7 +83,9 @@ type repo struct { develVersion *gui.Node // the devel branch version userVersion *gui.Node // the user branch version + endBox *gui.Node // a general box at the end of the row statusButton *gui.Node // opens up the status window + diffButton *gui.Node // opens up the status window status *repostatus.RepoStatus } diff --git a/summaryBox.go b/summaryBox.go new file mode 100644 index 0000000..3bf0cd5 --- /dev/null +++ b/summaryBox.go @@ -0,0 +1,57 @@ +// This is a simple example +package main + +import ( + "fmt" + "os" + "path/filepath" + + "go.wit.com/gui" + "go.wit.com/lib/gui/shell" + "go.wit.com/log" + // "go.wit.com/gui/gadgets" +) + +func summaryBox(box *gui.Node) { + group1 := box.NewGroup("Repository Summary") + grid := group1.RawGrid() + + grid.NewButton("Show Repository Window", func() { + globalDisplaySetRepoState() + // reposwin.Toggle() + }) + + grid.NewButton("open docs (localhost:8080)", func() { + me.autotypistWindow.Disable() + defer me.autotypistWindow.Enable() + + goSrcDir := me.goSrcPwd.String() + filename := filepath.Join(goSrcDir, "go.work") + + f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600) + if err != nil { + return + } + defer f.Close() + fmt.Fprintln(f, "go 1.21.4") + fmt.Fprintln(f, "") + fmt.Fprintln(f, "use (") + for _, repo := range me.allrepos { + if repo.status.Exists("go.mod") { + fmt.Fprintln(f, "\t"+repo.String()) + } else { + log.Info("missing go.mod for", repo.String()) + repo.status.MakeRedomod() + } + } + fmt.Fprintln(f, ")") + tmp := me.userHomePwd.String() + tmpDir := filepath.Join(tmp, "go/src") + os.Chdir(tmpDir) + pkgsite := filepath.Join(tmp, "go/bin", "pkgsite") + os.Unsetenv("GO111MODULE") + go shell.Run([]string{pkgsite}) + shell.Run([]string{"ping", "-c", "3", "git.wit.org"}) + shell.OpenBrowser("http://localhost:8080") + }) +} diff --git a/tagWindow.go b/tagWindow.go index 745ab62..d5e33b8 100644 --- a/tagWindow.go +++ b/tagWindow.go @@ -39,10 +39,11 @@ func makeTagWindow() *tagWindow { tagW.win.Draw() tagW.box = tagW.win.Box() + topGrid := tagW.box.RawGrid() tagW.group = tagW.box.NewGroup("tags") tagW.grid = tagW.box.RawGrid() - tagW.group.NewButton("list all tags", func() { + topGrid.NewButton("list all tags", func() { me.autotypistWindow.Disable() defer me.autotypistWindow.Enable() for _, repo := range me.allrepos { @@ -58,9 +59,9 @@ func makeTagWindow() *tagWindow { log.Info("found tag:", t.TagString(), "from", repo.status.String()) } } - }) + }).SetProgName("TAGSLISTALL") - tagW.group.NewButton("delete all dup tags", func() { + topGrid.NewButton("delete all dup tags", func() { me.autotypistWindow.Disable() defer me.autotypistWindow.Enable() for _, repo := range me.allrepos {