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

Output of ls or Get-ChildItem has unexpected bg color for directories names #18550

Closed
5 tasks done
ExtremeGTX opened this issue Nov 13, 2022 · 16 comments
Closed
5 tasks done
Labels
Resolution-Answered The question is answered.

Comments

@ExtremeGTX
Copy link

Prerequisites

Steps to reproduce

Hello pwsh team,

Please check the screenshot below:
image

I have empty profile file under Documents\PowerShell\Microsoft.PowerShell_profile.ps1 also no modules under Documents\PowerShell\Modules\ .
Could you please tell me where else should i check for such configuration?

Thanks

Expected behavior

Directories names has a transparent background color

Actual behavior

Directories names has a blue background color

Error details

No response

Environment data

PS C:\Program Files> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

@ExtremeGTX ExtremeGTX added the Needs-Triage The issue is new and needs to be triaged by a work group. label Nov 13, 2022
@237dmitry
Copy link

237dmitry commented Nov 14, 2022

Configure $PSStyle For example white directory color:

$PSStyle.FileInfo.Directory = "`e[38;2;255;255;255m"

@jhoneill
Copy link

jhoneill commented Nov 14, 2022

You will discover some other colouring applied to items in directory output - which you probably don't want either

if ($pstyle) {
  $psstyle.FileInfo.Directory = $psstyle.FileInfo.Executable = $psstyle.FileInfo.SymbolicLink  = "" 
  $PSStyle.FileInfo.Extension.Clear()
  $PSStyle.Formatting.TableHeader       = ""
  $PsStyle.Formatting.FormatAccent      = ""
}

Is a useful add on to many profiles. The powers that be believe most people want their directories to be blue because bash makes them blue, but it blue on black breaks the accessibility requirements for contrast so they have selected white on blue. A search should find the discussion on this. The important thing is you can set things exactly how you want them to be.

@Liturgist
Copy link

If there is a desire to "do it like bash does it," then how about putting a [System.IO.Path]::DirectorySeparatorChar at the end of directory names?

@SteveL-MSFT SteveL-MSFT added Resolution-Answered The question is answered. and removed Needs-Triage The issue is new and needs to be triaged by a work group. labels Nov 14, 2022
@ThomasNieto
Copy link
Contributor

If there is a desire to "do it like bash does it," then how about putting a [System.IO.Path]::DirectorySeparatorChar at the end of directory names?

Feel free to open a new issue/discussion on that however, the name of the property for System.IO.DirectoryInfo is Name which does not contain a /. You can however create a new formatter that adds the slash if you so desire.

@ExtremeGTX
Copy link
Author

Thanks Guys.
so, this blue color is the default of Powershell 7? if not, how can I track down where is the source of this modification?

@jhoneill
Copy link

Thanks Guys. so, this blue color is the default of Powershell 7? if not, how can I track down where is the source of this modification?

It's the default in 7.3 yes. Not in 7.2 and earlier (it was an experimental feature in 7.2). See my post above for how to control it.

If there is a desire to "do it like bash does it," then how about putting a [System.IO.Path]::DirectorySeparatorChar at the end of directory names?

Feel free to open a new issue/discussion on that however, the name of the property for System.IO.DirectoryInfo is Name which does not contain a /. You can however create a new formatter that adds the slash if you so desire.

It would be pretty easy to add / or \ along with the ansi escapes. But if someone assumes directory names contain a trailing / or \ then they will complain that what is displayed doesn't match the property.

@ExtremeGTX
Copy link
Author

That's answers my question, Thanks @jhoneill

@garretwilson
Copy link

garretwilson commented Nov 18, 2022

It's the default in 7.3 yes. Not in 7.2 and earlier …

So what was the default in 7.2 and earlier? Was it just normal text, or was it white? I frankly don't remember.

@ThomasNieto
Copy link
Contributor

@garretwilson There was no color, the color was determined by your console/terminal text color setting.

@garretwilson
Copy link

Thanks, @ThomasNieto . So how do I tell PowerShell to go back to using the "no specific color". I don't want to set a new color. I want to tell PowerShell to go back to not having a special color for directories.

@ThomasNieto
Copy link
Contributor

@garretwilson look at @jhoneill comment. His code snippet does that.

@garretwilson
Copy link

Well it's mixed in with several things. Not that it's not helpful. But to clarify, are you saying that it's this part? (I like to separate out and understand what I'm doing.)

$PSStyle.FileInfo.Directory = "" 

@jhoneill
Copy link

@garretwilson the to turn all the colours off you can set
$PSStyle.OutputRendering = "PlainText"

Otherwise the noticeable update in 7.3 is that
$psstyle.FileInfo.Directory, $psstyle.FileInfo.Executable and $psstyle.FileInfo.SymbolicLink now contain escape sequences for Directories links and executables. You can choose your own if you don't like the PowerShell team's choice, I find none at all is best.

For other items $PSStyle.FileInfo.Extension holds the file extension and the escape sequence. Clear() removes them all. $PSStyle.FileInfo.Extension.Add(".JPG","$($PSStyle.Foreground.BrightCyan)") adds one. Again I find clear() gives the optimal combinations.

If you don't like column headings and list labels in green then $PSStyle.Formatting.TableHeader and $PsStyle.Formatting.FormatAccent contain the ansi sequence for those and I find that no-sequence is better for me

As with so much, it's very customizable if (like me) you don't like the defaults.

@jpomfret
Copy link

jpomfret commented Dec 1, 2022

This did not work well for me - apparently missed this change and just thought it was broken.

image

Unclear why this is closed? Is it being fixed in new version?

@JumBe08
Copy link

JumBe08 commented Feb 12, 2023

Rephrasing out what was said above, for someone who is being bothered by this and is landing here out of the blue, and doesn't quite grasp what is happening, hoping that it is a bit more clear.

  • Yes, since 7.3 the PowerShell started to add that background to directories
  • If you type in your PShell "$PSStyle", you'll get a list of some variables that you can customize, and the possible color codes
  • The variable that you are looking for, in the case of folders, is "FileInfo.Directory"
  • If you type what @237dmitry suggested directly in the Powershell, it will clear the background highlighting, while that shell session is active
  • To do it permanently, you can add it to your PowerShell profile, so that it is loaded every time

I found it a bit perplexing that a change like this was added, as the default behavior. Maybe there was a lot of people asking for it. Anyway, changing the background color of folders is just one of the options, it is actually pretty cool what can be done with PSStyle. I've found this blog post pretty good, explaining some neat things you can do.

@jhoneill
Copy link

jhoneill commented Feb 13, 2023

I found it a bit perplexing that a change like this was added, as the default behavior. Maybe there was a lot of people asking for it.

I have a problem reading things when there is movement, unexpected colours and a few other things on the screen, and find unix/linux seemingly random use of colours makes it much more difficult to read. There is a demand from people coming from other shells to be able to get the same colours, in particular "blue" for directory. However blue text on black fails accessibility tests for people with more common eyesight problems - who need more contrast, hence this compromise. A decision was "what seemed like a good idea to a dev at the time" colours to be opt out rather than opt in, so that people would know colour was available. I still contend that finding the opt out leaves a few people who want it off frothing-at-the-mouth angry, where an opt in would have left those who missed their linux colours feeling mild disappointment... however that argument was lost long ago. I turn it off in my profile, and if I need to test with -noprofile I work with slight nausea and the reading speed of a small child :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Answered The question is answered.
Projects
None yet
Development

No branches or pull requests

9 participants