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:
And when I run this:
print -P '%B%F{red}co%F{green}lo%F{blue}rs%f%b'
I get the expected:
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?
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.
Related
The following line of code appears in a python source file. It appears exactly like this when the file is opened up in VS Code and in vi (as well as this text edit block). When I cat the file, the green square is replaced by several non-ascii characters. My question is how does one create a line of text with a swatch of some arbitrary color?
'correct_place': '🟩',
🟩 ("Large Green Square") is actually an emoji. Every emoji has a unicode number. The unicode number for 🟩 is U+1F7E9.
You can open a file in VSCode, copy the emoji above and paste it in that file (using the regular copy and paste commands on your computer, like command+C command+V).
You can also use the echo command in a Linux terminal to write this emoji into a file by using 🟩's unicode number, for example:
$ echo -e '\U0001F7E9' >> sizzzzlerz.txt
$ cat sizzzzlerz.txt
🟩
I want to change the Xterm background color based on what branch I'm currently in. Is there a good way to automate this?
Currently I'm changing the profile by hand. And I find it a bit annoying that google couldn't provide me with an answer. Everyone seems settled by just changing the prompt.
You could start with "fixing the prompt": some of those answers deal with modifying the (bash or zsh) prompts to send escape sequences which change the window title. The background color for xterm would be just another escape sequence, part of the same group of Operating System Commands:
OSC Ps ; Pt BEL
OSC Ps ; Pt ST
Set Text Parameters. For colors and font, if Pt is a "?", the
control sequence elicits a response which consists of the con-
trol sequence which would set the corresponding value. The
dtterm control sequences allow you to determine the icon name
and window title.
...
The 10 colors (below) which may be set or queried using 1 0
through 1 9 are denoted dynamic colors, since the correspond-
ing control sequences were the first means for setting xterm's
colors dynamically, i.e., after it was started. They are not
the same as the ANSI colors. These controls may be disabled
using the allowColorOps resource. At least one parameter is
expected for Pt. Each successive parameter changes the next
color in the list. The value of Ps tells the starting point
in the list. The colors are specified by name or RGB specifi-
cation as per XParseColor.
...
Ps = 1 0 -> Change VT100 text foreground color to Pt.
Ps = 1 1 -> Change VT100 text background color to Pt.
With xterm (not necessarily for "xterm" imitators...),
printf '\033]11;blue\007'
printf '\033]11;white\007'
changes the window background to blue and then white.
Unlike settings for "ANSI colors", the dynamic colors persist, will not be reset by other escape sequences.
Oddly, xterm: how to change the background color? suggests "two" (actually one) different way for setting the background color, but that's not useful for your purpose.
In powershell under W10, when I type cd "xxxx", the "xxxx" are not visible on the screen (the cursor moves but the characters print in the same color as the background). When I type the first double quote then the > at the beginning of the line turns red and when I type final quotes it turns back to white and the rest of the line is visible.
For example if I type:
>cd "Desktop" Hello
I get:
>cd Hello
My powershell used to work well until yesterday... Do you know how to correct this bug?
Edit
I found out why this happens, it has to do with the palette in the Colors tab.
If you edit the values in the palette when choosing your text/background colors (which I did by accident), you can change the color of quoted strings.
The 4th value is the one related to quoted strings:
Hope it helps!
Old solution
The command below suggested by TravisEz13 works.
remove-module psreadline
But it also removes the nice syntax highlight. It's local solution, you'll have to do it every time you open a new PowerShell session.
Has anyone been able to do this successfully? As far as I can tell this is very difficult because gnome-terminal lacks an option to disable "use bright as bold". Which means that:
$ echo "\e[1;31mred" # bold, color #1 (red)
and
$ echo "\e[31mred" # no bold, color #1 (red)
will use different colors (the former will actually use color #9, 'bright red'), whereas 16 color themes depend on this not happening.
You can get around it by doing:
$ echo "\e[1;38;5;1mred"
which will display bold text with color #1, not color #9, but many existing apps don't do this, and rely on "\e[1;31mred" being red.
Barring modifying all terminal applications that use color to use the 38 code method, is there any way to get gnome-terminal to work w/ these themes?
I can change console background color by script:
$host.UI.RawUI.BackgroundColor = "Black"
but in this case I'm limited to preset number of defined colors and unfortunately one I'm looking for is not here. There is option to pick color from console GUI (right click on top Windows PowerShell bar->properties->Colors). Unfortunately (again) only BackGroundColor and ForeGroundColor can be changed there, no way to change one of $host.privatedata colors there.
Is there possibility to put hex coded color via script somehow?
there is a registry hack here : http://stackingcode.com/blog/2011/11/14/zenburn-powershell
In my view, Powershell should allow you to set colors to a rgb hex value rather than the predefined set of colors. But design questions aside, the way I worked around this was to create a .reg file to redefine the "color buckets" (which they call ColorTables) that Powershell uses. The code below includes comments indicating what the specific ColorTable controls in Powershell.
Notes:
To save your current colors first, open regedit and export HKCU\Console.
Save the code below to a file (e.g. colors.reg), and run it.
Create a shortcut pointing to powershell. Run it. It should have new colors.
To modify colors, set the appropriate ColorTableXX dword to the hex value, but note, the RGB values are actually BGR, and they need to be padded with 00 in front of the number. So a blue color, #4286f4, would have a dword of 00f48642.
colors.reg:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Console]
; BACKGROUND
"ColorTable07"=dword:00efefef
; ERROR BACKGROUND
"ColorTable00"=dword:00efefef
;ERROR
"ColorTable12"=dword:00255ffc
; STATIC TEXT (PROMPT and OUTPUT) AND COMMAND ARGUMENT
"ColorTable01"=dword:00472713
; COMMAND TEXT
"ColorTable14"=dword:00c56e36
; COMMAND TEXT SELECTED
"ColorTable09"=dword:00ef47d3
; COMMAND FLAG
"ColorTable08"=dword:00a53733
; COMMAND FLAG SELECTED
"ColorTable15"=dword:00ef47d3
; COMMMAND ARGUMENT SELECTED
"ColorTable06"=dword:00ef47d3
; COMMAND VARIABLE (e.g. $profile)
"ColorTable10"=dword:00a53733
; COMMAND VARIABLE SELECTED
"ColorTable13"=dword:00ef47d3
; deep purple -- not sure what this is
"ColorTable04"=dword:00660566
; brown -- not sure what this is
"ColorTable05"=dword:00336699
; purple -- not sure what this is
"ColorTable11"=dword:00845f84
; green -- not sure what this is
"ColorTable02"=dword:00339933
; pastel lavendar -- not sure what this is
"ColorTable03"=dword:00FF9999