How about colors and terminal graphics in std.format?

Chad J chadjoan at __spam.is.bad__gmail.com
Mon Mar 12 22:50:52 PDT 2012


On 03/13/2012 01:41 AM, James Miller wrote:
> On 13 March 2012 18:24, Chad J<chadjoan at __spam.is.bad__gmail.com>  wrote:
>> I'm not sure I agree with resetting to a default color.  What if I want to
>> write to the stream without altering the terminal's graphics settings?
>
> Actually, I meant more to make sure that any output is reset to the
> terminal's default. I'm pretty sure there is a way to do this. The
> point is that not undoing mode changes is bad form.
>
> Otherwise, I can live with the colourings being nested, but I would
> suggest a change in syntax, I understand that yours is mostly just for
> show, but using parenthesis will be annoying, I'd probably use braces
> ('{' and '}') instead, since they are less common.
>
> writefln('%Cred(\(this is in color\))');
>   vs
> writefln('%Cred{(this is in color)}');
>
> Neither are /that/ pretty, but at least the second one requires less
> escaping in the common case.
>
> --
> James Miller

Oh, I see what you mean.

This is why the second paren always had a % before it:

writefln('%Cred((this is in color)%)');

Is this OK?  I know that escaping is still involved, but the text itself 
does not need escaping: only the special closing element does.

I like this constraint because it means that the only character you ever 
have to escape in your normal text is %, which you write by using %% 
instead.


More information about the Digitalmars-d mailing list