Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload Console.Write and Console.WriteLine to take ConsoleColor as a parameter #3711

Closed
abhaycashikar opened this issue Jul 21, 2020 · 1 comment

Comments

@abhaycashikar
Copy link

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. In that case, the above example might look like this:

Console.WriteLine("This output is white on black.");
Console.WriteLine("This output is red on green.", ConsoleColor.Red, ConsoleColor.Green);
Console.WriteLine("This output is white on black.");

If overloading is not possible, additional methods like WriteColor and WriteLineColor would still be very useful in my opinion.

@CyrusNajmabadi
Copy link
Member

Not a C# language issue. Consider filing over at dotnet/runtime. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants