mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 02:48:55 +00:00
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:
parent
85fe5feadb
commit
684600cf42
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user