How do zsh ansi color codes work?

I want to make my hostname on my orange terminal. How to do it?

+17
zsh zshrc
May 28 '11 at 5:30
source share
4 answers

Firstly, I’m not sure which terminal you are using or if it will even support the color orange. My supports the following: red, blue, green, cyan, yellow, magenta, black and white. And here is how I get the colors in my terminal:




You need to load the colors first using autoload . I use the following to load colors and assign them meaningful names

 #load colors autoload colors && colors for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do eval $COLOR='%{$fg_no_bold[${(L)COLOR}]%}' #wrap colours between %{ %} to avoid weird gaps in autocomplete eval BOLD_$COLOR='%{$fg_bold[${(L)COLOR}]%}' done eval RESET='%{$reset_color%}' 

You can set the host name at your invitation using the %m line. To set, say, a red host name, you would do

 ${RED}%m${WHITE}\> 

which will print something like bneil.so>

+14
May 28 '11 at 5:38 a.m.
source share

Running the following code on your terminal should indicate whether your terminal supports 256 colors.

 for COLOR in {0..255} do for STYLE in "38;5" do TAG="\033[${STYLE};${COLOR}m" STR="${STYLE};${COLOR}" echo -ne "${TAG}${STR}${NONE} " done echo done 

it also shows you the code for each color in the form 38;5;x , where x is the code for one of the 256 available colors. Also note that changing "38;5" to "48;5" will show you the equivalent of the background. Then you can use any colors that you would like to make, as indicated earlier.

+26
May 27 '13 at 10:54
source share

It is not clear in your question whether you are familiar with the idea of ​​setting up the zsh prompt, but there are problems with color codes.

There is a lot of information on the Internet. Here are three links:

They should cover both the invitation setting and the use of color codes to assign colors.

+5
May 28 '11 at 5:38
source share

Print

 <ESC>[33mHostname<ESC>[0m 

Being an escape \ x1b character

+3
May 28 '11 at 5:37 a.m.
source share



All Articles