In terminal emulators, bash fails to render correct background color #113

Closed
opened 2026-01-30 21:42:40 +00:00 by claunia · 18 comments
Owner

Originally created by @bitcrazed on GitHub (Feb 16, 2018).

From @Elderry on July 17, 2017 8:2

My Windows build number: Microsoft Windows [Version 10.0.15063]

It seems that in many terminal emulators, after running a command that outputs colors to the terminal using bash, the background will become a strange gray or black. But the default Windows Console doesn't has this problem. Here are the examples:

Integrated Terminal of Visual Studio Code:
1

Integrated Terminal of Intellij IDEA:
2

Default Windows Console:
3

To provide more detail, here is my bash prompt:

BLUE='\e[1;34m'
GREEN='\e[1;32m'
RESET='\e[0m'
source $HOME/Projects/Personal/posh-git-sh/git-prompt.sh
PROMPT_COMMAND='__posh_git_ps1 "" "${BLUE}\w\n${GREEN}\u@\h${RESET} > "'

Copied from original issue: Microsoft/WSL#2344

Originally created by @bitcrazed on GitHub (Feb 16, 2018). _From @Elderry on July 17, 2017 8:2_ My Windows build number: Microsoft Windows [Version 10.0.15063] It seems that in many terminal emulators, after running a command that outputs colors to the terminal using bash, the background will become a strange gray or black. But the default Windows Console doesn't has this problem. Here are the examples: Integrated Terminal of Visual Studio Code: <img width="614" alt="1" src="https://user-images.githubusercontent.com/1892221/28259432-d27e19b6-6b08-11e7-896a-871dd8f8327b.PNG"> Integrated Terminal of Intellij IDEA: <img width="653" alt="2" src="https://user-images.githubusercontent.com/1892221/28259448-e142b574-6b08-11e7-8b2e-9e8516e5b6fa.PNG"> Default Windows Console: <img width="732" alt="3" src="https://user-images.githubusercontent.com/1892221/28259457-ef355344-6b08-11e7-9d6e-842abc040733.PNG"> To provide more detail, here is my bash prompt: ``` BLUE='\e[1;34m' GREEN='\e[1;32m' RESET='\e[0m' source $HOME/Projects/Personal/posh-git-sh/git-prompt.sh PROMPT_COMMAND='__posh_git_ps1 "" "${BLUE}\w\n${GREEN}\u@\h${RESET} > "' ``` _Copied from original issue: Microsoft/WSL#2344_
claunia added the Resolution-Fix-Available label 2026-01-30 21:42:40 +00:00
Author
Owner

@bitcrazed commented on GitHub (Feb 16, 2018):

From @zadjii-msft on July 17, 2017 16:35

I believe this is already fixed in Insider's builds - I believe it's a dupe of #1706

image

@bitcrazed commented on GitHub (Feb 16, 2018): _From @zadjii-msft on July 17, 2017 16:35_ I believe this is already fixed in Insider's builds - I believe it's a dupe of #1706 ![image](https://user-images.githubusercontent.com/18356694/28278851-631833ca-6ad3-11e7-8d4e-04adc73455bc.png)
Author
Owner

@bitcrazed commented on GitHub (Feb 16, 2018):

From @Elderry on October 18, 2017 5:50

@zadjii-msft I'm afraid this issue remains, today my Windows updated to: Microsoft Windows [Version 10.0.16299.19], and I reinstalled Ubuntu using Microsoft Store.
capture

@bitcrazed commented on GitHub (Feb 16, 2018): _From @Elderry on October 18, 2017 5:50_ @zadjii-msft I'm afraid this issue remains, today my Windows updated to: Microsoft Windows [Version 10.0.16299.19], and I reinstalled Ubuntu using Microsoft Store. ![capture](https://user-images.githubusercontent.com/1892221/31702705-529b8390-b40b-11e7-895c-4508b842fba9.JPG)
Author
Owner

@bitcrazed commented on GitHub (Feb 16, 2018):

From @zadjii-msft on October 18, 2017 15:56

Hmm. That's certainly weird.

@Elderry Can you open a powershell window, and post a screenshot of the colors tab of the property sheet?

image
image

@bitcrazed commented on GitHub (Feb 16, 2018): _From @zadjii-msft on October 18, 2017 15:56_ Hmm. That's certainly weird. @Elderry Can you open a powershell window, and post a screenshot of the colors tab of the property sheet? ![image](https://user-images.githubusercontent.com/18356694/31728796-21319f34-b3e2-11e7-88b2-b0de3d66e5fe.png) ![image](https://user-images.githubusercontent.com/18356694/31728801-2851809a-b3e2-11e7-90a1-b0fcab62a893.png)
Author
Owner

@bitcrazed commented on GitHub (Feb 16, 2018):

From @Elderry on October 19, 2017 1:25

@zadjii-msft Here it is:
capture

@bitcrazed commented on GitHub (Feb 16, 2018): _From @Elderry on October 19, 2017 1:25_ @zadjii-msft Here it is: ![capture](https://user-images.githubusercontent.com/1892221/31749941-7a6c989c-b4af-11e7-9c02-0d7e6b9afb1e.JPG)
Author
Owner

@bitcrazed commented on GitHub (Feb 16, 2018):

From @zadjii-msft on October 19, 2017 15:22

@Elderry Okay, this is gonna sound crazy, but what happens if you switch the first and last values of the color table in the Powershell properties dialog, and instead choose the first color (now white) as your "Screen Background" and the last (now black) as the "Screen Text", then open a new vscode?

@bitcrazed commented on GitHub (Feb 16, 2018): _From @zadjii-msft on October 19, 2017 15:22_ @Elderry Okay, this is gonna sound crazy, but what happens if you switch the first and last values of the color table in the Powershell properties dialog, and instead choose the first color (now white) as your "Screen Background" and the last (now black) as the "Screen Text", then open a new vscode?
Author
Owner

@bitcrazed commented on GitHub (Feb 16, 2018):

From @Elderry on October 23, 2017 2:1

@zadjii-msft I did as you say, nothing changes:
2

@bitcrazed commented on GitHub (Feb 16, 2018): _From @Elderry on October 23, 2017 2:1_ @zadjii-msft I did as you say, nothing changes: ![2](https://user-images.githubusercontent.com/1892221/31869214-1180c22c-b7d9-11e7-9fe9-02c115e9c19c.JPG)
Author
Owner

@bitcrazed commented on GitHub (Feb 16, 2018):

From @zadjii-msft on October 23, 2017 17:30

Okay shoot. I was hoping that might help. Can you try pasting this file into a file called 256color.pl and running it (with perl 256color.pl) in both the console window and the vscode window?

@bitcrazed commented on GitHub (Feb 16, 2018): _From @zadjii-msft on October 23, 2017 17:30_ Okay shoot. I was hoping that might help. Can you try pasting [this file](https://gist.githubusercontent.com/hSATAC/1095100/raw/ee5b4d79aee151248bdafa8b8412497a5a688d42/256color.pl) into a file called `256color.pl` and running it (with `perl 256color.pl`) in both the console window and the vscode window?
Author
Owner

@bitcrazed commented on GitHub (Feb 16, 2018):

From @Elderry on October 24, 2017 1:30

It looks terrible in vscode's terminal:
1

@bitcrazed commented on GitHub (Feb 16, 2018): _From @Elderry on October 24, 2017 1:30_ It looks terrible in vscode's terminal: ![1](https://user-images.githubusercontent.com/1892221/31920842-0714ce62-b89e-11e7-96d7-afad487a0671.JPG)
Author
Owner

@bitcrazed commented on GitHub (Feb 16, 2018):

From @Elderry on October 24, 2017 1:38

@zadjii-msft Seems it is an upstream issue caused by winpty referred here.

@bitcrazed commented on GitHub (Feb 16, 2018): _From @Elderry on October 24, 2017 1:38_ @zadjii-msft Seems it is an upstream issue caused by winpty referred [here](https://github.com/rprichard/winpty/issues/108).
Author
Owner

@bitcrazed commented on GitHub (Feb 16, 2018):

From @zadjii-msft on October 24, 2017 16:1

Oh, that's not the issue I was mostly concerned about. I was more concerned about the white and black entries in the first 8 colors printed are reversed in VScode from what you'd expect.

I think I have an idea of how this happened. If you look in the registry, under Computer\HKEY_CURRENT_USER\Console, is ScreenColors set to 0xf0 (240)?

I think VSCode is using the console defaults, not the properties. So because your default color selection is Color00 (dark_black) text on Color15 (bright_white) background, and VScode changes 00->white and 15-> black, your "default" colors in vscode are white on black, even if the rest of the background is white.

If you really want black text on white for all of your terminals, then I'd just replicate VSCode's behavior in your defaults manually, and switch the first and last entries of the "Defaults" in the console settings.

@bitcrazed commented on GitHub (Feb 16, 2018): _From @zadjii-msft on October 24, 2017 16:1_ Oh, that's not the issue I was mostly concerned about. I was more concerned about the white and black entries in the first 8 colors printed are reversed in VScode from what you'd expect. I think I have an idea of how this happened. If you look in the registry, under `Computer\HKEY_CURRENT_USER\Console`, is `ScreenColors` set to 0xf0 (240)? I think VSCode is using the console *defaults*, not the *properties*. So because your default color selection is Color00 (dark_black) text on Color15 (bright_white) background, and VScode changes 00->white and 15-> black, your "default" colors in vscode are white on black, even if the rest of the background is white. If you really want black text on white for all of your terminals, then I'd just replicate VSCode's behavior in your defaults manually, and switch the first and last entries of the "Defaults" in the console settings.
Author
Owner

@bitcrazed commented on GitHub (Feb 16, 2018):

From @Elderry on October 25, 2017 2:16

@zadjii-msft You are right, my ScreenColors entry is set to 0xf0, and other things happen just like you say. I prefer to keep my current settings because switching entries will change the definition of my DARK_BLACK and BRIGHT_WHITE. Thank you for your time.

Now my problem is why vscode choose to changes 00->white and 15->black, even Intellij IDEA's integrated terminal does the same.

@bitcrazed commented on GitHub (Feb 16, 2018): _From @Elderry on October 25, 2017 2:16_ @zadjii-msft You are right, my `ScreenColors` entry is set to `0xf0`, and other things happen just like you say. I prefer to keep my current settings because switching entries will change the definition of my `DARK_BLACK` and `BRIGHT_WHITE`. Thank you for your time. Now my problem is why vscode choose to changes 00->white and 15->black, even Intellij IDEA's integrated terminal does the same.
Author
Owner

@Elderry commented on GitHub (May 5, 2018):

It seem this issued is fixed in windows 10 1803.

@Elderry commented on GitHub (May 5, 2018): It seem this issued is fixed in windows 10 1803.
Author
Owner

@davy-tw commented on GitHub (May 8, 2018):

@Elderry how this get fixed on 1803?
It still happened on my vscode with 1803

@davy-tw commented on GitHub (May 8, 2018): @Elderry how this get fixed on 1803? It still happened on my vscode with 1803
Author
Owner

@Elderry commented on GitHub (May 9, 2018):

I tested it again and confirmed 1803 fixed part of this issue.

capture

@david50407 You can compare this capture to the above, the mainly difference is that the black background no longer overflow. Though white and black entries are still reversed, the pain point for me no longer exists.

@Elderry commented on GitHub (May 9, 2018): I tested it again and confirmed 1803 fixed part of this issue. <img width="758" alt="capture" src="https://user-images.githubusercontent.com/1892221/39791283-67611c84-536d-11e8-97db-51ef5c4654f7.PNG"> @david50407 You can compare this capture to the above, the mainly difference is that the black background no longer overflow. Though white and black entries are still reversed, the pain point for me no longer exists.
Author
Owner

@davy-tw commented on GitHub (May 9, 2018):

@Elderry oh ok thanks

But the color cube still broken in 3rd-party terminal simulators...
It seems that Windows doesn't provide enough API to get the 256 color information to let these simulators to paint the correct color

@davy-tw commented on GitHub (May 9, 2018): @Elderry oh ok thanks But the color cube still broken in 3rd-party terminal simulators... It seems that Windows doesn't provide enough API to get the 256 color information to let these simulators to paint the correct color
Author
Owner

@miniksa commented on GitHub (May 9, 2018):

Correct, our API ReadConsoleOutput and friends doesn't provide the ability to read this information out of the screen buffer. VSCode uses WinPTY which scrapes this information out of our buffer with the console APIs.

We've been focusing on #57 instead to allow 3rd-party terminals to receive this information on a standard PTY stream like other platforms instead.

@miniksa commented on GitHub (May 9, 2018): Correct, our API `ReadConsoleOutput` and friends doesn't provide the ability to read this information out of the screen buffer. VSCode uses WinPTY which scrapes this information out of our buffer with the console APIs. We've been focusing on #57 instead to allow 3rd-party terminals to receive this information on a standard PTY stream like other platforms instead.
Author
Owner

@zadjii-msft commented on GitHub (May 9, 2018):

Thanks @Elderry for confirming that this is fixed in 1803.

I'm going to close this as resolved, @miniksa is right about the 256 color stuff.

@zadjii-msft commented on GitHub (May 9, 2018): Thanks @Elderry for confirming that this is fixed in 1803. I'm going to close this as resolved, @miniksa is right about the 256 color stuff.
Author
Owner

@Elderry commented on GitHub (Oct 4, 2018):

I'm sad to say that this issue re-occurred in Windows 10 1809.
capture
You can see that in VScode's terminal, there are white characters on black background, while this is reversed in 1803.
@zadjii-msft

@Elderry commented on GitHub (Oct 4, 2018): I'm sad to say that this issue re-occurred in Windows 10 1809. ![capture](https://user-images.githubusercontent.com/1892221/46460063-64602800-c7ed-11e8-9ac9-16fe5c1e1e5c.jpg) You can see that in VScode's terminal, there are white characters on black background, while this is reversed in 1803. @zadjii-msft
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#113