Debian Codegraph @

lib/srfi-159/color.scm

raw
1 ;; color.scm -- colored output
2 ;; Copyright (c) 2006-2017 Alex Shinn. All rights reserved.
3 ;; BSD-style license: http://synthcode.com/license.txt
4
5 (define (color->ansi x)
6 (case x
7 ((bold) "1")
8 ((dark) "2")
9 ((underline) "4")
10 ((black) "30")
11 ((red) "31")
12 ((green) "32")
13 ((yellow) "33")
14 ((blue) "34")
15 ((magenta) "35")
16 ((cyan) "36")
17 ((white) "37")
18 (else "0")))
19
20 (define (ansi-escape color)
21 (string-append (string (integer->char 27)) "[" (color->ansi color) "m"))
22
23 (define (colored new-color . args)
24 (fn (color)
25 (with ((color new-color))
26 (each (ansi-escape new-color)
27 (each-in-list args)
28 (if (or (memq new-color '(bold underline))
29 (memq color '(bold underline)))
30 (ansi-escape 'reset)
31 nothing)
32 (ansi-escape color)))))
33
34 (define (as-red . args) (colored 'red (each-in-list args)))
35 (define (as-blue . args) (colored 'blue (each-in-list args)))
36 (define (as-green . args) (colored 'green (each-in-list args)))
37 (define (as-cyan . args) (colored 'cyan (each-in-list args)))
38 (define (as-yellow . args) (colored 'yellow (each-in-list args)))
39 (define (as-magenta . args) (colored 'magenta (each-in-list args)))
40 (define (as-white . args) (colored 'white (each-in-list args)))
41 (define (as-black . args) (colored 'black (each-in-list args)))
42 (define (as-bold . args) (colored 'bold (each-in-list args)))
43 (define (as-underline . args) (colored 'underline (each-in-list args)))