title: How to change colors of text and background in PowerShell using Set-PSReadLineOption
body: <p>NB, the question <strong>isn't</strong> about how to set colors, as such. It's specificially and explicitly targeting color selection using <code>Set-PSReadLineOption</code> and no other method whatsoever, including 3rd party tools and what not. Furthermore, it includes altering the color of both (the text as well as the background) and requires an established syntax (such as RGB or HSV) allowing arbitrary manipulation (i.e. no enumerated, predefined literals). And yes, simply <em>it can't be done, go away</em> will be an acceptable, if not happily appreciated, reply. By other words, as far as the scope of this question goes, I'm not interested in alternative ways to affect colors in my window.</p>
  <pre><code>Currently I have setup like this.
  
  $options = @{
    HistoryNoDuplicates = $true
    ...
    Colors = @{
      &quot;Selection&quot; = &quot;#bbdd99&quot;
      ...
    }
  }
  Set-PSReadLineOption @options
  </code></pre>
  <p>It works and I'm happy with it. However, I'd like to control the background of the selected text as well. According to <a href="https://docs.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-7.1" rel="nofollow noreferrer">the docs for <code>PSReadLineOption</code></a> it's suppose to be possible and the exact example of such is provided <a href="https://docs.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-7.1#example-1--set-foreground-and-background-colors" rel="nofollow noreferrer">right here</a>.</p>
  <pre><code>Set-PSReadLineOption -Colors @{ &quot;Comment&quot;=&quot;`e[32;47m&quot; }
  </code></pre>
  <p>There's even another, more sophisticated, example <a href="https://docs.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-7.1#example-5--set-color-values-for-multiple-types" rel="nofollow noreferrer">here</a> (the second item, for &quot;string&quot;).</p>
  <pre><code>Set-PSReadLineOption -Colors @{ &quot;String&quot; = &quot;$([char]0x1b)[38;5;100m&quot; }
  </code></pre>
  <p>That's great but I simply can't for the life of me grasp how to translate that weirdly unusual syntax into the hexa-values (which a normal person can handle) for colors to be able to alter the background as well. And in case it's that weirdo for syntax that is an absolute requirement for altering the background's color, I'm equally clueless how to translate two hexadecimal values (one for the text, one for the back) into the form I'm using on my system (the first sample with <code>@options</code> variable).</p>
  <p>Who came up with that syntax anyway? Are we to understand that MS doesn't want us to horse around with colors or something?!</p>