Implement nice ansi formatting wrapper.
This commit is contained in:
parent
802a642965
commit
cf86180222
1 changed files with 31 additions and 0 deletions
31
ansi.scm
31
ansi.scm
|
@ -38,6 +38,7 @@
|
||||||
a:highlight
|
a:highlight
|
||||||
ansi-string-length
|
ansi-string-length
|
||||||
ansi-paragraph-format
|
ansi-paragraph-format
|
||||||
|
ansi-string
|
||||||
ansi-tests!
|
ansi-tests!
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@
|
||||||
(chicken base)
|
(chicken base)
|
||||||
(chicken string)
|
(chicken string)
|
||||||
(chicken irregex)
|
(chicken irregex)
|
||||||
|
(chicken keyword)
|
||||||
testing
|
testing
|
||||||
utils)
|
utils)
|
||||||
|
|
||||||
|
@ -135,6 +137,29 @@
|
||||||
word)
|
word)
|
||||||
(cdr res))))))))
|
(cdr res))))))))
|
||||||
|
|
||||||
|
;; Returns a concatenation of all ANSI styles specified by this
|
||||||
|
;; module
|
||||||
|
(define (ansi-string . args)
|
||||||
|
(apply string-append
|
||||||
|
(let loop ((args args)
|
||||||
|
(kws '())
|
||||||
|
(res '()))
|
||||||
|
(if (null? args)
|
||||||
|
(let ((rres (if (null? kws)
|
||||||
|
res
|
||||||
|
(cons (apply ansi kws) res))))
|
||||||
|
(reverse rres))
|
||||||
|
(let ((arg (car args)))
|
||||||
|
(loop (cdr args)
|
||||||
|
(if (keyword? arg)
|
||||||
|
(cons arg kws)
|
||||||
|
'())
|
||||||
|
(if (keyword? arg)
|
||||||
|
res
|
||||||
|
(if (null? kws)
|
||||||
|
(cons arg res)
|
||||||
|
(cons arg (cons (apply ansi (reverse kws)) res))))))))))
|
||||||
|
|
||||||
;; Performs ANSI module self-tests.
|
;; Performs ANSI module self-tests.
|
||||||
(define (ansi-tests!)
|
(define (ansi-tests!)
|
||||||
(run-tests
|
(run-tests
|
||||||
|
@ -154,6 +179,12 @@
|
||||||
(test-equal? ansi-paragraph-format
|
(test-equal? ansi-paragraph-format
|
||||||
(ansi-paragraph-format "Formats string as paragraph of maximum given width" 20)
|
(ansi-paragraph-format "Formats string as paragraph of maximum given width" 20)
|
||||||
"Formats string as\nparagraph of maximum\ngiven width")
|
"Formats string as\nparagraph of maximum\ngiven width")
|
||||||
|
(test-equal? ansi-string
|
||||||
|
(ansi-string "Hello" #:bold "World")
|
||||||
|
"Hello\x1b[1mWorld")
|
||||||
|
(test-equal? ansi-string
|
||||||
|
(ansi-string "Hello" #:bold #:red "World")
|
||||||
|
"Hello\x1b[1;31mWorld")
|
||||||
))
|
))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue