Skip to content

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

Closed

Description

@Elderry

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} > "'

Activity

  1. changed the title [-]In terminals emulators, bash fails to render correct background color[/-] [+]In terminal emulators, bash fails to render correct background color[/+] on Jul 17, 2017
  2. zadjii-msft commented on Jul 17, 2017

    @zadjii-msft
    Member

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

    image

  3. Elderry commented on Oct 18, 2017

    @Elderry
    Author

    Mike Griese (@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

  4. zadjii-msft commented on Oct 18, 2017

    @zadjii-msft
    Member

    Hmm. That's certainly weird.

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

    image
    image

  5. Elderry commented on Oct 19, 2017

    @Elderry
    Author
  6. zadjii-msft commented on Oct 19, 2017

    @zadjii-msft
    Member

    Ruiyang Li (@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?

  7. Elderry commented on Oct 23, 2017

    @Elderry
    Author

    Mike Griese (@zadjii-msft) I did as you say, nothing changes:
    2

  8. zadjii-msft commented on Oct 23, 2017

    @zadjii-msft
    Member

    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?

  9. Elderry commented on Oct 24, 2017

    @Elderry
    Author

    It looks terrible in vscode's terminal:
    1

  10. Elderry commented on Oct 24, 2017

    @Elderry
    Author

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

  11. zadjii-msft commented on Oct 24, 2017

    @zadjii-msft
    Member

    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.

  12. Elderry commented on Oct 25, 2017

    @Elderry
    Author

    Mike Griese (@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.

  13. bitcrazed commented on Feb 16, 2018

    @bitcrazed
    Contributor

    This issue was moved to microsoft/terminal#88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions