php achieve the command line output colored text

Today, when you are prompted to perform composer's command inside the window that appears with some critical part of the color, so very curious to study a little, here recorded

In fact, at the command line output with ANSI color escape character font is mainly used to achieve, we look at an example:

? <
 Echo "\ 033 [38; 5; 1M red text \ 033 [0m";

display:

In the terminal, ANSI defined Escape code for controlling a screen display screen in the format:

\ 033 [ 38 is;. 5;. 1 m red text \ 033 [ 0 m

     Representatives began Settings tab

     On behalf of setup is complete label

     On behalf of setup parameters

     On behalf of the characters to be displayed

Here the start and end tags are fixed, the start tag is "\ 033 [" the meaning is the end tag "m" section in which the parameters can be set according to the parameters in the following table

Code effect Remark
0 Reset / Normal Close all the properties.
1 Bold or increase strength  
2 Weakening (decreased strength) Not widely supported.
3 Italic Not widely supported. Sometimes viewed as reverse video.
4 Underline  
5 Slow flashing Below 150 beats per minute.
6 Fast flashing MS-DOS ANSI.SYS; 150 per minute or more; not widely supported.
7 Anti-significant Foreground and background color exchange.
8 hide Not widely supported.
9 In addition to planning Character clear, but marked for deletion. Not widely supported.
10 The main (default) font  
11–19 Font substitution Selects a substitute font {\ DisplayStyle-n-10} {\displaystyle n-10}.
20 Sharp body Almost no support.
21 Close bold or underlined double Close bold is not widely supported; double underline almost no support.
22 Normal color or intensity Not strong not weak.
23 Non-italics, non-angular body  
24 Close underscore Remove single and double underlined.
25 Close Flashing  
27 Close reverse display  
28 Close Hide  
29 In addition to draw close  
30–37 Set the foreground color See the following color table.
38 Set the foreground color The next parameter is 5;nor 2;r;g;b, below.
39 The default foreground color Realized by a specifically defined (according to standard).
40–47 Set the background color See the following color table.
48 Set the background color The next parameter is 5;nor 2;r;g;b, below.
49 The default background color Realized by a specifically defined (according to standard).
51 Framed  
52 Encircled  
53 Overline  
54 Not framed or encircled  
55 Close overline  
60 Underline the right line or ideograms Almost no support.
61 Ideograms double underline or double line on the right
62 Or scribe line on the left ideogram
63 Ideographic double scribe lines or the left-bis
64 Ideographic signs focus
65 Ideographic property Close Reset 60- 64of all effect.
90–97 Set the foreground color bright aixterm (non-standard).
100–107 Set bright background color aixterm (non-standard).

The table we can see that the parameter set 38 represent foreground set 5 represents the color setting mode is represented by 256 colors 1 that color indication of

In addition to setting the color property outside we can also set other attributes such as underline, and not every property need to set a number of parameters, such as the underscore attribute directly we can add two 4 friends

? < PHP
 echo "\ 033 [38; 5; 1; 4M red text \ 033 [0m";

Note: Due to the different terminals each system, provided it is inactive, or some effect will be different, the final results to the actual display subject!

Guess you like

Origin www.cnblogs.com/itsuibi/p/11121628.html