try a really fast loop to see how it works out

This commit is contained in:
Jeff Carr 2024-11-17 16:08:00 -06:00
parent a2532b2f3b
commit 7afc01d14e
1 changed files with 14 additions and 4 deletions

18
cmd.go
View File

@ -149,21 +149,31 @@ func PathRunRealtime(pwd string, args []string) cmd.Status {
}
statusChan := findCmd.Start() // non-blocking
ticker := time.NewTicker(500 * time.Millisecond)
ticker := time.NewTicker(5 * time.Millisecond)
// this is interesting, maybe useful, but wierd, but neat. interesting even
// Print last line of stdout every 2s
go func() {
// loop very quickly, but only print the line if it changes
var lastout string
var lasterr string
for range ticker.C {
status := findCmd.Status()
n := len(status.Stdout)
if n != 0 {
log.Info(status.Stdout[n-1])
// fmt.Printf("status", status.Exit, "complete =", status.Complete)
newline := status.Stdout[n-1]
if lastout != newline {
lastout = newline
log.Info(lastout)
}
}
n = len(status.Stderr)
if n != 0 {
log.Info(status.Stderr[n-1])
newline := status.Stderr[n-1]
if lasterr != newline {
lasterr = newline
log.Info(lasterr)
}
}
if status.Complete {
return