1

In PowerShell >6.0 I can change the command line FOREGROUND colors with:

Set-PSReadLineOption -Colors @{ Keyword="#0FAFE0"; Variable="#987ABC" }+

but how do I change the BACKGROUND colors with RGB??? (#RRGGBB)
i can see some examples with ASCII console sequences
but none with the RGB format

ZEE
  • 2,931
  • 5
  • 35
  • 47
  • Does this answer your question? [How to set Powershell background color programmatically to RGB Value](https://stackoverflow.com/questions/18685772/how-to-set-powershell-background-color-programmatically-to-rgb-value) – stackprotector Jul 25 '20 at 06:59

1 Answers1

4

I don't think you can? SelectionColor uses the ansi escape code for black on white: "`e[30;47m" (ps 7 for the `e). https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

How about this from that wikipeda page:

ESC[ 38;2;⟨r⟩;⟨g⟩;⟨b⟩ m -- choose RGB foreground color

ESC[ 48;2;⟨r⟩;⟨g⟩;⟨b⟩ m -- choose RGB background color

Red foreground (255 0 0) blue (0 0 255) background.

Set-PSReadLineOption -Colors @{ variable = "`e[38;2;255;0;0m" + # fg
                                           "`e[48;2;0;0;255m" } # bg

In ps5 you have to say $([char]0x1b) instead of `e.

$e = [char]0x1b
Set-PSReadLineOption -Colors @{ variable = "$e[38;2;255;0;0m" + # fg
                                           "$e[48;2;0;0;255m" } # bg
js2010
  • 23,033
  • 6
  • 64
  • 66
  • That's exactly that... meanwhile I read the very interesting Wikipedia article about the history of ANSI control sequences... and I recommend it -> "https://en.wikipedia.org/wiki/ANSI_escape_code" – ZEE Jul 27 '20 at 20:42
  • I'm not clear on that `Select` part. Is that a PS command or where does it come from? – Konrad Viltersten Aug 08 '21 at 10:08
  • @KonradViltersten That's just a quote from the wikipedia docs. – js2010 Aug 08 '21 at 12:10
  • Ah. hahaha. so silly of me. In the markdown, it appeared colored as if it was a keyword, or something. I tried it and googled it but couldn't find anything on it. The site thought probably that you were writing a SQL statement or something. – Konrad Viltersten Aug 08 '21 at 19:29