(I was directed to repost this feature request here.)
I'm trying to create a user-friendly command-line application, and as such I wanted to color my output to the console. However, I found myself frequently writing code like this:
Console.WriteLine("This output is white on black.");
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.Green;
Console.WriteLine("This output is red on green.");
Console.ResetColor();
Console.WriteLine("This output is white on black.");
I thought it might be a lot easier for Console
to have an overload on Write
and WriteLine
that takes in two ConsoleColor
elements as arguments for the ForegroundColor
and BackgroundColor
variables and abstracts this process away from the developer. This way, the process of setting the ForegroundColor
and BackgroundColor
variables, writing to the console, and resetting the color can be written as one line in code. I think something like the below would work:
+ public static void WriteLine(ConsoleColor foreground, ConsoleColor background, string value) { throw null; }
Console.WriteLine("This output is white on black.");
Console.WriteLine(ConsoleColor.Red, ConsoleColor.Green, "This output is red on green.");
Console.WriteLine("This output is white on black.");
would be equivalent to the code in the Background and Motivation section.
If overloading is not possible, additional methods like WriteColor
and WriteLineColor
would still be very useful in my opinion.
I'm not really sure if there are any risks that come with making this change. I don't think there would be because the functionality would just use the existing methods in Console
and the existing ConsoleColor
enum.
Most helpful comment