Skip to content

Redundant logic in ConsoleExtensions #1851

Closed
@KalleOlaviNiemitalo

Description

@KalleOlaviNiemitalo

The SetTerminalForegroundRed and ResetTerminalForegroundColor methods of ConsoleExtensions can read the Platform.IsConsoleRedirectionCheckSupported and Console.IsOutputRedirected properties when deciding what to do. However, the value of Console.IsOutputRedirected has no effect in the end, because those methods execute the same code either way:

IsConsoleRedirectionCheckSupported IsOutputRedirected SetTerminalForegroundRed ResetTerminalForegroundColor
true false sets Console.ForegroundColor calls Console.ResetColor()
true true sets Console.ForegroundColor calls Console.ResetColor()
false not read does nothing does nothing

That seems unintentional. If the behavior is correct, then at least the logic could be simplified.

Previously noted in #1850 (comment).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions