blob: 5f9fbe409a9301d5e9e461eae0c3c479e8be96f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
(define-module (vulgar color)
:export (color-if color-escape))
(define-public STR-YELLOW "\x1b[0;33m")
(define-public STR-RESET "\x1b[m")
(define-syntax-rule (color-if pred color body ...)
(let ((pred-value pred))
(format #f "~a~a~a"
(if pred-value color "")
(begin body ...)
(if pred-value STR-RESET ""))))
(define (color-escape n)
(cond ((not n) "")
((char=? #\# (string-ref n 0))
(let* ((str (string-drop n 1))
(rs (substring str 0 2))
(gs (substring str 2 4))
(bs (substring str 4 6)))
(format #f "\x1b[38;2;~a;~a;~am"
(string->number rs 16)
(string->number gs 16)
(string->number bs 16))))))
|