Skip to content

Commit

Permalink
[corlib] Support terminals without color support
Browse files Browse the repository at this point in the history
Some terminals like vt220 don't have a format string for setting foreground
or background colors. In that case, the set*color members of the
TermInfoDriver are set to null and trying to set the background color throws.

Signed-off-by: Kai Ruhnau <[email protected]>
Kai Ruhnau authored and marek-safar committed Feb 21, 2018
1 parent 705223f commit d2383c0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mcs/class/corlib/System/TermInfoDriver.cs
Original file line number Diff line number Diff line change
@@ -391,6 +391,10 @@ public bool IsSpecialKey (char c)

void ChangeColor (string format, ConsoleColor color)
{
if (String.IsNullOrEmpty (format))
// the terminal doesn't support colors
return;

int ccValue = (int)color;
if ((ccValue & ~0xF) != 0)
throw new ArgumentException("Invalid Console Color");

0 comments on commit d2383c0

Please sign in to comment.