[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/01: guix: Add coloring soft port.
From: |
Ricardo Wurmus |
Subject: |
01/01: guix: Add coloring soft port. |
Date: |
Tue, 19 Jun 2018 14:45:51 -0400 (EDT) |
rekado pushed a commit to branch wip-sahithi
in repository guix.
commit 5b556e2bb44c18a96d6ebc2d878ce0589b1b7dbd
Author: Sahithi Yarlagadda <address@hidden>
Date: Sat Jun 16 13:21:42 2018 +0530
guix: Add coloring soft port.
* guix/ui.scm (handle-string): New procedures.
(colorful-build-output-port): New variable.
guix: Added colorful-build-output-port to build.scm instead of default
---
guix/scripts/build.scm | 4 +---
guix/ui.scm | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index 4dd4fbc..81ad255 100644
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -733,9 +733,7 @@ needed."
;; Set the build options before we do anything else.
(set-build-options-from-command-line store opts)
- (parameterize ((current-build-output-port (if quiet?
- (%make-void-port "w")
- (current-error-port))))
+ (parameterize ((current-build-output-port
colorful-build-output-port))
(let* ((mode (assoc-ref opts 'build-mode))
(drv (options->derivations store opts))
(urls (map (cut string-append <> "/log")
diff --git a/guix/ui.scm b/guix/ui.scm
index 80f1a4d..88e5fa6 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -109,7 +109,7 @@
warning
info
guix-main
- colorize-string))
+ colorful-build-output-port))
;;; Commentary:
;;;
@@ -1631,4 +1631,51 @@ be reset such that subsequent output will not have any
colors in effect."
str
(color 'RESET)))
+(define (handle-string str)
+ "Accepts input string(str) as argument and checks whether it matches with one
+of the regular expressions specified. Upon matching, each substring is
colorized
+with corresponding colors and the modified colored string is returned. If the
+input string fails match with the following conditionals it returns back the
+unmodified input string."
+ (let ((message (or (and=> (string-match "^(starting phase)(.*)" str)
+ (lambda (m)
+ (string-append
+ (colorize-string (match:substring m 1) 'BLUE)
+ (colorize-string (match:substring m 2) 'GREEN))))
+
+ (and=> (string-match "^(phase)(.*)(succeeded after)(.*)(seconds)" str)
+ (lambda (m)
+ (string-append
+ (colorize-string (match:substring m 1) 'BLUE)
+ (colorize-string (match:substring m 2) 'GREEN)
+ (colorize-string (match:substring m 3) 'BLUE)
+ (colorize-string (match:substring m 4) 'GREEN)
+ (colorize-string (match:substring m 5) 'BLUE))))
+
+ (and=> (string-match "^(phase)(.*)(failed after)(.*)(seconds)" str)
+ (lambda (m)
+ (string-append
+ (colorize-string (match:substring m 1) 'RED)
+ (colorize-string (match:substring m 2) 'GREEN)
+ (colorize-string (match:substring m 3) 'RED)
+ (colorize-string (match:substring m 4) 'GREEN)
+ (colorize-string (match:substring m 5) 'RED))))
+
+ ;; Didn’t match with any expression, returns back unmodified string.
+ str)))
+ (display message (current-error-port))))
+
+(define colorful-build-output-port
+ (make-soft-port
+ (vector
+ ;; procedure accepting one character for output
+ (lambda (c) (write c (current-error-port)))
+ ;; procedure accepting a string for handle-string procedure
+ handle-string
+ (lambda () (force-output (current-error-port)))
+ (const #t)
+ (lambda () (display "@" (current-error-port))))
+ "rw"))
+
+
;;; ui.scm ends here