Hi Ricardo,

I think I am done with basic changes for 4th task. File is attached. As
mentioned in IRC output is in escape code sequence when I tried in REPL.

> I am done with 2nd task out of given 4 tasks and that was included in my
> previous patch.
> I am currently working on 4th task. 
I am able to filter lines.
I am trying out  to*only* filter lines when “guix package” is used but
not when “guix build” by adding other port.


----
Thanks!!
Sahithi
(use-modules (ice-9 match)   ; need this for “match-lambda”
             (srfi srfi-1)
              (srfi srfi-26))  ; need this for “any”

(define str "phase foo failed after 100 seconds")


;; Each list item in “patterns” is a regular expression followed by a
;; number of colours.
(let ((patterns '(("^(starting phase )(.*)"
                   BLUE GREEN)
                  ("^(phase)(.*)(succeeded after)(.*)(seconds)"
                   GREEN BLUE GREEN BLUE GREEN)
                  ("^(phase)(.*)(failed after)(.*)(seconds)"
                   RED BLUE RED BLUE RED))))

   ;; See if “any” of the patterns matches, i.e. returns a string and
   ;; not just #f.  We use “match-lambda” to bind the pattern to the
   ;; variable “pattern” and the list of colours to the variable
   ;; “colors”.

   (or (any (match-lambda
             ((pattern . colors)
              ;; TODO: use string-match, match:count, match:substring,
              ;; colorize-string, and=>, etc to see if a pattern matches
              ;; and to transform the string according to “colors”.

              ;; If the pattern does not match return #f to
              ;; automatically try the next, thanks to “any”.
              
              ;;(colorize-string (match:substring (match:count (string-match pattern str))) colors)
           
              (and=> (string-match pattern str)
           (lambda (m)
              ;     (colorize-string (map match:substring m (iota (- (match:count m) 1) 1) colors)))



          ;(map (cut match:substring m <>) (iota (- (match:count m) 1) 1))))

(string-join (map (lambda (n color) (colorize-string (match:substring m n) color))  (iota (- (match:count m) 1) 1) colors))))
         
           
             ))
             patterns)
       ;; Nothing matched, so return the string without changes.
       str))

Reply via email to