1

So I set up my new laptop with both powershell 5.1 to powershell 7 and I just have this weird problem with powershell 7 where it highlights the background of the text which I just don't like.

I do not face this problem with powershell 5.1. I tried to change that background in the color scheme in "settings.json" to an alpha channel for transparency but powershell doesn't accept rgba values so it errors out.

Here's an example image of the problem I'm facing

PowerShell 7: Powershell V7

PowerShell 5.1: Powershell 5.1

Please help me resolve this issue :)

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    See [about_ANSI_Terminals](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_ansi_terminals?view=powershell-7.3) added in 7.3 and the new `$PSStyle` – jfrmilner Feb 15 '23 at 14:24
  • Sorry man I don't understand, I checked the documentation but I can't figure out how to turn off that background color – Mynameisaname Feb 15 '23 at 15:42
  • Your 5.1 has folder symbols, something mine does not. Plus, I have no colors, just gray text on blue background. Is there some type of PowerShell customization to get those features? If yes, is there then a 7.x version of that customization? If yes again, then maybe applying that customization to 7.x would fix it. – Darin Feb 15 '23 at 16:08
  • Is this the customization used in 5.1? Will this work in 7.x? https://learn.microsoft.com/en-us/windows/terminal/tutorials/custom-prompt-setup – Darin Feb 15 '23 at 16:43
  • 1
    It'll be `$PSStyle.FileInfo.Directory` try something like `$PSStyle.FileInfo.Directory = "\`e[4;1m"` or disable with `$PSStyle.OutputRendering = "Plaintext"` – jfrmilner Feb 15 '23 at 16:54
  • 1
    @Darin, thanks for your help brother, and yes I customised it with Oh my Posh and I'm currently using the dracula theme, I did try using the same customisations and profile of the 5.1 version but the text highlighting was the problem, but the solution by jfrmilner worked out pretty well. – Mynameisaname Feb 15 '23 at 19:02
  • @Mynameisaname, glad you are getting it solved! – Darin Feb 15 '23 at 19:10
  • 1
    @Darin, you were right about the fact that just by setting the profile to the one of that in 5.1 would also solve the error. It took some troubleshooting to get it to work but it did – Mynameisaname Feb 15 '23 at 19:37
  • @Mynameisaname, I was thinking it would overwrite/replace whatever setting was causing the problem. More of a shotgun approach instead of hunting down the exact issue. – Darin Feb 15 '23 at 19:48

1 Answers1

0

PowerShell 7.2 introduced the automatic variable $PSStyle for a new feature called PSAnsiRendering. You can use ANSI rendering to control text decorations, such as colour and font styling, in PowerShell. See Get-Help about_ANSI_Terminals for more information.

This includes File Info formatting when using Get-Childitem, you can alter the formatting with $PSStyle.FileInfo.Directory for example

$PSStyle.FileInfo.Directory = "`e[4;1m"

Or disable with

$PSStyle.OutputRendering = "Plaintext"

If you'd like to keep this consistent for each session then you'll need to add it to your PowerShell profile script.

jfrmilner
  • 1,458
  • 10
  • 11
  • Thank you so much for your help man, I would like to mention though that adding it to the profile would be a must so you don't have to go through the hassle of typing it everytime in the terminal but since I use terminal icons in my user profile, it seems to remove it itself. However if one doesn't then it is a must. Again, Thank you so much – Mynameisaname Feb 15 '23 at 19:39