move xterm here

This commit is contained in:
Jeff Carr 2025-01-07 18:53:10 -06:00
parent a8088938d2
commit 51e34a86ff
5 changed files with 58 additions and 13 deletions

View File

@ -9,12 +9,12 @@ import (
) )
var REPO *log.LogFlag var REPO *log.LogFlag
var REPOWARN *log.LogFlag var WARN *log.LogFlag
func init() { func init() {
full := "go.wit.com/lib/gui/repo" full := "go.wit.com/lib/gui/repo"
short := "repo" short := "repo"
REPO = log.NewFlag("REPO", false, full, short, "general repo things") REPO = log.NewFlag("REPO", false, full, short, "general repo things")
REPOWARN = log.NewFlag("REPOWARN", true, full, short, "repo warnings") WARN = log.NewFlag("REPOWARN", true, full, short, "repo warnings")
} }

View File

@ -103,10 +103,10 @@ func (r *RepoList) AddRepo(pb *gitpb.Repo) (*RepoRow, error) {
newRepo.endBox.NewButton("show diff", func() { newRepo.endBox.NewButton("show diff", func() {
r.reposbox.Disable() r.reposbox.Disable()
log.Log(REPOWARN, "show diff currentName =", newRepo.currentName.String()) log.Log(WARN, "show diff currentName =", newRepo.currentName.String())
log.Log(REPOWARN, "show diff masterVersion =", newRepo.masterVersion.String()) log.Log(WARN, "show diff masterVersion =", newRepo.masterVersion.String())
// newRepo.Status.XtermNohup([]string{"git diff"}) // newRepo.Status.XtermNohup([]string{"git diff"})
newRepo.Status.Xterm("git diff; bash") newRepo.Xterm("git diff; bash")
r.reposbox.Enable() r.reposbox.Enable()
}) })
@ -117,17 +117,17 @@ func (r *RepoList) AddRepo(pb *gitpb.Repo) (*RepoRow, error) {
return return
} }
if !pb.IsUserBranch() { if !pb.IsUserBranch() {
log.Log(REPOWARN, "can not commit on non user branch") log.Log(WARN, "can not commit on non user branch")
return return
} }
r.reposbox.Disable() r.reposbox.Disable()
// restore anything staged so everything can be reviewed // restore anything staged so everything can be reviewed
pb.RunRealtimeVerbose([]string{"git", "restore", "--staged", "."}) pb.RunRealtimeVerbose([]string{"git", "restore", "--staged", "."})
newRepo.Status.XtermWait("git diff") newRepo.XtermWait("git diff")
newRepo.Status.XtermWait("git add --all") newRepo.XtermWait("git add --all")
newRepo.Status.XtermWait("git commit -a") newRepo.XtermWait("git commit -a")
newRepo.Status.XtermWait("git push") newRepo.XtermWait("git push")
if newRepo.Status.CheckDirty() { if newRepo.Status.CheckDirty() {
// commit was not done, restore diff // commit was not done, restore diff
pb.RunRealtimeVerbose([]string{"git", "restore", "--staged", "."}) pb.RunRealtimeVerbose([]string{"git", "restore", "--staged", "."})

View File

@ -47,12 +47,12 @@ func (r *RepoRow) UpdatePb(newpb *gitpb.Repo) {
func (r *RepoRow) NewScan() int { func (r *RepoRow) NewScan() int {
var changed int = 0 var changed int = 0
if r.Status == nil { if r.Status == nil {
log.Log(REPOWARN, "repo.Status = nil. not initialized for some reason") log.Log(WARN, "repo.Status = nil. not initialized for some reason")
return changed return changed
} }
pb := r.pb pb := r.pb
if pb == nil { if pb == nil {
log.Log(REPOWARN, "NewScan() pb = nil") log.Log(WARN, "NewScan() pb = nil")
return changed return changed
} }

View File

@ -34,7 +34,7 @@ func (r *RepoList) Watchdog(f func()) {
} }
// print every 'delay' seconds // print every 'delay' seconds
if i%delay == 0 { if i%delay == 0 {
log.Log(REPOWARN, "Not auto scanning", i, "REPO_AUTO_SCAN =", os.Getenv("REPO_AUTO_SCAN")) log.Log(WARN, "Not auto scanning", i, "REPO_AUTO_SCAN =", os.Getenv("REPO_AUTO_SCAN"))
} }
return return
} }

45
xterm.go Normal file
View File

@ -0,0 +1,45 @@
package repolist
import (
"os"
"os/exec"
"strings"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
func (rs *RepoRow) XtermNohup(cmdline string) {
p := rs.pb.GetFullPath()
shell.XtermCmd(p, []string{cmdline})
}
func (rs *RepoRow) Xterm(cmdline string) {
p := rs.pb.GetFullPath()
shell.XtermCmd(p, []string{cmdline})
}
func (rs *RepoRow) XtermWait(cmdline string) {
p := rs.pb.GetFullPath()
shell.XtermCmdWait(p, []string{cmdline})
}
func (rs *RepoRow) XtermBash(args []string) {
var argsX = []string{"-geometry", "120x40"}
tmp := strings.Join(args, " ") + ";bash"
argsX = append(argsX, "-e", "bash", "-c", tmp)
argsX = append(argsX, args...)
log.Info("xterm cmd=", argsX)
// set less to not exit on small diff's
os.Setenv("LESS", "-+F -+X -R")
cmd := exec.Command("xterm", argsX...)
path := rs.pb.GetFullPath()
cmd.Dir = path
if err := cmd.Run(); err != nil {
log.Log(WARN, "xterm.Run() failed")
log.Log(WARN, "path =", path)
log.Log(WARN, "cmd = xterm", argsX)
} else {
log.Log(WARN, "xterm.Run() worked")
log.Log(WARN, "path =", path)
log.Log(WARN, "cmd = xterm", argsX)
}
}