Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

ANSI Colors

samintz

Scott Mintz
May
1,582
27
I think I have MS Terminal and Tcmd configured to use the same font. But the ANSI colors are different. I am running bash (WSL2) in a tab in Tcmd and also in MS Terminal. The top image is Terminal and the lower one is Tcmd. The blues are lighter in Terminal.

1610464607790.png


Is there any way to control this? The darker blue in Tcmd is much harder to read. FWIW - the darker blue also shows up if I launch Ubuntu2004.exe which opens wsl2 in its own console window. So it seems like it might be a feature of conhost vs OpenConsole.
 
My guess is that TCMD knows only 16 colors while WT, OpenConsole, and conhost know a lot more. Here (top to bottom) are WT, OpenConsole, and conhost.

1610472989462.png



In TCMD that looks like this. I don't know why TCMD doesn't see two shades of blue. Legacy apps are supposed to get a "closest match".

1610473688290.png


If I detach the tab it looks OK, like the three above.

1610473721299.png


All that said, there are some bugs in the generally available conhos.exet that make ReadConsoleOutputAttribute not work as expected. This is fixed in OpenConsole.exe and, I believe, in conhost.exe in insider builds.

Interesting: Here's the OpenConsole from far above after being attached to TCMD.

1610474311501.png


There's a very recent thread on GitHub (Terminal) started by the author of ConEmu that deals with reading the attributes. It refers to a few other threads dealing with various aspects of the same thing.
 
I forgot that doing that was not exactly straightforward. At an elevated TCC prompt I went to one of these.

Code:
c:\program files\windowsapps\Microsoft.WindowsTerminalPreview_1.5.3242.0_x64__8wekyb3d8bbwe\
c:\program files\windowsapps\Microsoft.WindowsTerminal_1.4.3243.0_x64__8wekyb3d8bbwe\

Then I could copy OpenConsole.exe.
 
On my system, OpenConsole.exe is located at;
Code:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\Terminal\ServiceHub\os64\OpenConsole.exe
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\Terminal\ServiceHub\os86\OpenConsole.exe

I can run that directly without copying it;
Code:
 Directory of  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\Terminal\ServiceHub\os64\*

2020-12-10  17:43         <DIR>    .
2020-12-10  17:43         <DIR>    ..
2020-12-10  17:43          51,088  conpty.dll
2020-12-10  17:43       1,009,568  OpenConsole.exe
           1,060,656 bytes in 2 files and 2 dirs    1,064,960 bytes allocated

Although you [ @vefatica ] may have a newer one than I have.

Joe
Code:
     _x64: 1
   _admin: 1
_elevated: 1

TCC  27.00.18 x64   Windows 10 [Version 10.0.18363.1256]
 
This is my newest one.

Code:
c:\program files\windowsapps\microsoft.windowsterminalpreview_1.5.3242.0_x64__8wekyb3d8bbwe> d o*
2020-12-04  22:35       1,079,296  OpenConsole.exe

My VisualStudio 64-bit one is

Code:
2020-12-03  23:04       1,009,568  OpenConsole.exe

My latest release WT one is

Code:
c:\program files\windowsapps\microsoft.windowsterminal_1.4.3243.0_x64__8wekyb3d8bbwe> d o*
2020-11-27  14:34       1,060,352  OpenConsole.exe

I wouldn't put too much stock in the file dates.
 
I think I have MS Terminal and Tcmd configured to use the same font. But the ANSI colors are different. I am running bash (WSL2) in a tab in Tcmd and also in MS Terminal. The top image is Terminal and the lower one is Tcmd. The blues are lighter in Terminal.

View attachment 3200

Is there any way to control this? The darker blue in Tcmd is much harder to read. FWIW - the darker blue also shows up if I launch Ubuntu2004.exe which opens wsl2 in its own console window. So it seems like it might be a feature of conhost vs OpenConsole.

You need to define a custom palette in TCMD (like Terminal is doing).
 
You need to define a custom palette in TCMD (like Terminal is doing).

Would you mind explaining how to do that?

Options / Take Command / Tabs / Colors pops up a color picker, but it doesn't seem to do anything. The sixteen 'custom colors' at the bottom look like console colors, and I would think that changing them would affect either the current tab or new tabs, but that doesn't seem to work for me.
 
Today's console (the general audience conhost.exe or openconsole.exe) and WindowsTerminal support 24-bit color and I think TCMD supports only 16 colors. Below are 896 colors (I checked them by reading the screen, plus black) in conhost.exe/TCC ... all at once.
1610559117959.png

Those were made with the escape sequence ESC[38;2;<r>;<g>;<b>m. There are a couple other palettes in the new-fangled console and escape sequences to use them. This is good reading (and not comprehensive).

Once those colors have been displayed, there's no way to retrieve them using the console API functions. They have to be approximated by the colors in the legacy 16-color palette (those can be changed but there's still only 16 of them). So while a custom TCMD palette might work OK (i.e., compared to a console) in some cases, it might not in other cases.

I'll continue, mostly because I have a question.

When the console above is attached by TCMD, the result is dreadful.
1610560724155.png

I suspect that's due to a bug in today's conhost.exe in which ReadConsoleOutputAttribute doesn't work correctly. If I run lotsacolors.btm in the newer OpenConsole.exe, it looks the same as in conhost.exe and it looks better when attached by TCMD.
1610560992603.png

You can see the "approximation" using 16 colors in the righthand 3/4 of that pic. But what's going on in the left 1/4? I'd expect it to be much darker ... even black.
 
My question? I'm just asking how to use Take Command's color configuration dialog, which I honestly don't get. Nothing to do with Windows Terminal or other third-party tools.
Here's how it works. Go to Options\TakeCommand\Tabs ... press the "Colors" button. Under "Custom colors" you see the current palette. Select one of them (the one to be replaced) ... I chose dark blue.. Then pick (basic colors) or create another color and say "Add to custom colors" (I chose the top-left one, kind of pale orange) ... it replaces the dark blue. Say OK ... OK ... and restart TCMD. Now, after running lotsacolors.btm, I see
1610562777099.png

Compare that to my last post. Dark blue has been replaced by pale orange.
 
So, Scott, you can use the technique of my last port to change the dark blue to something lighter.
 
P.S., You don't have to restart TCMD. Though the change won't show up in existing tabs, it will show up in new tabs.
 
Here's how it works. Go to Options\TakeCommand\Tabs ... press the "Colors" button. Under "Custom colors" you see the current palette. Select one of them (the one to be replaced) ... I chose dark blue.. Then pick (basic colors) or create another color and say "Add to custom colors" (I chose the top-left one, kind of pale orange) ... it replaces the dark blue. Say OK ... OK ... and restart TCMD. Now, after running lotsacolors.btm, I see
View attachment 3212
Compare that to my last post. Dark blue has been replaced by pale orange.

On my system — Take Command 26.02, Windows 10 x64 — that doesn't do anything. It doesn't affect the current tab or newly created tabs, and the custom colors are lost when restarting Take Command.

Custom-colors.png
 
I don't know what's going on. In v27, I can repro my experiment with lotsacolors.btm and the dark blue continues to be pale orange. And in v26, I can do the same experiment changing the dark blue to a very light blue. Using lotsacolors.btm, I see the lighter blue after a restart, but I don't see the lighter blue in the color dialogs and I don't see it if I use ^e[34m. Here's the BTM.

Code:
do i=1 to 255 by 2 ( echos ^e[38;2;%i;%i;%[i]m%@char[0x2588] ) & echo.
do i=1 to 255 by 2 ( echos ^e[38;2;%i;0;0m%@char[0x2588] ) & echo.
do i=1 to 255 by 2 ( echos ^e[38;2;0;%i;0m%@char[0x2588] ) & echo.
do i=1 to 255 by 2 ( echos ^e[38;2;0;0;%[i]m%@char[0x2588] ) & echo.
do i=1 to 255 by 2 ( echos ^e[38;2;%i;%i;0m%@char[0x2588] ) & echo.
do i=1 to 255 by 2 ( echos ^e[38;2;%i;0;%[i]m%@char[0x2588] ) & echo.
do i=1 to 255 by 2 ( echos ^e[38;2;0;%i;%[i]m%@char[0x2588] ) & echo.

So forgetting about the 24-bit color stuff, I don't see how you change the basic 16 colors that TCMD uses which (I would hope) would correspond to the (good old fashioned).
 
Hmmm! The help says

Take Command will first try to retrieve a color palette from the console. If the console app is using a custom palette, Take Command will use that palette for the tab window. If there is no custom palette defined for this console, Take Command will use the palette set by Tab Colors.

I still don't know what's going on. That only seems to make it more complicated. Is TCMD looking at the subkeys of HKCU\Console?
 
You're making this a lot more complicated than it really is.

1. TCC has nothing to do with the displayed colors; that's entirely up to conhost or openconsole.
2. TCMD can only support 16 colors, because the Windows console APIs only support 16 colors. (The higher-color modes in the Win 10 console are only supported through ANSI sequences in the console, which TCMD can't see.)
3. TCMD.INI has an optional [ConsoleColors] section that will redefine the color palette to use. The Tabs / Colors button in the Take Command configuration dialog sets the values in [ConsoleColors].
4. "COLOR /F filename" will read a color .INI or .ITERMCOLORS file.
 
3. TCMD.INI has an optional [ConsoleColors] section that will redefine the color palette to use. The Tabs / Colors button in the Take Command configuration dialog sets the values in [ConsoleColors].

I see that the Options / Take Command / Tabs / Colors dialog does save the custom color values to the .INI file. However, Take Command doesn't seem to use those values: not for the current tab, not for new tabs, not when Take Command is restarted. The [TabColors] .INI section appears to be write-only.

TCmd-color-config.png
 
You're making this a lot more complicated than it really is.

1. TCC has nothing to do with the displayed colors; that's entirely up to conhost or openconsole.
2. TCMD can only support 16 colors, because the Windows console APIs only support 16 colors. (The higher-color modes in the Win 10 console are only supported through ANSI sequences in the console, which TCMD can't see.)
3. TCMD.INI has an optional [ConsoleColors] section that will redefine the color palette to use. The Tabs / Colors button in the Take Command configuration dialog sets the values in [ConsoleColors].
4. "COLOR /F filename" will read a color .INI or .ITERMCOLORS file.
I see that the Options / Take Command / Tabs / Colors dialog does save the custom color values to the .INI file. However, Take Command doesn't seem to use those values: not for the current tab, not for new tabs, not when Take Command is restarted. The [TabColors] .INI section appears to be write-only.
Charles, the colors in the INI file are used. Make this change and you'll see what I mean.
Code:
TabColor00=16777215

But (Rex) when you're in the Tabs/Colors dialog, how do you know which color you're changing? And if you do change something, it doesn't look changed in that dialog after a restart. How can you tell what, in that dialog, corresponds to what, in the INI file ... and how those two match up with the the color names (and possibly BRIGHT) and with the numbers that typically go here: ESC[3x;4x[;1]m.

Maybe you could give a specific example. If I want to change TabColor04 (dark blue, 128) to something lighter, what do I do in the dialog? There's a "Define Custom Colors >>" button, which sounds interesting, but it's (always) greyed out.
 
Charles, the colors in the INI file are used. Make this change and you'll see what I mean.
Code:
TabColor00=16777215

Yeah, no. Black is still black, even after restarting TCmd. And if I change it to TabColor00=QQQ, Take Command doesn't complain about that either. It looks like Take Command isn't even reading that section.
 
Yeah, no. Black is still black, even after restarting TCmd. And if I change it to TabColor00=QQQ, Take Command doesn't complain about that either. It looks like Take Command isn't even reading that section.
Hmmm! Do you think it has something to do with ...

Take Command will first try to retrieve a color palette from the console. If the console app is using a custom palette, Take Command will use that palette for the tab window. If there is no custom palette defined for this console, Take Command will use the palette set by Tab Colors.
 
So I started poking around in the registry. No custom colors for TCC v26:

Regedit-console-colors.png


(PowerShell has custom colors defined for magenta and (dark) yellow. Weird.... I never use PoS.)

On a hunch, I tried toggling the value for ForceV2. Surprise! When ForceV2=0, Take Command uses the values under [TabColors]. When ForceV2=1, Take Command ignores them. Bug?
 
On a hunch, I tried toggling the value for ForceV2. Surprise! When ForceV2=0, Take Command uses the values under [TabColors]. When ForceV2=1, Take Command ignores them. Bug?
I have ForceV2 = 1 in HKCU\Console and in every subkey, including one for each TCC, 24~27. I know the INI values are being used because when I changed TabColor00 as I suggested you do, my TCMD background changed from black to white.

I'd like to know what "retrieve a color palette from the console" means.

Here's a command that might help folks make sense of what's in the INI file. I believe I got these back to the defaults (with some effort).

Code:
v:\> do l in /P (type %_ininame | findstr /r TabColor...) (echo %@word["=",0,%l] RGB = %@format[06,%@eval[%@word["=",1,%l]=h]])
TabColor00 RGB = 000000
TabColor01 RGB = 800000
TabColor02 RGB = 008000
TabColor03 RGB = 808000
TabColor04 RGB = 000080
TabColor05 RGB = 800080
TabColor06 RGB = 008080
TabColor07 RGB = C0C0C0
TabColor08 RGB = 808080
TabColor09 RGB = FF0000
TabColor10 RGB = 00FF00
TabColor11 RGB = FFFF00
TabColor12 RGB = 0000FF
TabColor13 RGB = FF00FF
TabColor14 RGB = 00FFFF
TabColor15 RGB = FFFFFF
 
I have ForceV2 = 1 in HKCU\Console and in every subkey, including one for each TCC, 24~27. I know the INI values are being used because when I changed TabColor00 as I suggested you do, my TCMD background changed from black to white.

Well, I'm confused. It doesn't work for me when ForceV2=1. Different versions of Windows, perhaps? Mine is Windows 10 v1809.

I'd like to know what "retrieve a color palette from the console" means.

I think it means GetConsoleScreenBufferInfoEx(). At least that's the only way I know to do it.

Here's a command that might help folks make sense of what's in the INI file. I believe I got these back to the defaults (with some effort).

Code:
v:\> do l in /P (type %_ininame | findstr /r TabColor...) (echo %@word["=",0,%l] RGB = %@format[06,%@eval[%@word["=",1,%l]=h]])
TabColor00 RGB = 000000
TabColor01 RGB = 800000
TabColor02 RGB = 008000
TabColor03 RGB = 808000
TabColor04 RGB = 000080
TabColor05 RGB = 800080
TabColor06 RGB = 008080
TabColor07 RGB = C0C0C0
TabColor08 RGB = 808080
TabColor09 RGB = FF0000
TabColor10 RGB = 00FF00
TabColor11 RGB = FFFF00
TabColor12 RGB = 0000FF
TabColor13 RGB = FF00FF
TabColor14 RGB = 00FFFF
TabColor15 RGB = FFFFFF

COLORREFs. Everyone else on the planet uses RGB, so of course Microsoft has to do it bassackwards. Incidentally, I believe you can use hex values in the .INI file, provided you give them a leading 0X.
 
I'm using 10.0.19042.746 (2009, 20H2).

The values in the INI file are RGBs, but in decimal.
 
I'm using 10.0.19042.746 (2009, 20H2).

The values in the INI file are RGBs, but in decimal.
I guess they're not RGBs. For a very long time I thought 1,2,4 were R,G,B ... possibly because of the 31, 32, 34 in VT control sequences (but those didn't come from Microsoft). I hope it sinks in!
 
I guess they're not RGBs. For a very long time I thought 1,2,4 were R,G,B ... possibly because of the 31, 32, 34 in VT control sequences (but those didn't come from Microsoft). I hope it sinks in!

RBG - Ruth Bader Ginsburg
BGR - Microsoft
RGB - everyone else
 
RBG - Ruth Bader Ginsburg
BGR - Microsoft
RGB - everyone else
My misunderstanding goes way back ... to MSDOS, ANSI.SYS, and 4DOS. I may never get it straight.

Charles, have you any more speculation on why TCMD uses my INI file color palette and not yours?
 

Similar threads

Back
Top