ui: update status for the backup command on non-interactive terminals

Allow the backup command to print status on non-interactive terminals.
The output is disabled by setting a MinUpdatePause == 0.
This commit is contained in:
Michael Eischer
2020-12-29 15:05:08 +01:00
parent 85fe5feadb
commit 684600cf42
3 changed files with 24 additions and 8 deletions

View File

@@ -78,6 +78,11 @@ func New(wr io.Writer, errWriter io.Writer, disableStatus bool) *Terminal {
return t
}
// CanUpdateStatus return whether the status output is updated in place.
func (t *Terminal) CanUpdateStatus() bool {
return t.canUpdateStatus
}
// Run updates the screen. It should be run in a separate goroutine. When
// ctx is cancelled, the status lines are cleanly removed.
func (t *Terminal) Run(ctx context.Context) {
@@ -203,8 +208,15 @@ func (t *Terminal) runWithoutStatus(ctx context.Context) {
fmt.Fprintf(os.Stderr, "flush failed: %v\n", err)
}
case <-t.status:
// discard status lines
case stat := <-t.status:
for _, line := range stat.lines {
// ensure that each line ends with newline
withNewline := strings.TrimRight(line, "\n") + "\n"
fmt.Fprint(t.wr, withNewline)
}
if err := t.wr.Flush(); err != nil {
fmt.Fprintf(os.Stderr, "flush failed: %v\n", err)
}
}
}
}