kekkonen/format.scm
whiteline 4baee01dc6 nyaa
2022-10-11 23:18:30 +02:00

118 lines
2.6 KiB
Scheme

(module format (terminal-code-reset terminal-code-bold terminal-code-fg-red)
(import scheme)
(import (chicken base))
(import matchable)
(define (terminal-code str)
(string-append "\u001b[" str "m"))
(define terminal-code-reset
(terminal-code "0"))
(define terminal-code-bold
(terminal-code "1"))
(define terminal-code-fg-black
(terminal-code "30"))
(define terminal-code-fg-red
(terminal-code "31"))
(define terminal-code-fg-green
(terminal-code "32"))
(define terminal-code-fg-yellow
(terminal-code "33"))
(define terminal-code-fg-blue
(terminal-code "34"))
(define terminal-code-fg-magenta
(terminal-code "35"))
(define terminal-code-fg-cyan
(terminal-code "36"))
(define terminal-code-fg-white
(terminal-code "37"))
(define terminal-code-fg-bright-black
(terminal-code "30;1"))
(define terminal-code-fg-bright-red
(terminal-code "31;1"))
(define terminal-code-fg-bright-green
(terminal-code "32;1"))
(define terminal-code-fg-bright-yellow
(terminal-code "33;1"))
(define terminal-code-fg-bright-blue
(terminal-code "34;1"))
(define terminal-code-fg-bright-magenta
(terminal-code "35;1"))
(define terminal-code-fg-bright-cyan
(terminal-code "36;1"))
(define terminal-code-fg-bright-white
(terminal-code "37;1"))
(define terminal-code-bg-black
(terminal-code "40"))
(define terminal-code-bg-red
(terminal-code "41"))
(define terminal-code-bg-green
(terminal-code "42"))
(define terminal-code-bg-yellow
(terminal-code "43"))
(define terminal-code-bg-blue
(terminal-code "44"))
(define terminal-code-bg-magenta
(terminal-code "45"))
(define terminal-code-bg-cyan
(terminal-code "46"))
(define terminal-code-bg-white
(terminal-code "47"))
(define terminal-code-bg-bright-black
(terminal-code "40;1"))
(define terminal-code-bg-bright-red
(terminal-code "41;1"))
(define terminal-code-bg-bright-green
(terminal-code "42;1"))
(define terminal-code-bg-bright-yellow
(terminal-code "43;1"))
(define terminal-code-bg-bright-blue
(terminal-code "44;1"))
(define terminal-code-bg-bright-magenta
(terminal-code "45;1"))
(define terminal-code-bg-bright-cyan
(terminal-code "46;1"))
(define terminal-code-bg-bright-white
(terminal-code "47;1"))
(define (format str)
(let loop (input result state)
(if (null? input)
(list->string (reverse result))
(match (cons (car input) state)
((#\< . 'text) (loop (cdr input) result 'enter-tag))
((#\b . 'enter-tag) (loop (cdr input)