diff --git a/doc/manual_rest.rst b/doc/manual_rest.rst index d26bde9f9..3e567b359 100644 --- a/doc/manual_rest.rst +++ b/doc/manual_rest.rst @@ -135,10 +135,10 @@ command: Subcommands that support showing progress information such as ``backup``, ``check`` and ``prune`` will do so unless the quiet flag ``-q`` or -``--quiet`` is set. For interactive consoles the environment variable -``RESTIC_PROGRESS_FPS`` can be used to control the frequency of progress -reporting. When running from a non-interactive console progress reporting -is disabled to not fill your logs. +``--quiet`` is set. When running from a non-interactive console progress +reporting is disabled by default to not fill your logs. For interactive +and non-interactive consoles the environment variable ``RESTIC_PROGRESS_FPS`` +can be used to control the frequency of progress reporting. Additionally, on Unix systems if ``restic`` receives a SIGUSR1 signal the current progress will be written to the standard output so you can check up diff --git a/internal/ui/backup.go b/internal/ui/backup.go index fc87712f7..5b37446a9 100644 --- a/internal/ui/backup.go +++ b/internal/ui/backup.go @@ -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() diff --git a/internal/ui/termstatus/status.go b/internal/ui/termstatus/status.go index c0873577c..ff0a899f6 100644 --- a/internal/ui/termstatus/status.go +++ b/internal/ui/termstatus/status.go @@ -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) + } } } }