mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 21:38:07 -05:00
progress: Rate limit drawing in the progress-reporter/bar.
This helps smooth the output in cases where the bar is updated very quickly, for example in guix weather where it's computing derivations. * guix/progress.scm (progress-reporter/bar): Wrap the drawing code with the rate-limited procedure.
This commit is contained in:
parent
c12c7f1284
commit
604880ae22
1 changed files with 16 additions and 10 deletions
|
@ -270,19 +270,25 @@ (define* (progress-reporter/bar total
|
|||
tasks is performed. Write PREFIX at the beginning of the line."
|
||||
(define done 0)
|
||||
|
||||
(define (draw-bar)
|
||||
(let* ((ratio (* 100. (/ done total))))
|
||||
(erase-current-line port)
|
||||
(if (string-null? prefix)
|
||||
(display (progress-bar ratio (current-terminal-columns)) port)
|
||||
(let ((width (- (current-terminal-columns)
|
||||
(string-length prefix) 3)))
|
||||
(display prefix port)
|
||||
(display " " port)
|
||||
(display (progress-bar ratio width) port)))
|
||||
(force-output port)))
|
||||
|
||||
(define draw-bar/rate-limited
|
||||
(rate-limited draw-bar %progress-interval))
|
||||
|
||||
(define (report-progress)
|
||||
(set! done (+ 1 done))
|
||||
(unless (> done total)
|
||||
(let* ((ratio (* 100. (/ done total))))
|
||||
(erase-current-line port)
|
||||
(if (string-null? prefix)
|
||||
(display (progress-bar ratio (current-terminal-columns)) port)
|
||||
(let ((width (- (current-terminal-columns)
|
||||
(string-length prefix) 3)))
|
||||
(display prefix port)
|
||||
(display " " port)
|
||||
(display (progress-bar ratio width) port)))
|
||||
(force-output port))))
|
||||
(draw-bar/rate-limited)))
|
||||
|
||||
(progress-reporter
|
||||
(start (lambda ()
|
||||
|
|
Loading…
Reference in a new issue