Thanks juli, updated style to be fucking awesome
This commit is contained in:
parent
b26aedbe87
commit
3460f892b3
|
@ -1,6 +1,8 @@
|
|||
(define-module (termenv style)
|
||||
#:use-module (termenv)
|
||||
#:use-module (termenv unix)
|
||||
#:use-module (ice-9 match)
|
||||
#:use-module (srfi srfi-26)
|
||||
#:use-module (srfi srfi-9 gnu)
|
||||
#:export (make-style
|
||||
styled
|
||||
|
@ -34,6 +36,17 @@
|
|||
(string style-string set-style-string)
|
||||
(sequences style-sequences set-style-sequences))
|
||||
|
||||
;; Unsure if there's a simpler way to do set-record-type-printer! semantics on just a list?
|
||||
(define-immutable-record-type <stylelist>
|
||||
(make-stylelist list)
|
||||
stylelist?
|
||||
(list stylelist-list set-stylelist-list))
|
||||
|
||||
(define (stylelist-styled stylelist port)
|
||||
(map (cut styled <> port) (stylelist-list stylelist)))
|
||||
|
||||
(set-record-type-printer! <stylelist> stylelist-styled)
|
||||
|
||||
(define (make-style str)
|
||||
(_make-style 'ansi str '()))
|
||||
|
||||
|
@ -47,22 +60,23 @@
|
|||
(let ((seq (string-join (style-sequences style) ";")))
|
||||
(if (equal? seq "")
|
||||
(just-str)
|
||||
(format port "~a~am~a~am" %CSI seq str (string-append %CSI %RESET)))))))
|
||||
(format port "~a~am~a~a~am" %CSI seq str %CSI %RESET))))))
|
||||
|
||||
(set-record-type-printer! <style> styled)
|
||||
|
||||
(define (cons-seq style-or-string sequence)
|
||||
(define style
|
||||
(if (string? style-or-string)
|
||||
(make-style style-or-string)
|
||||
style-or-string))
|
||||
(set-style-sequences style (cons* sequence (style-sequences style))))
|
||||
(define (cons-seq stylish sequence)
|
||||
(match stylish
|
||||
((style) (cons-seq style sequence))
|
||||
((? list? l) (make-stylelist (map (cut cons-seq <> sequence) l)))
|
||||
((? style? style) (set-style-sequences style (cons* sequence (style-sequences style))))
|
||||
((? stylelist? stylelist) (map (cut cons-seq <> sequence) (stylelist-list stylelist)))
|
||||
((? string? str) (_make-style 'ansi str (list sequence)))))
|
||||
|
||||
(define (bold s) (cons-seq s %BOLD))
|
||||
(define (faint s) (cons-seq s %FAINT))
|
||||
(define (italic s) (cons-seq s %ITALIC))
|
||||
(define (underline s) (cons-seq s %UNDERLINE))
|
||||
(define (overline s) (cons-seq s %OVERLINE))
|
||||
(define (blink s) (cons-seq s %BLINK))
|
||||
(define (reverse s) (cons-seq s %REVERSE))
|
||||
(define (cross-out s) (cons-seq s %CROSS-OUT))
|
||||
(define (bold . s) (cons-seq s %BOLD))
|
||||
(define (faint . s) (cons-seq s %FAINT))
|
||||
(define (italic . s) (cons-seq s %ITALIC))
|
||||
(define (underline . s) (cons-seq s %UNDERLINE))
|
||||
(define (overline . s) (cons-seq s %OVERLINE))
|
||||
(define (blink . s) (cons-seq s %BLINK))
|
||||
(define (reverse . s) (cons-seq s %REVERSE))
|
||||
(define (cross-out . s) (cons-seq s %CROSS-OUT))
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
"\x1b[1;3mneato\x1b[0m"
|
||||
(format #t "~a" (bold (italic "neato"))))
|
||||
|
||||
(verify-output
|
||||
"\x1b[1mpretty \x1b[0m\x1b[1;3mneato\x1b[0m"
|
||||
(format #t "~a" (bold "pretty " (italic "neato"))))
|
||||
|
||||
(verify-output
|
||||
"this is \x1b[4mimportant\x1b[0m!"
|
||||
(format #t "this is ~a!" (underline "important")))
|
||||
|
|
Loading…
Reference in New Issue