Hi Ricardo,

I have made necessary changes to ui, patch file is attached. Please
review changes and additionals to be added.

> to apply a different colour to different parts of the strings, e.g. using 
> blue for
> the name of the build phase and green for the rest.
>
> You will need to use regular expressions with sufficient match groups.
I have added above requirements to handle-string and used soft-port.

I din't added commentary lines i will be doing that.


-----
Thanks!
Sahithi.



From ab1d07107b3f701b8bcaed8eab3565dc0968f20c Mon Sep 17 00:00:00 2001
From: root <[email protected]>
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

Reply via email to