Using colors in console, how to store in a simplified notation

It's not entirely clear what you mean, but you could always create helper methods:

public static void ColoredConsoleWrite(ConsoleColor color, string text)
{
    ConsoleColor originalColor = Console.ForegroundColor;
    Console.ForegroundColor = color;
    Console.Write(text);
    Console.ForegroundColor = originalColor;
}

Use can use my library Edokan.KaiZen.Colors . It is a shameless copy of colors npm module for node.js.

It has some problems but it works. Actually it works just the way you want.

Console.WriteLine("INFO: ".Cyan().Bold() + " This is just a message");

Another idea is to embed something like the ANSI escape codes but they are quite extensive, with color just a smallish subset of them.

So I'd recommend embedding color codes in the output strings, using a section of the Unicode Private Use Area (PUA) in the Basic Multilingual Plane (BMP) and a basic parser/renderer.

BTW the console color settings are global to the process, so if multiple threads are generating colored output each block needs to be surrounded by a critical section to avoid "color confusion".

Since its a bit long to put inline I've uploaded the sample source to my site.

Tags:

C#

.Net

Console