runtime: Bright console colors don't work correctly on Linux

Given the following C# code:

using System;
using System.Linq;

namespace colors
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine();

            var colors = Enum.GetValues(typeof(ConsoleColor)).Cast<ConsoleColor>().ToList();
            foreach (var fore in colors)
            {
                foreach (var back in colors)
                {
                    Console.ForegroundColor = fore;
                    Console.BackgroundColor = back;
                    Console.Write(" *** ");

                    Console.ResetColor();
                    Console.Write("  ");
                }

                Console.WriteLine();
            }

            Console.WriteLine();
        }
    }
}

When run on Windows 10, it correctly prints out with bright foreground and background colors:

Windows 10

When run on Linux (in my example, Ubuntu Server 16.04), bright colors are shown dark:

Ubuntu 16.04

I verified this with bug .NET Core 1.x and 2.0. The reason this came up is because I noticed that the color output from dotnet xunit was broken, as we rely on bright colors when writing our output. I have a temporary workaround in place which emits the correct ANSI codes when running on non-Windows machines. Here you can see the difference between the Windows and Linux outputs:

dotnet xunit on Windows

dotnet xunit on Ubuntu 16.04


As an interesting postscript, the bug does not seem to affect Windows Subsystem for Linux:

Windows Subsystem for Linux

So when verifying this bug, it’s important to use a real Linux installation (I used VMs in Hyper-V for my testing).

/tag @karelz @terrajobst

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 4
  • Comments: 24 (15 by maintainers)

Most upvoted comments

@david-tamar if you have idea how to fix it, we would welcome a contribution. Otherwise I am afraid this is not too high on our priority list. Please upvote top post to help us gather the feedback on how many people want it … thanks!

That powershell prompt looks pretty slick…! :trollface: