[racket] terminal-color package - output colored text to the terminal - comments before release
This is really cool.
I agree that a `printf`-color` would be handy.
I notice that adding it would require adding it 3 times, to each of
the 3 plugins in private/.
I wonder if each plugin could instead supply just its variation of
`display-color`? Because IIUC `displayln-color`, `print-color`, and
`write-color` (and `printf-color` and so on) could all be implemented
on top of that, up in main.rkt?
For example, private/off.rkt could provide just this:
(define (display-color v #:fg fg #:bg bg)
(display v))
Now main.rkt can dynamic-require just that, from the appropriate
private/ plugin, and implement everything else in terms of that:
(define (displayln-color v #:fg fg #:bg bg)
(display-color v #:fg fg #:bg bg)
(newline))
(define (print-color v #:fg fg #:bg bg)
(define out (open-output-string))
(print v out)
(display-color (get-output-string out) #:fg fg #:bg bg))
(define (write-color v #:fg fg #:bg bg)
(define out (open-output-string))
(write v out)
(display-color (get-output-string out) #:fg fg #:bg bg))
That makes each private/ plugin simpler. Hmm, the above stuff
in main.rkt is still kind of repetitious. We could make that
simpler:
(define (my-x f)
(λ (v #:fg fg #:bg bg)
(define out (open-output-string))
(f v out)
(display-color (get-output-string out) #:fg fg #:bg bg)))
(define displayln-color (my-x displayln))
(define print-color (my-x print))
(define write-color (my-x write))