Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color issues with zsh in wsl

So, I'm trying to setup oh-my-zsh inside a wsl terminal (using powershell as the console here, but I get the same issue in cmd). I think I setup all my colors correctly: enter image description here

And when I run this:

print -P '%B%F{red}co%F{green}lo%F{blue}rs%f%b'

I get the expected: enter image description here

But, my prompt is still wrong, as you can tell. I'm using the agnoster theme and the grey background on the pwd there should be blue.

Is there any way to see the escape sequences so I can determine if the problem is with the escape sequence vs the rendering thereof?

like image 232
Tejay Cardon Avatar asked Aug 11 '17 17:08

Tejay Cardon


People also ask

Does Windows terminal support true colors?

As Powershell clearly shows, Windows Terminal can output True-color.


1 Answers

We could examine the $PROMPT (or $PS1).

Indeed, oh-my-zsh's agnoster theme uses PROMPT_SUBST for it. So, we can get the raw escape sequences with redirecting or piping the output of print -P:

$ print $PROMPT
%{%f%b%k%}$(build_prompt)
$ print -P $PROMPT | cat -v ;# or redirect to a file as you like
^[[39m^[[0m^[[49m^[[40m^[[39m me@mycomputer ^[[44m^[[30mM-nM-^BM-0^[[30m ~ ^[[49m^[[34mM-nM-^BM-0^[[39m

These raw escape sequences; the ANSI escape codes, are well described in https://en.wikipedia.org/wiki/ANSI_escape_code#Colors. It is the CSI codes CSI n m SGR - Select Graphic Renditoin.

Try to describe the above output:

(^[[39m: The first two characters are escaped by cat -v. We've got ESC[39m.)

  • ^[[39m^[[0m^[[49m: which are from %{%f%k%b%} part of the print $PROMPT output. ^[[39m to reset default foreground color, ^[[0m reset every effect and [[49m to reset default background color.
  • ^[[40m^[[39m me@mycomputer: bg black and fg default color
  • ^[[44m^[[30m M-nM-^BM-0: bg blue and fg default color (M-nM-^BM-0 is cat -v escaped form of )

At this point, it seems that the prompt outputs a bg blue code for pwd. You could check with
print -P '%b%F{red}co%F{green}lo%F{blue}rs%f%b' (Note: the first '%b')

This means the powershell's color pallet setting does not match with the ANSI escape sequences'. We could check whether the terminal's color pallet setting is correct or not with 16colors.sh in xterm distribution if we have sh with seeing the output of sh ./16colors.sh. (An example xterm default setting's output could be found for example: https://www.in-ulm.de/~mascheck/various/xterm/16-table.html)

It seems that your powershell's Solarized(?) theme maps the ansi color sequence blue (^[[44m or ^[[34m) as grey-ish color for our eyes.

like image 81
hchbaw Avatar answered Oct 02 '22 19:10

hchbaw