cleanup progress bar creation special cases

This commit is contained in:
Michael Eischer
2025-09-13 23:07:25 +02:00
parent b0eef4b965
commit 8b5dbc18ca
3 changed files with 4 additions and 9 deletions

View File

@@ -87,7 +87,8 @@ func runRecover(ctx context.Context, gopts GlobalOptions, term *termstatus.Termi
}
printer.P("load %d trees\n", len(trees))
bar = newTerminalProgressMax(!gopts.Quiet, uint64(len(trees)), "trees loaded", term)
bar = printer.NewCounter("trees loaded")
bar.SetMax(uint64(len(trees)))
for id := range trees {
tree, err := restic.LoadTree(ctx, repo, id)
if ctx.Err() != nil {

View File

@@ -10,7 +10,6 @@ import (
"github.com/restic/restic/internal/filter"
"github.com/restic/restic/internal/restic"
"github.com/restic/restic/internal/restorer"
"github.com/restic/restic/internal/terminal"
restoreui "github.com/restic/restic/internal/ui/restore"
"github.com/restic/restic/internal/ui/termstatus"
@@ -260,7 +259,7 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions,
}
var count int
t0 := time.Now()
bar := newTerminalProgressMax(!gopts.Quiet && !gopts.JSON && terminal.StdoutIsTerminal(), 0, "files verified", term)
bar := msg.NewCounterTerminalOnly("files verified")
count, err = res.VerifyFiles(ctx, opts.Target, countRestoredFiles, bar)
if err != nil {
return err

View File

@@ -62,11 +62,6 @@ func newTerminalProgressMax(show bool, max uint64, description string, term *ter
})
}
// newProgressMax calls newTerminalProgress without a terminal (print to stdout)
func newProgressMax(show bool, max uint64, description string) *progress.Counter {
return newGenericProgressMax(show, max, description, printProgress)
}
func printProgress(status string, final bool) {
canUpdateStatus := terminal.StdoutCanUpdateStatus()
@@ -103,7 +98,7 @@ func printProgress(status string, final bool) {
}
func newIndexProgress(quiet bool, json bool) *progress.Counter {
return newProgressMax(!quiet && !json && terminal.StdoutIsTerminal(), 0, "index files loaded")
return newGenericProgressMax(!quiet && !json && terminal.StdoutIsTerminal(), 0, "index files loaded", printProgress)
}
type terminalProgressPrinter struct {