aboutsummaryrefslogtreecommitdiff
path: root/internal/progress/refresh.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-08 14:15:38 +0800
committerGravatar Runxi Yu2026-03-08 14:15:38 +0800
commitc75a034d25ca87f3d209a8e82c743b8a7e96573b (patch)
treed8cd5befb9d812ab622dcce094c9d30797d6d861 /internal/progress/refresh.go
parent*: BestEffortFprintf as linter wants (diff)
signatureNo signature
internal/progress: Add progress meter
Diffstat (limited to 'internal/progress/refresh.go')
-rw-r--r--internal/progress/refresh.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/progress/refresh.go b/internal/progress/refresh.go
new file mode 100644
index 00000000..ed1782db
--- /dev/null
+++ b/internal/progress/refresh.go
@@ -0,0 +1,25 @@
+package progress
+
+import "time"
+
+func (meter *Meter) refreshThroughput(now time.Time) {
+ if !meter.throughput {
+ return
+ }
+
+ if meter.nextThroughput.After(now) && meter.throughputSuffix != "" {
+ return
+ }
+
+ for !now.Before(meter.nextThroughput) {
+ meter.nextThroughput = meter.nextThroughput.Add(throughputInterval)
+ }
+
+ elapsed := now.Sub(meter.startedAt)
+ if elapsed <= 0 {
+ return
+ }
+
+ rate := uint64(float64(meter.lastBytes) / elapsed.Seconds())
+ meter.throughputSuffix = ", " + humanizeBytes(meter.lastBytes) + " | " + humanizeBytes(rate) + "/s"
+}