IColorText - RealDoigt/ConsolePaint GitHub Wiki

IColorText

IColorText is an interface for coloured console text. Currently, it is inherited by ColorChar and ColorString.

Methods

Write()

This method is expected to write the text content of the child class or struct to the console. It is the case for both ColorChar and ColorString.

Here is some example C# code

using ConsolePaint;

public static void Main()
{
    var myColourfulArr = new IColorText[] 
    { 
        new ColorString(ConsoleColor.Blue, ConsoleColor.DarkBlue, "Hello, "),
        new ColorChar(ConsoleColor.Blue, ConsoleColor.DarkCyan, 'w'),
        new ColorChar(ConsoleColor.Blue, ConsoleColor.DarkGreen, 'o'),
        new ColorChar(ConsoleColor.Blue, ConsoleColor.DarkYellow, 'r'),
        new ColorChar(ConsoleColor.Blue, ConsoleColor.DarkRed, 'l'),
        new ColorChar(ConsoleColor.Blue, ConsoleColor.DarkMagenta, 'd'),
        new ColorChar(ConsoleColor.Blue, ConsoleColor.Black, '!')
    };

    foreach (var colouredText in myColourfulArr)
        colouredText.Write();

    // This will print a rainbow "Hello, world!"
}

WriteLine()

This method is expected to write the text content of the child class or struct to the console, then it should terminate the current line. It is the case for both ColorChar and ColorString.

Here is some example C# code

using ConsolePaint;

public static void Main()
{
    var myColourfulArr = new IColorText[] 
    { 
        new ColorString(ConsoleColor.Blue, ConsoleColor.DarkBlue, "Hello, "),
        new ColorChar(ConsoleColor.Blue, ConsoleColor.DarkCyan, 'w'),
        new ColorChar(ConsoleColor.Blue, ConsoleColor.DarkGreen, 'o'),
        new ColorChar(ConsoleColor.Blue, ConsoleColor.DarkYellow, 'r'),
        new ColorChar(ConsoleColor.Blue, ConsoleColor.DarkRed, 'l'),
        new ColorChar(ConsoleColor.Blue, ConsoleColor.DarkMagenta, 'd'),
        new ColorChar(ConsoleColor.Blue, ConsoleColor.Black, '!')
    };

    foreach (var colouredText in myColourfulArr)
        colouredText.WriteLine();

    /* 
        This will print a rainbow hello world on several lines:
        Hello, 
        w
        o
        r
        l
        d
        !
    */
}