Skip to content

Console Color Configuration #126

Answered by Tyrrrz
fossbrandon asked this question in Q&A
Discussion options

You must be logged in to vote

You can use these extension methods to set and auto-reset colors:

/// <summary>
/// Sets the specified foreground color and returns an <see cref="IDisposable"/>
/// that will reset the color back to its previous value upon disposal.
/// </summary>
public static IDisposable WithForegroundColor(this IConsole console, ConsoleColor foregroundColor)
{
var lastColor = console.ForegroundColor;
console.ForegroundColor = foregroundColor;
return Disposable.Create(() => console.ForegroundColor = lastColor);
}
/// <summary>
/// Sets the specified background c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by fossbrandon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants