You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bright console colors don't work correctly on Linux #23241
When run on Windows 10, it correctly prints out with bright foreground and background colors:
When run on Linux (in my example, Ubuntu Server 16.04), bright colors are shown dark:
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:
As an interesting postscript, the bug does not seem to affect 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).
@bradwilson, what is the value of your TERM environment variable? Is it "xterm"? What happens if you do export TERM=xterm-256color and then try running the program again?
Neither of my failure cases (SSH or native console) have xterm as their TERM value. The former has cygwin, and the latter has linux. In both cases, xterm-256color shows the results above (and is clearly not right, because it breaks full screen apps like nano).
FWIW, I don't believe that xterm-256color should be required, since the colors supported by ConsoleColor represent the core 16 colors (8+bold) that are always available in any ANSI-compatible terminal, including xterm. This is validated for me because when I replaced the calls to Console.ForegroundColor with their ANSI equivalents, I get correct functionality all around:
can you please describe what system you are connecting to and how?
What I was trying to say is that terminal handling (and colors) are somewhat more complicated.
The connecting client states it self via TERM and than the OS look into it's internal database and tries to map certain attributes into sequence of bytes. Those sequences are interpreted by your client and than turned into bold or colorful text. For example legacy VT100 could do bold but not colors.
The are parts is profile setting. Many distributions try to do all kinds of fancy stuff.
You can run "set" and see.
The other part of the puzzle may also be output setting. For example, in some cases you would get colors from 'ls'. But you would not if you pipe that to for example 'less' or 'more'.
This is because the output device is not terminal but a pipe.
If I have more details I'll try to repeat than and reproduce behavior you observed.
With that I can try to figure out if that is just some setting or real bug.
As described above, this is an Ubuntu Server 16.04 VM, running on Hyper-V. I experience the issue both via SSH (using the ssh client from Git for Windows) as well as via the native Linux console for the server (accessed via Hyper-V's client).
TERM for SSH = cygwin
TERM for Server console = linux
Is .NET Core's color implementation not depending on the bold terminal feature?
It is, but whether that's supported is dictated by the terminal, and what the terminal supports is exposed via terminfo, which .NET Core examines to determine what it can do. The terminfo specifies the max number of colors supported, and that's taken into account here when Console writes out the relevant escape string: https://github.com/dotnet/corefx/blob/38e60f7d5b1bfa68b6dba3481fed63fad29ce315/src/System.Console/src/System/ConsolePal.Unix.cs#L539-L545
That MaxColors value is coming from your terminfo database, based on whatever is specified in the TERM environment variable. When you see the limited set of colors, what do you get when you type infocmp? On around the 4th line of output, you should see something like colors#8, colors#16, colors#256, etc. If the terminal database tells .NET Core that it only supports 8 colors, .NET Core won't try to use more than that, as it doesn't want to output escape sequences that will be gibberish.
@stephentoub It says 8 colors with bold, as I would've expected. It would appear that you're not checking for bold support to see if it's available and just assume that 8 is all you can do (rather than bolding the 8 for 16).
It says 8 colors with bold, as I would've expected. It would appear that you're not checking for bold support
@bradwilson, are you referring to the entry bold=\E[1m that it has in addition to the setab=\E[4%p1%dm and setaf=\E[3%p1%dm entries for color? What exactly are you proposing be done... if the specified max colors is 8 rather than 16, and there's a bold entry, output both setfb and bold sequences when changing the foreground color? What about the background color?
FWIW, while I think it would be beneficial to the community at large to fix this, the fact that it's broken (and unlikely to be fixed) in 1.x as well as 2.x means that I'll probably leave my ANSI version in indefinitely. I can't imagine this would reach the bar of fixing it in LTS.
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.
Activity
clairernovotny commentedon Aug 18, 2017
That powershell prompt looks pretty slick....!
karelz commentedon Aug 18, 2017
@wfurt can you please take a look while @ianhays is out?
stephentoub commentedon Aug 18, 2017
@bradwilson, what is the value of your TERM environment variable? Is it "xterm"? What happens if you do
export TERM=xterm-256colorand then try running the program again?stephentoub commentedon Aug 18, 2017
For reference:

wfurt commentedon Aug 18, 2017
TERM is one thing to look for. The colors also possibly depend on profile and termcap/terminfo
bradwilson commentedon Aug 18, 2017
@stephentoub That's worse, actually:
Neither of my failure cases (SSH or native console) have
xtermas their TERM value. The former hascygwin, and the latter haslinux. In both cases,xterm-256colorshows the results above (and is clearly not right, because it breaks full screen apps like nano).FWIW, I don't believe that
xterm-256colorshould be required, since the colors supported byConsoleColorrepresent the core 16 colors (8+bold) that are always available in any ANSI-compatible terminal, includingxterm. This is validated for me because when I replaced the calls toConsole.ForegroundColorwith their ANSI equivalents, I get correct functionality all around:bradwilson commentedon Aug 18, 2017
@wfurt The
cygwinterminal supports bold colors, as shown here with the output frommsgcat --color=test:Is .NET Core's color implementation not depending on the bold terminal feature?
wfurt commentedon Aug 18, 2017
can you please describe what system you are connecting to and how?
What I was trying to say is that terminal handling (and colors) are somewhat more complicated.
The connecting client states it self via TERM and than the OS look into it's internal database and tries to map certain attributes into sequence of bytes. Those sequences are interpreted by your client and than turned into bold or colorful text. For example legacy VT100 could do bold but not colors.
The are parts is profile setting. Many distributions try to do all kinds of fancy stuff.
You can run "set" and see.
The other part of the puzzle may also be output setting. For example, in some cases you would get colors from 'ls'. But you would not if you pipe that to for example 'less' or 'more'.
This is because the output device is not terminal but a pipe.
If I have more details I'll try to repeat than and reproduce behavior you observed.
With that I can try to figure out if that is just some setting or real bug.
bradwilson commentedon Aug 18, 2017
As described above, this is an Ubuntu Server 16.04 VM, running on Hyper-V. I experience the issue both via SSH (using the ssh client from Git for Windows) as well as via the native Linux console for the server (accessed via Hyper-V's client).
TERM for SSH =
cygwinTERM for Server console =
linuxstephentoub commentedon Aug 18, 2017
It is, but whether that's supported is dictated by the terminal, and what the terminal supports is exposed via terminfo, which .NET Core examines to determine what it can do. The terminfo specifies the max number of colors supported, and that's taken into account here when Console writes out the relevant escape string:
https://github.com/dotnet/corefx/blob/38e60f7d5b1bfa68b6dba3481fed63fad29ce315/src/System.Console/src/System/ConsolePal.Unix.cs#L539-L545
That MaxColors value is coming from your terminfo database, based on whatever is specified in the TERM environment variable. When you see the limited set of colors, what do you get when you type
infocmp? On around the 4th line of output, you should see something likecolors#8,colors#16,colors#256, etc. If the terminal database tells .NET Core that it only supports 8 colors, .NET Core won't try to use more than that, as it doesn't want to output escape sequences that will be gibberish.bradwilson commentedon Aug 18, 2017
@stephentoub It says 8 colors with bold, as I would've expected. It would appear that you're not checking for bold support to see if it's available and just assume that 8 is all you can do (rather than bolding the 8 for 16).
danmoseley commentedon Aug 18, 2017
My ubuntu also supports "dim" (half-bright)
stephentoub commentedon Aug 19, 2017
@bradwilson, are you referring to the entry
bold=\E[1mthat it has in addition to thesetab=\E[4%p1%dmandsetaf=\E[3%p1%dmentries for color? What exactly are you proposing be done... if the specified max colors is 8 rather than 16, and there's a bold entry, output both setfb and bold sequences when changing the foreground color? What about the background color?bradwilson commentedon Aug 19, 2017
I'm suggesting that in the face of 8-color + bold, you can at least get the 16 foreground colors (if not the 16 background colors).
bradwilson commentedon Aug 21, 2017
FWIW, while I think it would be beneficial to the community at large to fix this, the fact that it's broken (and unlikely to be fixed) in 1.x as well as 2.x means that I'll probably leave my ANSI version in indefinitely. I can't imagine this would reach the bar of fixing it in LTS.
8 remaining items
eiriktsarpalis commentedon Mar 4, 2020
Triage: we welcome contributions towards improving this.
dotnet-policy-service commentedon Dec 24, 2024
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This process is part of our issue cleanup automation.
dotnet-policy-service commentedon Jan 7, 2025
This issue will now be closed since it had been marked
no-recent-activitybut received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.