cshell Prompt is mainly composed of two parts, one is the color definition, the other is the information display. Below we discuss these two parts separately.
color (ASCII color)
All colors are written in the form of \033[xxxm
e94ef03e18393e35354504b042ef2dd5---, xxx
are parameters separated by semicolons
C
printf("\033[31;1;4mHello\033[0m");
C++
std::cout<<"\033[31;1;4mHello\033[0m";
python3
print("\033[31;1;4mHello\033[0m")
shell
echo -e "\033[31;1;4mHello\033[0m"
font effect
Code | Effect | Note |
---|---|---|
0 | Reset / Normal | all attributes off |
1 | Bold or increased intensity | |
2 | Faint (decreased intensity) | Not widely supported. |
3 | Italic | Not widely supported. Sometimes treated as inverse. |
4 | Underline | |
5 | Slow Blink | less than 150 per minute |
6 | Rapid Blink | MS-DOS ANSI.SYS; 150+ per minute; not widely supported |
7 | [[reverse video]] | swap foreground and background colors |
8 | Conceal | Not widely supported. |
9 | Crossed-out | Characters legible, but marked for deletion. Not widely supported. |
10 | Primary(default) font | |
11–19 | Alternate font | Select alternate font n-10 |
20 | Fraktur | hardly ever supported |
twenty one | Bold off or Double Underline | Bold off not widely supported; double underline hardly ever supported. |
twenty two | Normal color or intensity | Neither bold nor faint |
twenty three | Not italic, not Fraktur | |
twenty four | Underline off | Not singly or doubly underlined |
25 | Blink off | |
27 | Inverse off | |
28 | Reveal | conceal off |
29 | Not crossed out | |
30–37 | Set foreground color | See color table below |
38 | Set foreground color | Next arguments are 5;<n> or 2;<r>;<g>; , see below |
39 | Default foreground color | implementation defined (according to standard) |
40–47 | Set background color | See color table below |
48 | Set background color | Next arguments are 5;<n> or 2;<r>;<g>; , see below |
49 | Default background color | implementation defined (according to standard) |
51 | Framed | |
52 | Encircled | |
53 | Overlined | |
54 | Not framed or encircled | |
55 | Not overlined | |
60 | ideogram underline | hardly ever supported |
61 | ideogram double underline | hardly ever supported |
62 | ideogram overline | hardly ever supported |
63 | ideogram double overline | hardly ever supported |
64 | ideogram stress marking | hardly ever supported |
65 | ideogram attributes off | reset the effects of all of 60-64 |
90–97 | Set bright foreground color | aixterm (not in standard) |
100–107 | Set bright background color | aixterm (not in standard) |
4bit color code
Only 8 colors are supported in the original specification. SGR uses 30-37 to define the foreground color and 40-47 to define the background color.
- If you want to get a black fixed rest on a white background, you can use
\033[33;47m
,30
for the foreground color and47
for the background color. - To get bright red, use
\033[1;31m
,1
for vivid. - To reset all properties, use
\033[0m
- To use bright colors directly, use 90-97 and 100-107
According to the above figure, if you want to use red foreground color and green background color, you can write: \033[31;42m
8bit color code
Foreground Color: \033[38;5;XXXm
Background Color: \033[48;5;XXXm
According to the above graph,
- If you want to use pink font, you can write it like this:
\033[38;5;206m
, 206 is its foreground color - If you want to use the morning green background, you can write:
\033[48;5;57m
, 57 is its background color
Can be combined: \033[38;5;206;48;5;57m
The approximate range of the 8bit color code is as follows:
scope | describe |
---|---|
0x00-0x07 | Standard color, same as 4bit |
0x08-0x0F | highly colored |
0x10-0xE7 | 6x6x6 space (216 colors): 16 + 36 xr + 6 xg + b (0<=r, g, b <=5) |
0xE8-0xFF | 24 shades of gray from black to white |
24bit full color system
If it supports true color
, then the color can be described in the following way:
Foreground Color: \033[38;2;<r>;<g>;<b>m
Background color: \033[48;2;<r>;<g>;<b>m
Foreground and background colors can be mixed to describe:
\033[38;2;255;82;197;48;2;155;106;0mHello
scripts to print
#!/usr/bin/python
print "\\033[XXm"
for i in range(30,37+1):
print "\033[%dm%d\t\t\033[%dm%d" % (i,i,i+60,i+60);
print "\033[39m\\033[49m - Reset colour"
print "\\033[2K - Clear Line"
print "\\033[<L>;<C>H OR \\033[<L>;<C>f puts the cursor at line L and column C."
print "\\033[<N>A Move the cursor up N lines"
print "\\033[<N>B Move the cursor down N lines"
print "\\033[<N>C Move the cursor forward N columns"
print "\\033[<N>D Move the cursor backward N columns"
print "\\033[2J Clear the screen, move to (0,0)"
print "\\033[K Erase to end of line"
print "\\033[s Save cursor position"
print "\\033[u Restore cursor position"
print " "
print "\\033[4m Underline on"
print "\\033[24m Underline off"
print "\\033[1m Bold on"
print "\\033[21m Bold off"
Terminal and message format
In cshell, the content inside %`{...%} means that it takes no space (0-width).
\e[...m
or \033[...m
for color. As described above.
The color \033[0m
is used to reset the color
prompt format
symbol | describe |
---|---|
%/ | Current working directory. |
%~ | cwd. If it starts with $HOME, that part is replaced by a ~. In addition if a directory name prefix matches a user's home directory, that part of the directory will be substituted with ~user. NOTE: The ~user substitution will only happen if the shell has performed a ~ expansion for that user name in this session. |
%c or %. | Trailing component of cwd, may be followed by by a digit to get more than one component, if it starts with $HOME, that part is replaced with a ~. |
%C | Trailing component of cwd, may be followed by a digit to get more than one component, no ~ substitution. |
%h, %!, ! | Current history event number. |
%M | The full machine hostname. |
%m | The hostname up to the first ".". |
%S (%s) | Start (stop) standout mode. |
%B (%b) | Start (stop) boldfacing mode. (Only if |
tcsh was compiled to be eight bit clean.) | |
%U (%u) | Start (stop) underline mode. (Only if |
tcsh was compiled to be eight bit clean.) | |
%t or %@ | Current time of day, in 12-hour, am/pm format. |
%T | Current time of day, in 24-hour format. |
(But see the ampm shell variable below.) | |
%p | Current time in 12-hour format, am/pm format with seconds. |
%P | Current time in 24-hour format, with seconds. |
\c | `c' is parsed the same way as in bindkey. |
^c | `c' is parsed the same way as in bindkey. |
%% | A single %. |
%n | The user name, contents of $user. |
%d | The weekday in <Day> format. |
%D | The day in dd format. |
%w | The month in <Mon> format. |
%W | The month in mm format. |
%y | The year in yy format. |
%Y | The year in yyyy format. |
%l | The line (tty) the user is logged on. |
%L | clear from prompt to end of display or end of line. |
%# | A #' if tcsh is run as a root shell, a >' if not. |
%{..%} | Include string as a literal escape sequence. Note that the enclosed escape sequence, should only be used to change terminal attributes and should not move the cursor location. Also, this cannot be the last character in the prompt string. (Available only if tcsh was compiled to be eight bit clean.) |
%? | return code of the last command executed just before the prompt. |
%R | In prompt3 this is the corrected string; in prompt2 it is the status of the parser. |
Common colors
30 - black
31 - red
32 - green
33 - yellow
34 - blue
35 - magenta
36 - cyan
37 - white
Common effects
0 - normal
1 - bold
2 - normal again
3 - background color
4 - underline the text
5 - blinking
special
If you want to use \n in prompt, you cannot define a color for it alone, otherwise the cursor will be confused.
example
set prompt="\n%{\033[0;32m%}%n @ %m:%{\033[0;33m%}%~%{\033[1;30m%} [%P]\n%{\033[0;35m%}#%{\033[0m%} " '
The effect is as follows
Quote:
ANSI-Color WIki
TCSH Manual
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。