[racket] terminal-color package - output colored text to the terminal - comments before release

From: Richard Hopkins (richhguard-monotone at yahoo.co.uk)
Date: Fri Jan 30 17:17:04 EST 2015

Thanks for your comments and trying it out, all of you!

I like the idea of mimicking what the terminal would look like so
I'll see if I can get Robby's idea to work.

---

As for printf-color, that was just an oversight, but I was
planning to add a high level formatting procedure to
format a message with multiple colors in one go, rather than
multiple calls. I just don't have the ability to do it yet.

e.g.
error: the value X is invalid. please make sure it follows Y.

error might want to be in red, and X in cyan to signify user data
from the rest of message.

At the moment you would have to do something like

(display-color "error:" #:fg 'red)
(display-color " the value " #:fg 'white)
(display-color X #:fg 'cyan)
(display-color " is invalid. please make sure it follows " #:fg 'white)
(display-color Y #:fg 'green)
(newline)

it's cumbersome and not very readable. Where as something like (made up
just now)

(outputf-color "(error:) the value (~a) is invalid. please make sure it follows (~a).~n"
               ([#:fg 'red])
               (X [#:fg 'cyan])
               (Y [#:fg 'green]))

shows the intent and the wanted output much clearer.

(outputf-color colored-format-string colored-args ...)

where colored-args is a list containing the data and a sublist each for
the the foreground and background color - all optional but at least
one must be supplied.

colored-format-string supports the standard formatting operators like printf,
but they must be inside parentheses. Anything inside parentheses will be
considered valid to be colored according to the relevant argument,
processed from left-to-right.
Anything inside the parentheses that is not a formatting operator will
flow directly through to the output.

I'm open for suggestions on this too.

---

I'll give Gregg's idea a go as well too to reduce the repetition.

Cheers


________________________________
 From: Asumu Takikawa <asumu at ccs.neu.edu>
To: Richard Hopkins <richhguard-monotone at yahoo.co.uk> 
Cc: "users at racket-lang.org" <users at racket-lang.org> 
Sent: Thursday, 29 January 2015, 23:17
Subject: Re: [racket] terminal-color package - output colored text to the terminal - comments before release
 

On 2015-01-25 22:19:51 +0000, Richard Hopkins wrote:
>    To help me learn Racket, and also because I find colored text useful I've
>    been working on
>    a Racket package which I aim to release on http://pkgs.racket-lang.org/

This is cool! I tried the examples on Linux and it works for me.

>    * the API is right for end users

I noticed that a `printf-color` was missing. That might be handy.

>    * the documentation is readable with decent examples

The docs look good to me. One thing I might note in the "Examples"
section is that the output in the docs don't look like how it's supposed
to look in a real terminal.

Cheers,
Asumu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150130/685e4256/attachment.html>

Posted on the users mailing list.