[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
05/07: progress: Add 'progress-reporter/bar'.
From: |
Ludovic Courtès |
Subject: |
05/07: progress: Add 'progress-reporter/bar'. |
Date: |
Wed, 22 Nov 2017 09:02:46 -0500 (EST) |
civodul pushed a commit to branch wip-pull-reload
in repository guix.
commit 1783be7b1a47cb7d79fa04b6599ff67d726d1668
Author: Ludovic Courtès <address@hidden>
Date: Wed Nov 22 14:39:00 2017 +0100
progress: Add 'progress-reporter/bar'.
* guix/progress.scm (progress-reporter/bar): New procedure.
---
guix/progress.scm | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/guix/progress.scm b/guix/progress.scm
index ba79442..3b760c6 100644
--- a/guix/progress.scm
+++ b/guix/progress.scm
@@ -1,6 +1,7 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Sou Bunnbu <address@hidden>
;;; Copyright © 2015 Steve Sprang <address@hidden>
+;;; Copyright © 2017 Ludovic Courtès <address@hidden>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -32,6 +33,7 @@
progress-reporter/silent
progress-reporter/file
+ progress-reporter/bar
byte-count->string
current-terminal-columns
@@ -212,6 +214,36 @@ ABBREVIATION used to shorten FILE for display."
;; Don't miss the last report.
(stop render))))
+(define* (progress-reporter/bar total
+ #:optional
+ (prefix "")
+ (port (current-error-port)))
+ "Return a reporter that shows a progress bar every time one of the TOTAL
+tasks is performed. Write PREFIX at the beginning of the line."
+ (define done 0)
+
+ (define (report-progress)
+ (set! done (+ 1 done))
+ (unless (> done total)
+ (let* ((ratio (* 100. (/ done total))))
+ (erase-in-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))))
+
+ (progress-reporter
+ (start (lambda ()
+ (set! done 0)))
+ (report report-progress)
+ (stop (lambda ()
+ (erase-in-line port)
+ (force-output port)))))
+
;; TODO: replace '(@ (guix build utils) dump-port))'.
(define* (dump-port* in out
#:key (buffer-size 16384)
- branch wip-pull-reload created (now 62dbd6e), Ludovic Courtès, 2017/11/22
- 05/07: progress: Add 'progress-reporter/bar'.,
Ludovic Courtès <=
- 07/07: self: Add a progress report while loading modules., Ludovic Courtès, 2017/11/22
- 04/07: progress: 'progress-bar' accounts for brackets., Ludovic Courtès, 2017/11/22
- 03/07: progress: Factorize erase-in-line., Ludovic Courtès, 2017/11/22
- 02/07: DRAFT pull: Reload modules before doing anything else., Ludovic Courtès, 2017/11/22
- 06/07: weather: Use (guix progress) for progress report., Ludovic Courtès, 2017/11/22
- 01/07: gnu: Fix ambiguous 'zip' reference., Ludovic Courtès, 2017/11/22