summaryrefslogtreecommitdiff
path: root/guix/ui.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-04-11 16:57:38 +0200
committerLudovic Courtès <ludo@gnu.org>2019-04-11 18:18:13 +0200
commit2569ef9dab4f796a75b8cdddd57d3be37b142036 (patch)
tree34b527c015552944c1a6fd1bb855dd45e36084bc /guix/ui.scm
parentc1df77e215b6e69dccbe781307836a3b962c5968 (diff)
downloadpatches-2569ef9dab4f796a75b8cdddd57d3be37b142036.tar
patches-2569ef9dab4f796a75b8cdddd57d3be37b142036.tar.gz
colors: Introduce a disjoint type and pre-compute ANSI escapes.
* guix/colors.scm (color-table, color): Remove. (<color>): New record type. (print-color): New procedure. (define-color-table, color): New macros. (color-codes->ansi): New procedure. (%reset): New variable. (colorize-string): Rewrite accordingly. (color-rules): Adjust accordingly. * guix/status.scm (print-build-event): Adjust to new 'colorize-string' interface. * guix/ui.scm (%highlight-argument): Likewise. (%warning-colors, %info-colors, %error-colors, %hint-colors) (%highlight-colors): Remove. (%warning-color, %info-color, %error-color, %hint-color) (%highlight-color): New variables.
Diffstat (limited to 'guix/ui.scm')
-rw-r--r--guix/ui.scm26
1 files changed, 13 insertions, 13 deletions
diff --git a/guix/ui.scm b/guix/ui.scm
index c3612d92b4..2481a1b78b 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -158,7 +158,7 @@ is a trivial format string."
(define highlight
(if (color-output? port)
(lambda (str)
- (apply colorize-string str %highlight-colors))
+ (colorize-string str %highlight-color))
identity))
(cond ((string? arg)
@@ -206,9 +206,9 @@ messages."
;; XXX: This doesn't work well for right-to-left languages.
;; TRANSLATORS: The goal is to emit "warning:" followed by a short phrase;
;; "~a" is a placeholder for that phrase.
-(define-diagnostic warning (G_ "warning: ") %warning-colors) ;emit a warning
-(define-diagnostic info (G_ "") %info-colors)
-(define-diagnostic report-error (G_ "error: ") %error-colors)
+(define-diagnostic warning (G_ "warning: ") %warning-color) ;emit a warning
+(define-diagnostic info (G_ "") %info-color)
+(define-diagnostic report-error (G_ "error: ") %error-color)
(define-syntax-rule (leave args ...)
"Emit an error message and exit."
@@ -216,27 +216,27 @@ messages."
(report-error args ...)
(exit 1)))
-(define %warning-colors '(BOLD MAGENTA))
-(define %info-colors '(BOLD))
-(define %error-colors '(BOLD RED))
-(define %hint-colors '(BOLD CYAN))
-(define %highlight-colors '(BOLD))
+(define %warning-color (color BOLD MAGENTA))
+(define %info-color (color BOLD))
+(define %error-color (color BOLD RED))
+(define %hint-color (color BOLD CYAN))
+(define %highlight-color (color BOLD))
(define* (print-diagnostic-prefix prefix #:optional location
- #:key (colors '()))
+ #:key (colors (color)))
"Print PREFIX as a diagnostic line prefix."
(define color?
(color-output? (guix-warning-port)))
(define location-color
(if color?
- (cut colorize-string <> 'BOLD)
+ (cut colorize-string <> (color BOLD))
identity))
(define prefix-color
(if color?
(lambda (prefix)
- (apply colorize-string prefix colors))
+ (colorize-string prefix colors))
identity))
(let ((prefix (if (string-null? prefix)
@@ -404,7 +404,7 @@ PORT."
(define colorize
(if (color-output? port)
(lambda (str)
- (apply colorize-string str %hint-colors))
+ (colorize-string str %hint-color))
identity))
(display (colorize (G_ "hint: ")) port)