79365798

Date: 2025-01-17 18:38:03
Score: 0.5
Natty:
Report link

For future users.. You can display 24bit (16,777,216) colors within a windows console from any language with the use of Ascii Text.

C# Example, this is a Color object extension:

public static class ColorExt
{
    /// <summary>
    /// Color extension to convert Color to Ascii text to be used within a Console.Write/WriteLine.
    /// </summary>
    public static string ToAscii(this Color clr, bool isForeground)
    {
        var present = isForeground ? 38 : 48;
        return $"\x1b[{present};2;{clr.R};{clr.G};{clr.B}m";
    }
}

Usage:

const string RESET = "\x1b[0m";
Console.WriteLine($"This is {Color.Gold.ToAscii(true)}GOLD text and " +
                  $"now with a {Color.Red.ToAscii(false)}RED background{RESET}. " +
                  $"After reset, all colors are set back to default.");

Results: enter image description here

Happy hacking..

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Chizl