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

@@ -90,7 +90,11 @@ func (b *Backup) Run(ctx context.Context) error {
defer t.Stop()
defer close(b.closed)
// Reset status when finished
defer b.term.SetStatus([]string{""})
defer func() {
if b.term.CanUpdateStatus() {
b.term.SetStatus([]string{""})
}
}()
for {
select {
@@ -132,7 +136,7 @@ func (b *Backup) Run(ctx context.Context) error {
}
// limit update frequency
if time.Since(lastUpdate) < b.MinUpdatePause {
if time.Since(lastUpdate) < b.MinUpdatePause || b.MinUpdatePause == 0 {
continue
}
lastUpdate = time.Now()