Skip to content

A library for coloring console output using ANSI escape codes

License

Notifications You must be signed in to change notification settings

Kantaiko/ConsoleFormatting

Repository files navigation

Kantaiko.ConsoleFormatting

A C# library for coloring console output using ANSI escape codes.

Support

  • Windows (cmd, powershell, Windows Terminal, ...)
  • Linux
  • MacOS (not tested yet)

Colors

All color methods have Fg (Foreground) and Bg (Background) versions.

Library uses colors from System.Drawing.Color

Default palette

Console.WriteLine(Colors.FgColor("Foreground Color", Color.Black));
Console.WriteLine(Colors.BgColor("Background Color", Color.Black));

Console.WriteLine(Colors.FgRed("Red"));
Console.WriteLine(Colors.BgRed("Green"));
  • Black
  • Red
  • Green
  • Yellow
  • Blue
  • Magenta
  • Cyan
  • Gray
  • White

RGB / HEX / HSL

Console.WriteLine(Colors.FgHex(".NET", "#FFCC00"));
Console.WriteLine(Colors.FgRgb(".NET", 80, 39, 213));
Console.WriteLine(Colors.FgHsl(".NET", 290, 1f, 0.25f));

Decorations

Console.WriteLine(Decorations.Decoration("Blink", TextDecoration.Blink));

Console.WriteLine(Decorations.Underline("Underline"));
  • Reset
  • Bold
  • Dim
  • Italic
  • Underline
  • Blink
  • Inverse
  • Hidden
  • Strike
  • Overline

Chain formatting

Console.WriteLine(Colors.FgYellow("Custom Text").BgRed().Bold().Underline());

Console.WriteLine(Decorations.Italic("Custom Text").FgRed());