Hi Ricardo,
> Another note about style: I think it would be better to use
> “alist->hash-table” instead of “make-hash-table” followed by repeated
> modifications to the hash table with “hashq-set!”.  We prefer to avoid
> mutation of values when possible.

I have made all necessary modifications. Can please review it once.
> Regarding copyright headers: please make sure to also add a copyright
> line for yourself and a copyright line from the file of guile-colorize
> to “(guix ui)”.
>
> When you’re done with these changes, please make a local commit and send
> the output of “git format-patch -1”.


I will proceed further once it is reviewed. :)

Thanks!!
---
Sahithi
(define-module (term ansi-color)
     #:export  (color
                colorize-string)
     #:use-module (srfi srfi-1)   ; for 'remove'
     #:use-module (srfi srfi-13)) ; for 'string-join' 

(define ansi-color-tables
  `((CLEAR       .   "0")
    (RESET       .   "0")
    (BOLD        .   "1")
    (DARK        .   "2")
    (UNDERLINE   .   "4")
    (UNDERSCORE  .   "4")
    (BLINK       .   "5")
    (REVERSE     .   "6")
    (CONCEALED   .   "8")
    (BLACK       .  "30")
    (RED         .  "31")
    (GREEN       .  "32")
    (YELLOW      .  "33")
    (BLUE        .  "34")
    (MAGENTA     .  "35")
    (CYAN        .  "36")
    (WHITE       .  "37")
    (ON-BLACK    .  "40")
    (ON-RED      .  "41")
    (ON-GREEN    .  "42")
    (ON-YELLOW   .  "43")
    (ON-BLUE     .  "44")
    (ON-MAGENTA  .  "45")
    (ON-CYAN     .  "46")
    (ON-WHITE    .  "47")))

(define (color . lst)
  (let ((color-list 
         (remove not 
                 (map (lambda (color) (assq-ref ansi-color-tables color))
                      lst))))
    (if (null? color-list)
        ""
        (string-append 
         (string #\esc #\[)
         (string-join color-list ";" 'infix)
         "m"))))
  
(define (colorize-string str . color-list)
  (string-append
   (apply color color-list)
   str
   (color 'RESET)))

(display (colorize-string "Hello!\n" 'RED 'BOLD 'ON-BLUE))

(for-each display
          (list (color 'RED 'BOLD 'ON-BLUE)
                "Hello!"
                 (color 'RESET)))

Reply via email to