Skip to content

Default color instead of white as foreground #13342

Closed

Description

@ADIX7

Windows Terminal version

1.14.1451.0

Windows build number

10.0.19043.0

Other Software

No response

Steps to reproduce

With this tool you can render the color palett

Console.WriteLine("Hello, World!");
for (var i = 0; i < 8; i++)
{
    Console.ForegroundColor = (ConsoleColor)i;
    Console.Write("Hello, World!");
    Console.ForegroundColor = (ConsoleColor)(i + 8);
    Console.WriteLine("\tHello, World!");
}

Console.WriteLine();

for (var i = 0; i < 8; i++)
{
    Console.ForegroundColor = (ConsoleColor)ShiftColor(i);
    Console.BackgroundColor = (ConsoleColor)i;
    Console.Write("Hello, World!");

    Console.ResetColor();
    Console.Write("\t");

    Console.ForegroundColor = (ConsoleColor)ShiftColor(i + 8);
    Console.BackgroundColor = (ConsoleColor)(i + 8);
    Console.Write("Hello, World!");
    Console.ResetColor();
    Console.WriteLine();
}

static int ShiftColor(int c)
{
    var result = c + 8;
    while (result > 15) result = c -= 8;
    while (result < 0) result = c += 8;

    return result;
}

Expected Behavior

When using white as foreground color, white ("white" attribute in scheme config) should be used instead of the "default" foreground ("foreground" attribute in scheme config)

Actual Behavior

Currently the default foreground color is used even when the foreground color is set to white.

After running in the attached snippet it is obvious that the white foreground (1st block 1st column last row) and the white background (2nd block 1st column last row) are not the same, on the other hand the first "Hello World" has the same colors as the one with white foreground (1st block 1st column last row)

kép

Activity

  1. ADIX7 commented on Jun 20, 2022

    @ADIX7
    Author

    Actually, based on this image it looks like the black background is also not correct as it uses the default background color.

  2. zadjii-msft commented on Jun 20, 2022

    @zadjii-msft
    Member

    This seems like it's just a disconnect between the legacy Console colors, which only had 16 values (and the foreground & background were each one of those 16), vs the model the Terminal uses. The Terminal uses a 16-color palette, and then the FG & BG are separate colors in addition to the color table.

    You know what, looking closer, I'm betting this is the automatic lightness adjustment. Could you share your settings.json file/?

  3. ADIX7 commented on Jun 20, 2022

    @ADIX7
    Author

    MyTheme is the color scheme.

    {
        "$help": "https://aka.ms/terminal-documentation",
        "$schema": "https://aka.ms/terminal-profiles-schema",
        "actions": 
        [
            {
                "command": 
                {
                    "action": "splitPane",
                    "split": "right"
                },
                "keys": "ctrl+alt+2"
            },
            {
                "command": 
                {
                    "action": "splitPane",
                    "split": "down"
                },
                "keys": "ctrl+alt+5"
            }
        ],
        "defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
        "profiles": 
        {
            "defaults": 
            {
                "colorScheme": "ADIX",
                "font": 
                {
                    "face": "CaskaydiaCove NF"
                },
                "opacity": 80,
                "useAcrylic": true
            },
            "list": 
            [
                {
                    "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
                    "hidden": false,
                    "name": "PowerShell",
                    "source": "Windows.Terminal.PowershellCore"
                },
                {
                    "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                    "hidden": false,
                    "name": "cmd"
                },
                {
                    "commandline": "gsudo \"C:\\Program Files\\PowerShell\\7\\pwsh.exe\"",
                    "guid": "{c3d1834f-b861-54a3-89fb-1c13f2363d95}",
                    "hidden": false,
                    "icon": "ms-appx:///ProfileIcons/{574e775e-4f2a-5b96-ac1e-a2962a402336}.png",
                    "name": "PowerShell (admin)",
                    "startingDirectory": "%USERPROFILE%"
                },
                {
                    "commandline": "gsudo %SystemRoot%\\System32\\cmd.exe",
                    "guid": "{0ad3d447-8f3d-513c-99e1-447b1dcda84a}",
                    "hidden": false,
                    "icon": "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
                    "name": "Command Prompt (admin)",
                    "startingDirectory": "%USERPROFILE%"
                },
                {
                    "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                    "hidden": false,
                    "name": "Windows PowerShell"
                },
                {
                    "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                    "hidden": false,
                    "name": "Azure Cloud Shell",
                    "source": "Windows.Terminal.Azure"
                },
                {
                    "guid": "{a3a2e83a-884a-5379-baa8-16f193a13b21}",
                    "hidden": false,
                    "name": "PowerShell 7 Preview",
                    "source": "Windows.Terminal.PowershellCore"
                },
                {
                    "guid": "{dc505395-c460-59d1-93a6-434a5808d193}",
                    "hidden": false,
                    "name": "Developer Command Prompt for VS 2022",
                    "source": "Windows.Terminal.VisualStudio"
                },
                {
                    "guid": "{d050a9e6-e1c2-5609-9f92-4c711743606d}",
                    "hidden": false,
                    "name": "Developer PowerShell for VS 2022",
                    "source": "Windows.Terminal.VisualStudio"
                }
            ]
        },
        "schemes": 
        [
            {
                "background": "#002B36",
                "black": "#171421",
                "blue": "#2A7BDE",
                "brightBlack": "#5E5C64",
                "brightBlue": "#308DFF",
                "brightCyan": "#33C7DE",
                "brightGreen": "#33D17A",
                "brightPurple": "#C061CB",
                "brightRed": "#F66151",
                "brightWhite": "#FFFFFF",
                "brightYellow": "#FFFD00",
                "cursorColor": "#FFFFFF",
                "cyan": "#2AA1B3",
                "foreground": "#839496",
                "green": "#26A269",
                "name": "MyTheme",
                "purple": "#A347BA",
                "red": "#C01C28",
                "selectionBackground": "#FFFFFF",
                "white": "#D0CFCC",
                "yellow": "#CECB00"
            },
            {
                "background": "#0C0C0C",
                "black": "#0C0C0C",
                "blue": "#0037DA",
                "brightBlack": "#767676",
                "brightBlue": "#3B78FF",
                "brightCyan": "#61D6D6",
                "brightGreen": "#16C60C",
                "brightPurple": "#B4009E",
                "brightRed": "#E74856",
                "brightWhite": "#F2F2F2",
                "brightYellow": "#F9F1A5",
                "cursorColor": "#FFFFFF",
                "cyan": "#3A96DD",
                "foreground": "#CCCCCC",
                "green": "#13A10E",
                "name": "Campbell",
                "purple": "#881798",
                "red": "#C50F1F",
                "selectionBackground": "#FFFFFF",
                "white": "#CCCCCC",
                "yellow": "#C19C00"
            },
            {
                "background": "#012456",
                "black": "#0C0C0C",
                "blue": "#0037DA",
                "brightBlack": "#767676",
                "brightBlue": "#3B78FF",
                "brightCyan": "#61D6D6",
                "brightGreen": "#16C60C",
                "brightPurple": "#B4009E",
                "brightRed": "#E74856",
                "brightWhite": "#F2F2F2",
                "brightYellow": "#F9F1A5",
                "cursorColor": "#FFFFFF",
                "cyan": "#3A96DD",
                "foreground": "#CCCCCC",
                "green": "#13A10E",
                "name": "Campbell Powershell",
                "purple": "#881798",
                "red": "#C50F1F",
                "selectionBackground": "#FFFFFF",
                "white": "#CCCCCC",
                "yellow": "#C19C00"
            },
            {
                "background": "#282C34",
                "black": "#282C34",
                "blue": "#61AFEF",
                "brightBlack": "#5A6374",
                "brightBlue": "#61AFEF",
                "brightCyan": "#56B6C2",
                "brightGreen": "#98C379",
                "brightPurple": "#C678DD",
                "brightRed": "#E06C75",
                "brightWhite": "#DCDFE4",
                "brightYellow": "#E5C07B",
                "cursorColor": "#FFFFFF",
                "cyan": "#56B6C2",
                "foreground": "#DCDFE4",
                "green": "#98C379",
                "name": "One Half Dark",
                "purple": "#C678DD",
                "red": "#E06C75",
                "selectionBackground": "#FFFFFF",
                "white": "#DCDFE4",
                "yellow": "#E5C07B"
            },
            {
                "background": "#FAFAFA",
                "black": "#383A42",
                "blue": "#0184BC",
                "brightBlack": "#4F525D",
                "brightBlue": "#61AFEF",
                "brightCyan": "#56B5C1",
                "brightGreen": "#98C379",
                "brightPurple": "#C577DD",
                "brightRed": "#DF6C75",
                "brightWhite": "#FFFFFF",
                "brightYellow": "#E4C07A",
                "cursorColor": "#4F525D",
                "cyan": "#0997B3",
                "foreground": "#383A42",
                "green": "#50A14F",
                "name": "One Half Light",
                "purple": "#A626A4",
                "red": "#E45649",
                "selectionBackground": "#FFFFFF",
                "white": "#FAFAFA",
                "yellow": "#C18301"
            },
            {
                "background": "#002B36",
                "black": "#4F6066",
                "blue": "#268BD2",
                "brightBlack": "#47565C",
                "brightBlue": "#839496",
                "brightCyan": "#93A1A1",
                "brightGreen": "#586E75",
                "brightPurple": "#6C71C4",
                "brightRed": "#CB4B16",
                "brightWhite": "#FDF6E3",
                "brightYellow": "#657B83",
                "cursorColor": "#FFFFFF",
                "cyan": "#2AA198",
                "foreground": "#839496",
                "green": "#859900",
                "name": "Solarized Dark",
                "purple": "#D33682",
                "red": "#DC322F",
                "selectionBackground": "#FFFFFF",
                "white": "#EEE8D5",
                "yellow": "#B58900"
            },
            {
                "background": "#FDF6E3",
                "black": "#002B36",
                "blue": "#268BD2",
                "brightBlack": "#073642",
                "brightBlue": "#839496",
                "brightCyan": "#93A1A1",
                "brightGreen": "#586E75",
                "brightPurple": "#6C71C4",
                "brightRed": "#CB4B16",
                "brightWhite": "#FDF6E3",
                "brightYellow": "#657B83",
                "cursorColor": "#002B36",
                "cyan": "#2AA198",
                "foreground": "#657B83",
                "green": "#859900",
                "name": "Solarized Light",
                "purple": "#D33682",
                "red": "#DC322F",
                "selectionBackground": "#FFFFFF",
                "white": "#EEE8D5",
                "yellow": "#B58900"
            },
            {
                "background": "#000000",
                "black": "#000000",
                "blue": "#3465A4",
                "brightBlack": "#555753",
                "brightBlue": "#729FCF",
                "brightCyan": "#34E2E2",
                "brightGreen": "#8AE234",
                "brightPurple": "#AD7FA8",
                "brightRed": "#EF2929",
                "brightWhite": "#EEEEEC",
                "brightYellow": "#FCE94F",
                "cursorColor": "#FFFFFF",
                "cyan": "#06989A",
                "foreground": "#D3D7CF",
                "green": "#4E9A06",
                "name": "Tango Dark",
                "purple": "#75507B",
                "red": "#CC0000",
                "selectionBackground": "#FFFFFF",
                "white": "#D3D7CF",
                "yellow": "#C4A000"
            },
            {
                "background": "#FFFFFF",
                "black": "#000000",
                "blue": "#3465A4",
                "brightBlack": "#555753",
                "brightBlue": "#729FCF",
                "brightCyan": "#34E2E2",
                "brightGreen": "#8AE234",
                "brightPurple": "#AD7FA8",
                "brightRed": "#EF2929",
                "brightWhite": "#EEEEEC",
                "brightYellow": "#FCE94F",
                "cursorColor": "#000000",
                "cyan": "#06989A",
                "foreground": "#555753",
                "green": "#4E9A06",
                "name": "Tango Light",
                "purple": "#75507B",
                "red": "#CC0000",
                "selectionBackground": "#FFFFFF",
                "white": "#D3D7CF",
                "yellow": "#C4A000"
            },
            {
                "background": "#000000",
                "black": "#000000",
                "blue": "#000080",
                "brightBlack": "#808080",
                "brightBlue": "#0000FF",
                "brightCyan": "#00FFFF",
                "brightGreen": "#00FF00",
                "brightPurple": "#FF00FF",
                "brightRed": "#FF0000",
                "brightWhite": "#FFFFFF",
                "brightYellow": "#FFFF00",
                "cursorColor": "#FFFFFF",
                "cyan": "#008080",
                "foreground": "#C0C0C0",
                "green": "#008000",
                "name": "Vintage",
                "purple": "#800080",
                "red": "#800000",
                "selectionBackground": "#FFFFFF",
                "white": "#C0C0C0",
                "yellow": "#808000"
            }
        ]
    }
  4. DHowett commented on Jun 20, 2022

    @DHowett
    Member

    Automatic lightness is disabled in all public builds... hmm.

    This looks like an explicit choice on behalf of the .NET folks, because it is totally possible using a non-.NET application to select the "white" color.

  5. ADIX7 commented on Jun 20, 2022

    @ADIX7
    Author

    I found this problem while using a custom prompt application (https://github.com/JanDeDobbeleer/oh-my-posh/) written in GO, so it is not a .NET specific thing. Can anyone with any programming language create a sample where white foreground looks as expected and not the default "foreground"?

  6. zadjii-msft commented on Jun 20, 2022

    @zadjii-msft
    Member

    printf "\x1b[0mDefault\n\x1b[37mWhite-on-default\x1b[m\n\x1b[37;47mWhite-on-white\x1b[m\n"

    image

    In a color scheme where default FG is black, not white:
    image

  7. ADIX7 commented on Jun 20, 2022

    @ADIX7
    Author

    kép

  8. DHowett commented on Jun 20, 2022

    @DHowett
    Member

    There is a process policy that applies only to powershell that translates White FG and Black BG to Default and Default, owing to a bug they shipped in Windows. That issue is documented in #6810.

    I suspect that is why Mike tested it with bash. Notably: this quirk only applies to executables named powershell.exe and pwsh.exe.

  9. zadjii-msft commented on Jun 20, 2022

    @zadjii-msft
    Member

    Meh, that's not why - I'm just quicker on the draw in bash 😄 But that was my next theory as well. So, basically this is a duplicate of #6807?

  10. DHowett commented on Jun 20, 2022

    @DHowett
    Member

    It shouldn't be. Again, it only applies to executables named pwsh.exe and powershell.exe... ADIX's Go binary is certainly not named that, nor is dotnet.exe...

  11. ADIX7 commented on Jun 20, 2022

    @ADIX7
    Author

    Hmmmmm, it might be the prompt app only generates the prompt as a string but at the end powershell is the one writing it...
    Jan De Dobbeleer (@JanDeDobbeleer) can you help with this?

    Also, it's funny, if you check my settings.json I have a profile for "admin powershell" with "commandline": "gsudo \"C:\\Program Files\\PowerShell\\7\\pwsh.exe\"", and it does work as it should be.

    Disclamer: it's not my prompt app, I'm just using it.

    kép

  12. zadjii-msft commented on Jun 20, 2022

    @zadjii-msft
    Member

    I'm under the impression that's exactly how oh-my-posh works. It just informs pwsh how to format the prompt, pwsh.exe is still the thing writing the prompt to the terminal.

    In the gsudo case, the actual root process attached to the console is gsudo, not pwsh, so the compat shim doesn't trigger.

    But Dustin's got a good point, the repro script above shouldn't be triggering this compat shim at all. That's weird.

  13. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on Jun 20, 2022
  14. ghost added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Jun 20, 2022
  15. ADIX7 commented on Jun 20, 2022

    @ADIX7
    Author

    Is there anything I can use to disable this functionality? Some escape sequence at the beginning of the string?

  16. DHowett commented on Jun 20, 2022

    @DHowett
    Member

    Hmm. As a quick fix, you can use indexed colors 0 and 7 from the 256-color palette:

    image

  17. ghost added
    Needs-Author-FeedbackThe original author of the issue/PR needs to come back and respond to something
    on Jun 20, 2022
  18. ADIX7 commented on Jun 21, 2022

    @ADIX7
    Author

    Unfortunately oh-my-posh does not support the 256-color palett. But it is a good idea, thank you, I will create a feature request there!

  19. ghost added
    Needs-AttentionThe core contributors need to come back around and look at this ASAP.
    on Jun 21, 2022
  20. ghost removed
    Needs-Author-FeedbackThe original author of the issue/PR needs to come back and respond to something
    on Jun 21, 2022
  21. JanDeDobbeleer commented on Jun 21, 2022

    @JanDeDobbeleer

    Yes, oh-my-posh provides a string to PowerShell which writes it. I'm however not planning to add support for 256 colors as we already have hex support (which is 256) and tbh not many end users will want to/understand ANSI escape sequences. Adding that is also a challenge.

    Let me get the conditions straight. When in powershell and Windows Terminal, I should replace the two white colors with index 0 and 7? Because that I can do. If someone could help me map the right values, that would be ace. Right now we have the following:

    • White FG: \e[37m
    • Black BG: \e[40m
  22. DHowett commented on Jun 21, 2022

    @DHowett
    Member

    Honestly, it might be better to wait for #13352 to land. You won't need to think about what colors should map to which indices any longer after that's been released broadly!

    For completeness, though: my original recommendation was going to be to map White FG to \e[38;2;7m and Black BG to \e[48;2;0m. Since those aren't the sequences that PowerShell was using, we didn't have to break those -- they continue to mean "actually white foreground" and "actually black background".

    I'm gonna close this as a /dupe of #6807, since it looks like that's what it ended up being!

  23. ghost closed this as completedon Jun 21, 2022
  24. ghost removed
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Jun 21, 2022
  25. ghost added
    Resolution-DuplicateThere's another issue on the tracker that's pretty much the same thing.
    on Jun 21, 2022
  26. ghost removed
    Needs-Tag-FixDoesn't match tag requirements
    on Jun 21, 2022
  27. ghost removed
    Needs-AttentionThe core contributors need to come back around and look at this ASAP.
    on Jun 21, 2022
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

    Issue-BugIt either shouldn't be doing this or needs an investigation.Resolution-DuplicateThere's another issue on the tracker that's pretty much the same thing.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions