clone url: git://git.m455.casa/sp
src/ansi.scm
1 | (define escape-code "\033[") |
2 |
|
3 | (define normal 0) |
4 | (define bold 1) |
5 |
|
6 | (define colors |
7 | '((black 30) |
8 | (red 31) |
9 | (green 32) |
10 | (yellow 33) |
11 | (blue 34) |
12 | (magenta 35) |
13 | (cyan 36) |
14 | (white 37) |
15 | (default 39))) |
16 |
|
17 | (define (colors-ref key) |
18 | (get colors key)) |
19 |
|
20 | (define (escape x) |
21 | (let ((y (if (pair? x) |
22 | (string-intersperse (map number->string x) ";") |
23 | (number->string x)))) |
24 | (string-append escape-code y "m"))) |
25 |
|
26 | (define (paint str color-key) |
27 | (string-append (escape (list bold (colors-ref color-key))) |
28 | str |
29 | (escape (list normal (colors-ref 'default))))) |