Skip to content

Detect background color and use a light theme as appropriate #464

Open

Description

@lzybkr

From garegin16 on September 4, 2016 14:53

I didn't try other linuxes, but the default typing color for centos 7 in gnome terminal is yellow.

Copied from original issue: PowerShell/PowerShell#2183

Activity

  1. lzybkr commented on Nov 9, 2016

    @lzybkr
    ContributorAuthor

    From sergei (@vors) on September 5, 2016 18:47

    Does it look like these screenshots #1036 ?

  2. lzybkr commented on Nov 9, 2016

    @lzybkr
    ContributorAuthor

    From garegin16 on September 5, 2016 20:6

    Yes. It's even worse on my screen. It looks bright yellow. I can't see anything

  3. lzybkr commented on Nov 9, 2016

    @lzybkr
    ContributorAuthor

    From sergei (@vors) on September 5, 2016 20:9

    Can you post a screenshot?

    As a workaround, you can set background color to black or anything dark.

  4. lzybkr commented on Nov 9, 2016

    @lzybkr
    ContributorAuthor

    From Joel Bennett (@Jaykul) on September 6, 2016 0:35

    Can we turn this into a request for PSReadline to detect the background and choose an appropriate default set of colors -- unless they have been set by the user?

    For that matter, is there any chance that we could get PSReadline to use some sort of configuration file rather than needing a long profile script to set all the colors? Especially now that we have (potentially) access to 256 xterm colors or even 16bit full color, and/or support for bold, etc...

    Yellow on white is not right,
    Nor is blue on black.
    Wise color choices are great.

  5. lzybkr commented on Nov 9, 2016

    @lzybkr
    ContributorAuthor

    From David R. Williamson (@drwill-ms) on September 17, 2016 2:13

    Same for me on OSX. Very bright yellow text on a white background. Only text I type.

  6. lzybkr commented on Nov 9, 2016

    @lzybkr
    ContributorAuthor

    From garegin16 on September 18, 2016 2:59

    Huh. It didn't do that on my os x install. The text is black by default.

    Sent from my iPhone

    On 16 Sep 2016, at 10:13 PM, David R. Williamson notifications@github.com wrote:

    Same for me on OSX. Very bright yellow text on a white background. Only text I type.

    —
    You are receiving this because you authored the thread.
    Reply to this email directly, view it on GitHub, or mute the thread.

  7. lzybkr commented on Nov 9, 2016

    @lzybkr
    ContributorAuthor

    From Steve Lee (@SteveL-MSFT) on November 1, 2016 19:2

    Joel Bennett (@Jaykul) I like your suggestion, can you open an issue in http://github.com/lzybkr/psreadline

  8. lzybkr commented on Nov 9, 2016

    @lzybkr
    ContributorAuthor

    From fnvogt1954 on November 5, 2016 15:46

    Power Shell command background seems to take on the value of the most recently used color of the screen background.
    Discovered this by accident.
    I can see my yellow commands against a darker background. I was using white as my background, then I changed it to a darker green, too dark, so I lightened it up to a nice shade of blue. Screen Snippet attached ,
    ps_yellow_command_letters_on_dark_background
    PS_Yellow_command_letters_on_dark_background.png.
    Now that I have something that is workable, but not great, I am afraid to tweak it more, have to move on to more urgent work.
    Major Minor Build Revision


    5 1 14393 206

  9. lzybkr commented on Nov 4, 2017

    @lzybkr
    ContributorAuthor

    It looks like it is possible to detect the background color on CentOS and possibly other systems, see here. This will make it possible to create light and dark themes.

  10. changed the title [-]the default typing color for text is yellow in centos, barely visible[/-] [+]Detect background color and use a light theme as appropriate[/+] on Nov 4, 2017
  11. milindsaraswala commented on Aug 23, 2018

    @milindsaraswala

    I am late to the party but I found the article which make your mac terminal window same like windows PowerShell. By Setting Profile. Please follow this below article
    https://info.sapien.com/index.php/quickguides/setting-up-powershell-on-your-mac

  12. gpunktschmitz commented on Nov 11, 2018

    @gpunktschmitz

    changing the background color to the default dark blue it has on windows would solve the issue. the issue here is $Host.UI.RawUI.BackgroundColor only takes colors of "System.ConsoleColor" which does not have this very blue. if pwsh would default to this background color (on linux) would be a huge win for every user.

  13. rkeithhill commented on Nov 11, 2018

    @rkeithhill
    Contributor

    If PSRL changed my terminal/console color from my preferred color scheme, I wouldn't be too happy with that.

  14. gpunktschmitz commented on Nov 11, 2018

    @gpunktschmitz

    If PSRL changed my terminal/console color from my preferred color scheme, I wouldn't be too happy with that.

    I totally understand your point. but I am more annoyed when I cannot read/use pwsh. I would prefer a default that works - that can be changed to personal preferences. rather than having to figure out why one cannot read/work with pwsh and how to change it to be readable. especially for new users this feels like a huge gap.

  15. SteveL-MSFT commented on Nov 11, 2018

    @SteveL-MSFT
    Member

    I think one way to solve this is to have themes support which includes the background color. You can set it once in your profile. It doesn't seem there is a universal way to programmatically get the current background color across all distros/OS's so I don't think we should try to solve that problem. We can start with dark, light, and Windows PowerShell themes.

  16. lzybkr commented on Nov 12, 2018

    @lzybkr
    ContributorAuthor

    I think theme support would be great, but I wonder if that belongs in PSReadLine or elsewhere.

    Note there are other projects introducing themes, e.g. https://github.com/mmims/PSConsoleTheme and maybe Joel Bennett (@Jaykul) has something else.

  17. SteveL-MSFT commented on Nov 12, 2018

    @SteveL-MSFT
    Member

    It would make sense to be separate if it works independently and cross-platform. Unfortunately, PSConsoleTheme is currently Windows only.

  18. Jaykul commented on Nov 26, 2018

    @Jaykul

    Console themes are a mess. Add in Windows PowerShell's weird custom color scheme, and it's a nearly unfixable mess.

    On Windows, traditionally, you can set the 16-color palette using proprietary APIs -- which is why PSConsoleTheme et. al. are Windows-only. The current beta of Pansies has (Windows-only) themes that use those Windows-only APIs and include support for PSReadLine and the PowerShell default error/warning colors, etc. They work fine, but ...

    There is no way to make that cross-platform yet.

    The only way there ever will be, is to use the OSC escape sequences to set the console palette, but that would require full implementations of OSC4, OSC10 and OSC11 on Windows and on all the third-party terminals you wanted to support. We need all three to be able to to set the palette and choose the default foreground and background colors -- additionally, we would need QUERY support to be able to detect the background color without explicitly setting it.

    Unfortunately, that support just isn't there in most places. According to the superuser thread Jason Shirk (@lzybkr) linked earlier, they work in some versions of xTerm, but they don't work in the default Ubuntu terminal. On Windows (even in tmux) only the OSC4 is implemented, but without query support and with no documentation (well, one of my teammates added some documentation for Windows, but it's just what we were able to discover on our own).

    Without query support, and with no way to set the default background and foreground, we would just have to assume that the background is 0 (black), and foreground is 15 (white) -- which results in really awful, pink backgrounds with yellow text in the default Windows PowerShell window, because it abused those color indexes for it's dark blue background and light gray foreground instead of using the actual dark blue and light gray color indexes.

    Importantly, this is terminal-specific.

    Even without taking operating systems into account, there's no way to change or detect the 16-color palette that works reliably across terminal apps. On Windows 10 the new escape sequences work on the same level as the APIs, so they have no effect in ConEmu or Console2 or Hyper ... each of which has it's own way to handle it. On Linux and Mac different terminals have different implementations -- as you can see on the superuser thread 😖

  19. Jaykul commented on Nov 26, 2018

    @Jaykul

    For what it's worth, my intention is to alter the theme support in PANSIES with support for sending the escape sequences on non-Windows platforms, in hopes that they'll work cross-platform. I may also take that functionality into a separate module, because themes don't necessarily need Windows 10 or RGB support 😉

  20. uladz-zubrycki commented on Feb 8, 2021

    @uladz-zubrycki

    Just encountered that issue using PowerShell Core 7.1.1 on Windows Terminal with Solarized Light theme (slightly customized). Syntax is highlighted with yellow and isn't visible at all.

    This is how [System.Reflection.AssemblyName]::GetAssemblyName($PathToAssembly).FullName looks like
    image

    Update:
    Fixed by editing %userprofile%\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 and choosing colors looking nice on my terminal schema, but it still would be nice to add support for light schemes out of the box.

    Set-PSReadLineOption -Colors @{
       "Default"   = [ConsoleColor]::Black
       "Parameter" = [ConsoleColor]::Black
       "Type"      = [ConsoleColor]::DarkBlue
       "Number"    = [ConsoleColor]::Magenta
       "String"    = [ConsoleColor]::Magenta
       "Comment"   = [ConsoleColor]::Yellow
       "Variable"  = [ConsoleColor]::Green
       "Keyword"   = [ConsoleColor]::Blue
       "Operator"  = [ConsoleColor]::Blue
       "Command"   = [ConsoleColor]::Blue
       "Member"    = [ConsoleColor]::Blue
       "Error"     = [ConsoleColor]::Red
    }
    

    image

  21. Skuldo commented on Apr 1, 2021

    @Skuldo

    Tried it on a fresh Mac OS install with a white terminal background, PS cmdlets are yellow, .NET classes are pale grey and their properties are an even paler grey - it's pretty unusable!

  22. JustPlayground commented on Dec 1, 2025

    @JustPlayground

    Almost 10 years.

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-Enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions