Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Last active April 23, 2021 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsscoder/ea120292d0ca053e565bf9b94fb5f170 to your computer and use it in GitHub Desktop.
Save gsscoder/ea120292d0ca053e565bf9b94fb5f170 to your computer and use it in GitHub Desktop.
C# console helper (colors and bold)
using System;
sealed class ConsoleEx
{
public void Write(ConsoleColor color, string format, params object[] arg)
{
var current = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.Write(format, arg);
Console.ForegroundColor = current;
}
public void WriteLine(ConsoleColor color, string format, params object[] arg) =>
Write(color, $"{format}\n", arg);
public void WriteBold(string format, params object[] arg) =>
Console.Write($"\x1b[1m{format}\x1b[0m", arg);
public void WriteBoldLine(string format, params object[] arg) =>
WriteBold($"{format}\n", arg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment