From 276d896c282a9c692507f20dac25569149d31c9f Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 6 Nov 2023 15:06:40 +0000 Subject: Use (term ansi-color) for colors. * build-aux/test-driver.scm (color): Use colorize-string from (term ansi-color). * ccwl/ui.scm (report-formatted-message, source-in-context, report-ccwl-violation): Use colorize-string from (term ansi-color). (color, bold, red, magenta): Delete functions. --- ccwl/ui.scm | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'ccwl') diff --git a/ccwl/ui.scm b/ccwl/ui.scm index 60fb1e7..c499041 100644 --- a/ccwl/ui.scm +++ b/ccwl/ui.scm @@ -20,6 +20,7 @@ #:use-module (rnrs io ports) #:use-module (srfi srfi-26) #:use-module (srfi srfi-28) + #:use-module (term ansi-color) #:use-module (ccwl conditions) #:export (report-formatted-message report-ccwl-violation)) @@ -29,7 +30,7 @@ user." (display (apply format (formatted-message-format exception) - (map (compose bold magenta) + (map (cut colorize-string <> 'BOLD 'MAGENTA) (formatted-message-arguments exception))) (current-error-port)) (newline (current-error-port))) @@ -66,15 +67,6 @@ whitespace intact." (get-string-n port (- (read-end port) (port-position port)))) -(define (color code str) - "Wrap STR in ANSI escape CODE, thus rendering it in color in a -terminal." - (format "~a[~am~a~a[0m" #\esc code str #\esc)) - -(define bold (cut color 1 <>)) -(define red (cut color 31 <>)) -(define magenta (cut color 35 <>)) - (define (count-lines str) "Count the number of lines in STR." (call-with-input-string str @@ -146,7 +138,7 @@ red. LINE-NUMBER and COLUMN-NUMBER are zero-based." ;; Display syntax x in red. Color each line separately to ;; help line oriented functions like ;; `display-with-line-numbers'. - (display (string-join (map (compose bold red) + (display (string-join (map (cut colorize-string <> 'BOLD 'RED) (string-split (read-sexp-string port) #\newline)) "\n") @@ -163,9 +155,10 @@ red. LINE-NUMBER and COLUMN-NUMBER are zero-based." (let ((file (ccwl-violation-file exception)) (line (ccwl-violation-line exception)) (column (ccwl-violation-column exception))) - (display (bold (format "~a:~a:~a: " file (1+ line) column)) + (display (colorize-string (format "~a:~a:~a: " file (1+ line) column) + 'BOLD) (current-error-port)) - (display (bold (red "error:")) + (display (colorize-string "error:" 'BOLD 'RED) (current-error-port)) (display " " (current-error-port)) (when (formatted-message? exception) -- cgit v1.2.3