mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-13 14:40:21 -05:00
git: Make better use of the better progress bar.
Commit 189525412e
introduced
‘high-resolution’ Unicode progress bars, but these require more granular
calls to reach their full potential.
* guix/git.scm (show-progress): Derive the number of PROGRESS-BAR
updates from its maximum resolution, rather than hard-coding 100.
This commit is contained in:
parent
98e2a15b1e
commit
5d10644371
1 changed files with 15 additions and 11 deletions
26
guix/git.scm
26
guix/git.scm
|
@ -4,6 +4,7 @@
|
||||||
;;; Copyright © 2021 Kyle Meyer <kyle@kyleam.com>
|
;;; Copyright © 2021 Kyle Meyer <kyle@kyleam.com>
|
||||||
;;; Copyright © 2021 Marius Bakke <marius@gnu.org>
|
;;; Copyright © 2021 Marius Bakke <marius@gnu.org>
|
||||||
;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
|
;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
|
||||||
|
;;; Copyright © 2023 Tobias Geerinckx-Rice <me@tobias.gr>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -141,11 +142,6 @@ (define (show-progress progress)
|
||||||
(define total
|
(define total
|
||||||
(indexer-progress-total-objects progress))
|
(indexer-progress-total-objects progress))
|
||||||
|
|
||||||
(define hundredth
|
|
||||||
(match (quotient total 100)
|
|
||||||
(0 1)
|
|
||||||
(x x)))
|
|
||||||
|
|
||||||
(define-values (done label)
|
(define-values (done label)
|
||||||
(if (< (indexer-progress-received-objects progress) total)
|
(if (< (indexer-progress-received-objects progress) total)
|
||||||
(values (indexer-progress-received-objects progress)
|
(values (indexer-progress-received-objects progress)
|
||||||
|
@ -156,14 +152,22 @@ (define-values (done label)
|
||||||
(define %
|
(define %
|
||||||
(* 100. (/ done total)))
|
(* 100. (/ done total)))
|
||||||
|
|
||||||
(when (and (< % 100) (zero? (modulo done hundredth)))
|
;; TODO: Both should be handled & exposed by the PROGRESS-BAR API instead.
|
||||||
|
(define width
|
||||||
|
(max (- (current-terminal-columns)
|
||||||
|
(string-length label) 7)
|
||||||
|
3))
|
||||||
|
|
||||||
|
(define grain
|
||||||
|
(match (quotient total (max 100 (* 8 width))) ; assume 1/8 glyph resolution
|
||||||
|
(0 1)
|
||||||
|
(x x)))
|
||||||
|
|
||||||
|
(when (and (< % 100) (zero? (modulo done grain)))
|
||||||
(erase-current-line (current-error-port))
|
(erase-current-line (current-error-port))
|
||||||
(let ((width (max (- (current-terminal-columns)
|
(format (current-error-port) "~a ~3,d% ~a"
|
||||||
(string-length label) 7)
|
|
||||||
3)))
|
|
||||||
(format (current-error-port) "~a ~3,d% ~a"
|
|
||||||
label (inexact->exact (round %))
|
label (inexact->exact (round %))
|
||||||
(progress-bar % width)))
|
(progress-bar % width))
|
||||||
(force-output (current-error-port)))
|
(force-output (current-error-port)))
|
||||||
|
|
||||||
(when (= % 100.)
|
(when (= % 100.)
|
||||||
|
|
Loading…
Reference in a new issue