mirror of
https://github.com/restic/restic.git
synced 2025-08-23 13:08:08 +00:00
ui/progress: don't print progress on non-interactive terminals
This reverts to the old behavior of not printing progress updates on non-interactive terminals. It was accidentally changed in #3058.
This commit is contained in:
@@ -41,7 +41,9 @@ func New(interval time.Duration, report Func) *Counter {
|
||||
start: time.Now(),
|
||||
stopped: make(chan struct{}),
|
||||
stop: make(chan struct{}),
|
||||
tick: time.NewTicker(interval),
|
||||
}
|
||||
if interval > 0 {
|
||||
c.tick = time.NewTicker(interval)
|
||||
}
|
||||
|
||||
go c.run()
|
||||
@@ -64,7 +66,9 @@ func (c *Counter) Done() {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
c.tick.Stop()
|
||||
if c.tick != nil {
|
||||
c.tick.Stop()
|
||||
}
|
||||
close(c.stop)
|
||||
<-c.stopped // Wait for last progress report.
|
||||
*c = Counter{} // Prevent reuse.
|
||||
@@ -85,11 +89,15 @@ func (c *Counter) run() {
|
||||
c.report(c.get(), time.Since(c.start), true)
|
||||
}()
|
||||
|
||||
var tick <-chan time.Time
|
||||
if c.tick != nil {
|
||||
tick = c.tick.C
|
||||
}
|
||||
for {
|
||||
var now time.Time
|
||||
|
||||
select {
|
||||
case now = <-c.tick.C:
|
||||
case now = <-tick:
|
||||
case sig := <-signals.ch:
|
||||
debug.Log("Signal received: %v\n", sig)
|
||||
now = time.Now()
|
||||
|
@@ -53,3 +53,22 @@ func TestCounterNil(t *testing.T) {
|
||||
c.Add(1)
|
||||
c.Done()
|
||||
}
|
||||
|
||||
func TestCounterNoTick(t *testing.T) {
|
||||
finalSeen := false
|
||||
otherSeen := false
|
||||
|
||||
report := func(value uint64, d time.Duration, final bool) {
|
||||
if final {
|
||||
finalSeen = true
|
||||
} else {
|
||||
otherSeen = true
|
||||
}
|
||||
}
|
||||
c := progress.New(0, report)
|
||||
time.Sleep(time.Millisecond)
|
||||
c.Done()
|
||||
|
||||
test.Assert(t, finalSeen, "final call did not happen")
|
||||
test.Assert(t, !otherSeen, "unexpected status update")
|
||||
}
|
||||
|
Reference in New Issue
Block a user