Actual ANSI color and bold attribute generation.
This commit is contained in:
parent
d161233a8a
commit
f90041a0ff
1 changed files with 20 additions and 1 deletions
21
ansi.scm
21
ansi.scm
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
(import scheme
|
(import scheme
|
||||||
(chicken base)
|
(chicken base)
|
||||||
|
(chicken string)
|
||||||
testing)
|
testing)
|
||||||
|
|
||||||
;; Only basic ANSI colors and bold attribute support.
|
;; Only basic ANSI colors and bold attribute support.
|
||||||
|
@ -59,12 +60,30 @@
|
||||||
(loop (cdr lst)
|
(loop (cdr lst)
|
||||||
res)))))
|
res)))))
|
||||||
|
|
||||||
|
;; Returns ANSI sequence changing color and/or bold attribute.
|
||||||
(define (ansi . args)
|
(define (ansi . args)
|
||||||
"")
|
(let ((argsl
|
||||||
|
(map
|
||||||
|
(lambda (key-color)
|
||||||
|
(number->string (cdr key-color)))
|
||||||
|
(filter
|
||||||
|
identity
|
||||||
|
(map (lambda (arg) (assq arg colors)) args)))))
|
||||||
|
(if (null? argsl)
|
||||||
|
""
|
||||||
|
(string-append "\x1b["
|
||||||
|
(string-intersperse argsl ";")
|
||||||
|
"m"))))
|
||||||
|
|
||||||
|
;; Performs ANSI module self-tests.
|
||||||
(define (ansi-tests!)
|
(define (ansi-tests!)
|
||||||
(run-tests
|
(run-tests
|
||||||
ansi
|
ansi
|
||||||
|
(test-equal? filter (filter odd? '(1 2 3 4)) '(1 3))
|
||||||
|
(test-equal? filter (filter odd? '(2 4)) '())
|
||||||
|
(test-equal? ansi (ansi #:red) "\x1b[31m")
|
||||||
|
(test-equal? ansi (ansi #:nonsense) "")
|
||||||
|
(test-equal? ansi (ansi #:default) "\x1b[0m")
|
||||||
))
|
))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue