mirror of
https://github.com/restic/restic.git
synced 2026-11-06 07:19:21 +00:00
restic: introduce Counter interface to decouple from ui/progress (#21861)
decouple restic and ui/progress packages
This commit is contained in:
1 parent
22a304af7e
commit
8e11f5747d
37 files changed
+181
-145
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
"github.com/restic/restic/internal/ui"
|
||||
)
|
||||
|
||||
@@ -27,9 +28,9 @@ func CalculateProgressInterval(show bool, json bool, canUpdateStatus bool) time.
|
||||
}
|
||||
|
||||
// newProgressMax returns a progress.Counter that prints to terminal if provided.
|
||||
func newProgressMax(show bool, max uint64, description string, term ui.Terminal) *Counter {
|
||||
func newProgressMax(show bool, max uint64, description string, term ui.Terminal) restic.Counter {
|
||||
if !show {
|
||||
return nil
|
||||
return restic.NoopCounter
|
||||
}
|
||||
interval := CalculateProgressInterval(show, false, term.CanUpdateStatus())
|
||||
|
||||
@@ -57,11 +58,11 @@ type terminalPrinter struct {
|
||||
v uint
|
||||
}
|
||||
|
||||
func (t *terminalPrinter) NewCounter(description string) *Counter {
|
||||
func (t *terminalPrinter) NewCounter(description string) restic.Counter {
|
||||
return newProgressMax(t.v > 0, 0, description, t.term)
|
||||
}
|
||||
|
||||
func (t *terminalPrinter) NewCounterTerminalOnly(description string) *Counter {
|
||||
func (t *terminalPrinter) NewCounterTerminalOnly(description string) restic.Counter {
|
||||
return newProgressMax(t.v > 0 && t.term.OutputIsTerminal(), 0, description, t.term)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user