summaryrefslogtreecommitdiff
path: root/gnu/installer/utils.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2022-12-09 17:47:08 +0100
committerLudovic Courtès <ludo@gnu.org>2022-12-09 17:49:22 +0100
commit591af24ade1021d91a3e7c62fcc7a8c90f00d4bb (patch)
tree5bb5df57945451751d176a50a7d2c042d621eef4 /gnu/installer/utils.scm
parent556520a33c8a62fc80ac9ab925f86f08986d138b (diff)
installer: Print progress bars and such as soon as \r is read.
Fixes <https://issues.guix.gnu.org/59922>. Previously progress bars and related things would be buffered by 'run-external-command-with-line-hooks' until \n is read. * gnu/installer/utils.scm (run-external-command-with-line-hooks): Use 'read-delimited' rather than 'get-line'. Pass 'concat as the last argument. (%display-line-hook): Remove. (run-command): Use 'display' instead of '%display-line-hook'. (%syslog-line-hook): Add "\n" when LINE doesn't end in \n. (%installer-log-line-hook): Do not add an extra newline. (installer-log-line): Add an extra newline.
Diffstat (limited to 'gnu/installer/utils.scm')
-rw-r--r--gnu/installer/utils.scm26
1 files changed, 14 insertions, 12 deletions
diff --git a/gnu/installer/utils.scm b/gnu/installer/utils.scm
index 061493e6a79..6838410166d 100644
--- a/gnu/installer/utils.scm
+++ b/gnu/installer/utils.scm
@@ -1,6 +1,6 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com> 2;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
3;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org> 3;;; Copyright © 2019, 2020, 2022 Ludovic Courtès <ludo@gnu.org>
4;;; 4;;;
5;;; This file is part of GNU Guix. 5;;; This file is part of GNU Guix.
6;;; 6;;;
@@ -159,7 +159,9 @@ COMMAND will be run in a pseudoterminal. Returns the integer status value of
159the child process as returned by waitpid." 159the child process as returned by waitpid."
160 (define (handler input) 160 (define (handler input)
161 (and 161 (and
162 (and=> (get-line input) 162 ;; Lines for progress bars etc. end in \r; treat is as a line ending so
163 ;; those lines are printed right away.
164 (and=> (read-delimited "\r\n" input 'concat)
163 (lambda (line) 165 (lambda (line)
164 (if (eof-object? line) 166 (if (eof-object? line)
165 #f 167 #f
@@ -186,7 +188,7 @@ in a pseudoterminal."
186 188
187 (installer-log-line "running command ~s" command) 189 (installer-log-line "running command ~s" command)
188 (define result (run-external-command-with-line-hooks 190 (define result (run-external-command-with-line-hooks
189 (list %display-line-hook) command 191 (list display) command
190 #:tty? tty?)) 192 #:tty? tty?))
191 (define exit-val (status:exit-val result)) 193 (define exit-val (status:exit-val result))
192 (define term-sig (status:term-sig result)) 194 (define term-sig (status:term-sig result))
@@ -264,7 +266,10 @@ values."
264 (or port (%make-void-port "w"))))) 266 (or port (%make-void-port "w")))))
265 267
266(define (%syslog-line-hook line) 268(define (%syslog-line-hook line)
267 (format (syslog-port) "installer[~d]: ~a~%" (getpid) line)) 269 (let ((line (if (string-suffix? "\r" line)
270 (string-append (string-drop-right line 1) "\n")
271 line)))
272 (format (syslog-port) "installer[~d]: ~a" (getpid) line)))
268 273
269(define-syntax syslog 274(define-syntax syslog
270 (lambda (s) 275 (lambda (s)
@@ -293,11 +298,7 @@ values."
293 port))) 298 port)))
294 299
295(define (%installer-log-line-hook line) 300(define (%installer-log-line-hook line)
296 (format (installer-log-port) "~a~%" line)) 301 (display line (installer-log-port)))
297
298(define (%display-line-hook line)
299 (display line)
300 (newline))
301 302
302(define %default-installer-line-hooks 303(define %default-installer-line-hooks
303 (list %syslog-line-hook 304 (list %syslog-line-hook
@@ -309,9 +310,10 @@ values."
309 (syntax-case s () 310 (syntax-case s ()
310 ((_ fmt args ...) 311 ((_ fmt args ...)
311 (string? (syntax->datum #'fmt)) 312 (string? (syntax->datum #'fmt))
312 #'(let ((formatted (format #f fmt args ...))) 313 (with-syntax ((fmt (string-append (syntax->datum #'fmt) "\n")))
313 (for-each (lambda (f) (f formatted)) 314 #'(let ((formatted (format #f fmt args ...)))
314 %default-installer-line-hooks)))))) 315 (for-each (lambda (f) (f formatted))
316 %default-installer-line-hooks)))))))
315 317
316 318
317;;; 319;;;