termcolor-d - Colors with writeln(...);

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Nov 21 23:30:39 UTC 2018


On Wed, Nov 21, 2018 at 06:36:06PM +0000, Vladimirs Nordholm via Digitalmars-d-announce wrote:
> https://github.com/vladdeSV/termcolor-d
> 
> Saw a library recently which allowed you to color text, but it had an
> odd syntax.
> 
> Since I already had some code for coloring text in terminals, I made
> this (hackish, POSIX only) project during lunch break. It in action:
> 
>     import std.stdio : writeln;
>     import termcolor;
> 
>     // Color → Green → Foreground
>     writeln(C.green.fg, "Green text", resetColor);
> 
>     // Color → Red → Background
>     writeln(C.red.bg, "Red background", resetColor);
> 
>     // only tested on macOS running zsh using iTerm2/Hyper.js/Terminal.app
> 
> Hope this helps those who are making CLI applications :^)

Clever idea!  Doesn't quite cover all the color features of newer
terminals, but good enough for basic coloring on the terminal.  Maybe
I'll steal your idea next time I'm looking for some terminal colors. :D


T

-- 
I am not young enough to know everything. -- Oscar Wilde


More information about the Digitalmars-d-announce mailing list