[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
03/09: progress: Add 'progress-reporter/bar'.
From: |
Ludovic Courtès |
Subject: |
03/09: progress: Add 'progress-reporter/bar'. |
Date: |
Fri, 1 Dec 2017 10:00:38 -0500 (EST) |
civodul pushed a commit to branch master
in repository guix.
commit 4cdb27af48c83b7d036c4d8cccb792a51d766790
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 | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/guix/progress.scm b/guix/progress.scm
index ba79442..1ee7ec3 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,39 @@ 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)
+ (unless (string-null? prefix)
+ (display prefix port)
+ (newline port))
+ (force-output port)))))
+
;; TODO: replace '(@ (guix build utils) dump-port))'.
(define* (dump-port* in out
#:key (buffer-size 16384)
- branch master updated (e695d79 -> c7ffbfe), Ludovic Courtès, 2017/12/01
- 01/09: progress: Factorize erase-in-line., Ludovic Courtès, 2017/12/01
- 02/09: progress: 'progress-bar' accounts for brackets., Ludovic Courtès, 2017/12/01
- 03/09: progress: Add 'progress-reporter/bar'.,
Ludovic Courtès <=
- 05/09: guix system: Simplify closure copy., Ludovic Courtès, 2017/12/01
- 09/09: gnu: guile: Add version 2.2.3., Ludovic Courtès, 2017/12/01
- 04/09: weather: Use (guix progress) for progress report., Ludovic Courtès, 2017/12/01
- 08/09: gnu: gnome-default-applications: Add Evince for PDF and PS., Ludovic Courtès, 2017/12/01
- 07/09: services: xorg: Add 'font-misc-misc' to the default font set., Ludovic Courtès, 2017/12/01
- 06/09: guix system: 'init' displays a progress bar while copying., Ludovic Courtès, 2017/12/01