Hi Ricardo,
> As a first change, could you please add the relevant parts of “(ice-9
> colorized)” to a module in Guix? We probably don’t want to depend on
> having users install this module separately. We also don’t need all of
> it. Please prepare a patch that adds only the relevant parts to “(guix
> ui)” and update the copyright headers.
I think small changes to the attached file will serve the purpose.
But when I tried executing the file, that resulted with a error unbound
variable : colorize string
I am not sure where I went wrong, can you please explain.
--Sahithi
(display (colorize-string "Hello!\n" 'RED 'BOLD 'ON-BLUE))
(for-each display
(list (color 'RED 'BOLD 'ON-BLUE)
"Hello!"
(color 'RESET)))
(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
(let ((table (make-hash-table 23)))
(hashq-set! table 'CLEAR "0")
(hashq-set! table 'RESET "0")
(hashq-set! table 'BOLD "1")
(hashq-set! table 'DARK "2")
(hashq-set! table 'UNDERLINE "4")
(hashq-set! table 'UNDERSCORE "4")
(hashq-set! table 'BLINK "5")
(hashq-set! table 'REVERSE "6")
(hashq-set! table 'CONCEALED "8")
(hashq-set! table 'BLACK "30")
(hashq-set! table 'RED "31")
(hashq-set! table 'GREEN "32")
(hashq-set! table 'YELLOW "33")
(hashq-set! table 'BLUE "34")
(hashq-set! table 'MAGENTA "35")
(hashq-set! table 'CYAN "36")
(hashq-set! table 'WHITE "37")
(hashq-set! table 'ON-BLACK "40")
(hashq-set! table 'ON-RED "41")
(hashq-set! table 'ON-GREEN "42")
(hashq-set! table 'ON-YELLOW "43")
(hashq-set! table 'ON-BLUE "44")
(hashq-set! table 'ON-MAGENTA "45")
(hashq-set! table 'ON-CYAN "46")
(hashq-set! table 'ON-WHITE "47")
table))
(define (color . lst)
(let ((color-list
(remove not
(map (lambda (color) (hashq-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)))