colors: Add 'highlight'.
* guix/colors.scm (%highlight-color): New variable. (highlight): New procedure. * guix/ui.scm (%highlight-argument)[highlight]: Remove. (%highlight-color): Remove.
This commit is contained in:
parent
a5c72da46c
commit
c1c5d68a94
@ -30,6 +30,7 @@ (define-module (guix colors)
|
|||||||
color?
|
color?
|
||||||
|
|
||||||
colorize-string
|
colorize-string
|
||||||
|
highlight
|
||||||
color-rules
|
color-rules
|
||||||
color-output?
|
color-output?
|
||||||
isatty?*))
|
isatty?*))
|
||||||
@ -132,6 +133,15 @@ (define (color-output? port)
|
|||||||
(not (getenv "NO_COLOR"))
|
(not (getenv "NO_COLOR"))
|
||||||
(isatty?* port)))
|
(isatty?* port)))
|
||||||
|
|
||||||
|
(define %highlight-color (color BOLD))
|
||||||
|
|
||||||
|
(define* (highlight str #:optional (port (current-output-port)))
|
||||||
|
"Return STR with extra ANSI color attributes to highlight it if PORT
|
||||||
|
supports it."
|
||||||
|
(if (color-output? port)
|
||||||
|
(colorize-string str %highlight-color)
|
||||||
|
str))
|
||||||
|
|
||||||
(define (colorize-matches rules)
|
(define (colorize-matches rules)
|
||||||
"Return a procedure that, when passed a string, returns that string
|
"Return a procedure that, when passed a string, returns that string
|
||||||
colorized according to RULES. RULES must be a list of tuples like:
|
colorized according to RULES. RULES must be a list of tuples like:
|
||||||
|
11
guix/ui.scm
11
guix/ui.scm
@ -155,16 +155,10 @@ (define len
|
|||||||
|
|
||||||
(define* (%highlight-argument arg #:optional (port (guix-warning-port)))
|
(define* (%highlight-argument arg #:optional (port (guix-warning-port)))
|
||||||
"Highlight ARG, a format string argument, if PORT supports colors."
|
"Highlight ARG, a format string argument, if PORT supports colors."
|
||||||
(define highlight
|
|
||||||
(if (color-output? port)
|
|
||||||
(lambda (str)
|
|
||||||
(colorize-string str %highlight-color))
|
|
||||||
identity))
|
|
||||||
|
|
||||||
(cond ((string? arg)
|
(cond ((string? arg)
|
||||||
(highlight arg))
|
(highlight arg port))
|
||||||
((symbol? arg)
|
((symbol? arg)
|
||||||
(highlight (symbol->string arg)))
|
(highlight (symbol->string arg) port))
|
||||||
(else arg)))
|
(else arg)))
|
||||||
|
|
||||||
(define-syntax define-diagnostic
|
(define-syntax define-diagnostic
|
||||||
@ -220,7 +214,6 @@ (define %warning-color (color BOLD MAGENTA))
|
|||||||
(define %info-color (color BOLD))
|
(define %info-color (color BOLD))
|
||||||
(define %error-color (color BOLD RED))
|
(define %error-color (color BOLD RED))
|
||||||
(define %hint-color (color BOLD CYAN))
|
(define %hint-color (color BOLD CYAN))
|
||||||
(define %highlight-color (color BOLD))
|
|
||||||
|
|
||||||
(define* (print-diagnostic-prefix prefix #:optional location
|
(define* (print-diagnostic-prefix prefix #:optional location
|
||||||
#:key (colors (color)))
|
#:key (colors (color)))
|
||||||
|
Loading…
Reference in New Issue
Block a user