more realtime-ish output when humans are watching

This commit is contained in:
Jeff Carr 2024-11-15 09:13:06 -06:00
parent bc31c85413
commit a2532b2f3b
1 changed files with 17 additions and 6 deletions

23
cmd.go
View File

@ -122,14 +122,18 @@ func PathRunLog(path string, argv []string, logf *log.LogFlag) cmd.Status {
return s return s
} }
// uses the 'log' package to disable echo to STDOUT
// only echos if you enable the shell.INFO log flag // only echos if you enable the shell.INFO log flag
func PathRunQuiet(pwd string, args []string) cmd.Status { func PathRunQuiet(pwd string, args []string) cmd.Status {
return PathRunLog(pwd, args, INFO) return PathRunLog(pwd, args, INFO)
} }
// absolutely doesn't echo anything // echos twice a second if anything sends to STDOUT or STDERR
// bad for now. leaves goroutines running all over the place // not great, but it's really just for watching things run in real time anyway
func PathRunQuietBad(pwd string, args []string) cmd.Status { // TODO: fix \r handling for things like git-clone so the terminal doesn't
// have to do a \n newline each time.
// TODO: add timeouts and status of things hanging around forever
func PathRunRealtime(pwd string, args []string) cmd.Status {
// Check if the slice has at least one element (the command name) // Check if the slice has at least one element (the command name)
if len(args) == 0 { if len(args) == 0 {
var s cmd.Status var s cmd.Status
@ -145,7 +149,7 @@ func PathRunQuietBad(pwd string, args []string) cmd.Status {
} }
statusChan := findCmd.Start() // non-blocking statusChan := findCmd.Start() // non-blocking
ticker := time.NewTicker(2 * time.Second) ticker := time.NewTicker(500 * time.Millisecond)
// this is interesting, maybe useful, but wierd, but neat. interesting even // this is interesting, maybe useful, but wierd, but neat. interesting even
// Print last line of stdout every 2s // Print last line of stdout every 2s
@ -154,8 +158,15 @@ func PathRunQuietBad(pwd string, args []string) cmd.Status {
status := findCmd.Status() status := findCmd.Status()
n := len(status.Stdout) n := len(status.Stdout)
if n != 0 { if n != 0 {
fmt.Println("todo:removethisecho", status.Stdout[n-1]) log.Info(status.Stdout[n-1])
fmt.Println("status", status.Exit) // fmt.Printf("status", status.Exit, "complete =", status.Complete)
}
n = len(status.Stderr)
if n != 0 {
log.Info(status.Stderr[n-1])
}
if status.Complete {
return
} }
} }
}() }()