From ab1d07107b3f701b8bcaed8eab3565dc0968f20c Mon Sep 17 00:00:00 2001 From: root Date: Tue, 5 Jun 2018 00:08:32 +0530 Subject: [PATCH] Added a soft port to (guix ui) that colorizes strings that match Regular Expressions. --- guix/ui.scm | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/guix/ui.scm b/guix/ui.scm index 80f1a4d77..3a36daadc 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -109,7 +109,8 @@ warning info guix-main - colorize-string)) + colorize-string + guix-colorful-port)) ;;; Commentary: ;;; @@ -1631,4 +1632,43 @@ be reset such that subsequent output will not have any colors in effect." str (color 'RESET))) +(define target-port (current-output-port)) + +(define (handle-string str) + (or (and=> (string-match "^(starting phase)(.*)" str) + (lambda (m) + (string-append + (colorized-display (match:substring m 1) '(BLUE)) + (colorized-display (match:substring m 2) '(GREEN))))) + + (and=> (string-match "^(phase)(.*) (succeeded)(.*)" str) + (lambda (m) + (string-append + (colorized-display (match:substring m 1) '(BLUE)) + (colorized-display (match:substring m 2) '(GREEN)) + (colorized-display (match:substring m 3) '(BLUE)) + (colorized-display (match:substring m 4) '(GREEN))))) + + (and=> (string-match "^(phase)(.*) (failed)(.*)" str) + (lambda (m) + (string-append + (colorized-display (match:substring m 1) '(BLUE)) + (colorized-display (match:substring m 2) '(GREEN)) + (colorized-display (match:substring m 3) '(BLUE)) + (colorized-display (match:substring m 4) '(GREEN))))) + + ;; Didn’t match, so return unmodified string. + str) + (display str target-port)) + +(define guix-colorful-port + (make-soft-port + (vector + (lambda (c) (write c target-port)) + handle-string + (lambda () (display "." target-port)) + (lambda () (char-upcase (read-char))) + (lambda () (display "@" target-port))) + "rw")) + ;;; ui.scm ends here -- 2.11.0