Walter Bright wrote:
> On 10/21/2012 12:28 PM, Robik wrote:
> > Simple example:
> >
> > import std.stdio, colord;
> > void main()
> > {
> >      setConsoleColors(Fg.red, Bg.blue);
> >      writeln("Red text on blue background.");
> >      resetConsoleColors(); // Bring back initial state
> > }
> 
> Need a method to get the current state, and reset the current state.
> Otherwise, nested calls to the console functions will screw up the
> state.
> 
> I.e.:
> 
>     auto save = getConsoleState();
>     setConsoleColors(Fg.red, Bg.blue);
>     writeln("Red text on blue background.");
>     setConsoleState(save); // Bring back initial state
> 
> Or better:
> 
>     auto save = getConsoleState();
>     scope (exit) setConsoleState(save);
>     setConsoleColors(Fg.red, Bg.blue);
>     writeln("Red text on blue background.");

Very true.
Problem is that on Linux (probably most Unix* systems) you cannot get
the current color. Only the default one.
I added wrappers like above.
https://github.com/jkm/terminal/blob/master/src/terminal.d#L187

Jens

Reply via email to