Task

Display a word in various colours on the terminal.

The system palette, or colours such as Red, Green, Blue, Magenta, Cyan, and Yellow can be used.



Optionally demonstrate:

 How the system should determine if the terminal supports colour
 Setting of the background colour
 How to cause blinking or flashing (if supported by the terminal)


import
    std.conv,
    std.stdio;
 
enum Color {
    fgBlack = 30,
    fgRed,
    fgGreen,
    fgYellow,
    fgBlue,
    fgMagenta,
    fgCyan,
    fgWhite,
 
    bgBlack = 40,
    bgRed,
    bgGreen,
    bgYellow,
    bgBlue,
    bgMagenta,
    bgCyan,
    bgWhite
}
 
string color(string text, Color ink) {
    return "\033["
        ~ ink.to!int.to!string
        ~ "m"
        ~ text
        ~ "\033[0m";
}
 
void main() {
    auto colors = [
        Color.fgBlack,
        Color.fgRed,
        Color.fgGreen,
        Color.fgYellow,
        Color.fgBlue,
        Color.fgMagenta,
        Color.fgCyan,
        Color.fgWhite
    ];
 
    foreach (c; colors) {
        // Print the color name, in white.
        c.to!string.color(Color.fgWhite).writeln;
 
        // Print some text in the color.
        "Hello, world!".color(c).writeln;
    }
}