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.");

Reply via email to