colors: Add 'colorize-full-matches'.
* guix/colors.scm (colorize-full-matches): New procedure.
This commit is contained in:
parent
00dcfb261b
commit
d08e4d52a3
1 changed files with 22 additions and 0 deletions
|
@ -36,6 +36,7 @@
|
||||||
highlight/warn
|
highlight/warn
|
||||||
dim
|
dim
|
||||||
|
|
||||||
|
colorize-full-matches
|
||||||
color-rules
|
color-rules
|
||||||
color-output?
|
color-output?
|
||||||
isatty?*
|
isatty?*
|
||||||
|
@ -153,6 +154,27 @@ that subsequent output will not have any colors in effect."
|
||||||
(define highlight/warn (coloring-procedure (color BOLD MAGENTA)))
|
(define highlight/warn (coloring-procedure (color BOLD MAGENTA)))
|
||||||
(define dim (coloring-procedure (color DARK)))
|
(define dim (coloring-procedure (color DARK)))
|
||||||
|
|
||||||
|
(define (colorize-full-matches rules)
|
||||||
|
"Return a procedure that, given a string, colorizes according to RULES.
|
||||||
|
RULES must be a list of regexp/color pairs; the whole match of a regexp is
|
||||||
|
colorized with the corresponding color."
|
||||||
|
(define proc
|
||||||
|
(lambda (str)
|
||||||
|
(if (string-index str #\nul)
|
||||||
|
str
|
||||||
|
(let loop ((rules rules))
|
||||||
|
(match rules
|
||||||
|
(()
|
||||||
|
str)
|
||||||
|
(((regexp . color) . rest)
|
||||||
|
(match (regexp-exec regexp str)
|
||||||
|
(#f (loop rest))
|
||||||
|
(m (string-append (proc (match:prefix m))
|
||||||
|
(colorize-string (match:substring m)
|
||||||
|
color)
|
||||||
|
(proc (match:suffix m)))))))))))
|
||||||
|
proc)
|
||||||
|
|
||||||
(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:
|
||||||
|
|
Reference in a new issue