summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2023-11-06 15:06:40 +0000
committerArun Isaac2023-11-06 15:06:40 +0000
commit276d896c282a9c692507f20dac25569149d31c9f (patch)
tree4a69f7c2045012f16ffc61ed52738bfb159857ba
parentd07493fbbccbf14b0230a77c992e52e048089d54 (diff)
downloadccwl-276d896c282a9c692507f20dac25569149d31c9f.tar.gz
ccwl-276d896c282a9c692507f20dac25569149d31c9f.tar.lz
ccwl-276d896c282a9c692507f20dac25569149d31c9f.zip
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.
-rw-r--r--build-aux/test-driver.scm13
-rw-r--r--ccwl/ui.scm19
2 files changed, 13 insertions, 19 deletions
diff --git a/build-aux/test-driver.scm b/build-aux/test-driver.scm
index 8fc5236..adac481 100644
--- a/build-aux/test-driver.scm
+++ b/build-aux/test-driver.scm
@@ -28,16 +28,17 @@
(use-modules (ice-9 format)
(ice-9 match)
(srfi srfi-26)
- (srfi srfi-64))
+ (srfi srfi-64)
+ (term ansi-color))
-(define (color code str color?)
+(define (color color-symbol str color?)
(if color?
- (format #f "~a[~am~a~a[0m" #\esc code str #\esc)
+ (colorize-string str color-symbol)
str))
-(define red (cut color 31 <> <>))
-(define green (cut color 32 <> <>))
-(define magenta (cut color 35 <> <>))
+(define red (cut color 'RED <> <>))
+(define green (cut color 'GREEN <> <>))
+(define magenta (cut color 'MAGENTA <> <>))
(define (my-gnu-runner color?)
(let ((runner (test-runner-null)))
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)