Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lzybkr opened this issue Nov 9, 2016 · 20 comments
Open

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

lzybkr opened this issue Nov 9, 2016 · 20 comments
Labels
Issue-Enhancement It's a feature request.

Comments

@lzybkr
Copy link
Member

lzybkr commented Nov 9, 2016

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

@lzybkr
Copy link
Member Author

lzybkr commented Nov 9, 2016

From @vors on September 5, 2016 18:47

Does it look like these screenshots #1036 ?

@lzybkr
Copy link
Member Author

lzybkr commented Nov 9, 2016

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

@lzybkr
Copy link
Member Author

lzybkr commented Nov 9, 2016

From @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.

@lzybkr
Copy link
Member Author

lzybkr commented Nov 9, 2016

From @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.

@lzybkr
Copy link
Member Author

lzybkr commented Nov 9, 2016

From @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.

@lzybkr
Copy link
Member Author

lzybkr commented Nov 9, 2016

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.

@lzybkr
Copy link
Member Author

lzybkr commented Nov 9, 2016

From @SteveL-MSFT on November 1, 2016 19:2

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

@lzybkr
Copy link
Member Author

lzybkr commented Nov 9, 2016

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

@lzybkr
Copy link
Member Author

lzybkr commented Nov 4, 2017

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.

@lzybkr lzybkr added Issue-Enhancement It's a feature request. and removed Issue-Discussion labels Nov 4, 2017
@lzybkr lzybkr 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 Nov 4, 2017
@lzybkr lzybkr mentioned this issue Nov 4, 2017
@milindsaraswala
Copy link

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

@gpunktschmitz
Copy link

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.

@rkeithhill
Copy link
Contributor

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

@gpunktschmitz
Copy link

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.

@SteveL-MSFT
Copy link
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.

@lzybkr
Copy link
Member Author

lzybkr commented Nov 12, 2018

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 @Jaykul has something else.

@SteveL-MSFT
Copy link
Member

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

@Jaykul
Copy link

Jaykul commented Nov 26, 2018

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 @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 😖

@Jaykul
Copy link

Jaykul commented Nov 26, 2018

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 😉

@uladz-zubrycki
Copy link

uladz-zubrycki commented Feb 8, 2021

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

@Skuldo
Copy link

Skuldo commented Apr 1, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement It's a feature request.
Projects
None yet
Development

No branches or pull requests

8 participants