[RFC] ColorD
Jens Mueller
jens.k.mueller at gmx.de
Sun Oct 21 15:11:07 PDT 2012
Chad J wrote:
> On 10/21/2012 05:01 PM, Jens Mueller wrote:
> >Robik wrote:
> >>Hello,
> >>
> >>I would like to introduce ColorD, small library that allows to
> >>simply manipulate console output colors, both on Windows and Posix
> >>operating systems. It also supports font styles such as underline
> >>and strikethrough(Posix feature only).
> >>
> >>
> >>Simple example:
> >>
> >>import std.stdio, colord;
> >>void main()
> >>{
> >> setConsoleColors(Fg.red, Bg.blue);
> >> writeln("Red text on blue background.");
> >> resetConsoleColors(); // Bring back initial state
> >>}
> >>
> >>
> >>Feedback welcome.
> >>
> >>GitHub: https://github.com/robik/ColorD
> >
> >Interesting looks solid to me.
> >Some nit-picks:
> >* Coloring on Posix depends a ANSI terminal. Can you check that a
> > terminal is ANSI compatible?
> >* There are some magic numbers in the code. These may be difficult to
> > figure out for maintaining.
> >* enum Color should maybe be same on all systems.
> > This is a rather small issue. But I may transfer the Color to another
> > system. So if it is possible there should only be one enum Color for
> > all systems.
> >* Call it terminal or similar. Because other terminal related stuff can
> > be added and IMHO it's a better name.
> >
> >I have written a similar library. Not finished. Let's join forces.
> >https://github.com/jkm/terminal
> >
> >Johannes Pfau has written a progress bar. I will add this.
> >
> >Jens
>
> Hey that looks cool.
>
> It seems to have a hard ncurses/termcap/etc dependency.
Yes. I think you cannot make it portable without. Please proof me wrong
and I'll fix this.
> I'll admit when I started trying to work on doing this thing, I
> never got anything onto the screen. What stopped me was that I
> couldn't figure out how to detect ncurses/termcap/etc. I was going
> to shoot for Phobos inclusion and making Phobos always link with
> ncurses seems like a bad idea.
Dependence on Phobos is bad. If you can detect whether a terminal is
ANSI compatible then this mode should be default. But I don't know how
to detect this.
> Ultimately I expect it to work with writeln or writefln to make it
> discoverable and easy to work with.
One could try this. At least for Linux. You just have to add the
appropriate escape sequences. But this won't work on Windows.
> Back then I did design a format spec for introducing colors into
> format strings:
> www.chadjoan.com/d/dmd.2.058/html/d/phobos/std_format.html
I doubt that the Phobos maintainers will accept this. This is very
invasive.
I added writecf, writec, etc. with additional arguments.
writec(Color.red, "some text")
or
writecf(Color.red, "%s", "some text")
This is fine I think. But better options may be worth investigating.
Jens
More information about the Digitalmars-d
mailing list