The code for the accepted project code is as follows:
$str .= $ok ? "\033[0;32;40m OK \033[0m " : "\033[0;31;40m ERROR \033[0m ";
What does this writing mean and what do you want to do?
Reply to discussion (solution)
? : This is an operator. it is a whole, called a conditional operator. it works similar to the if else statement max = (a> B )? A: B; equivalent to if (a> B) {max = a;} else {max = B ;}
? : Ternary operator
$ Str. = $ OK? "\ 033 [0; 32; 40 m OK \ 033 [0 m": "\ 033 [0; 31; 40 m ERROR \ 033 [0 m ";
Equivalent
If ($ OK ){
$ Str. = "\ 033 [0; 32; 40 m OK \ 033 [0 m ";
} Else {
$ Str. = "\ 033 [0; 31; 40 m ERROR \ 033 [0 m ";
}
\ 033 10 in decimal 27, ASCII name Esc, generally used as the device control command leading
Https://code.google.com/p/conemu-maximus5/wiki/AnsiEscapeCodes
AnsiEscapeCodes is introduced in detail, mainly responsible for terminal output.
30 m Black (foreground color)
31 m red (foreground)
32 m Green (foreground)
33 m yellow (foreground)
34 m blue (foreground)
35 m purple (foreground)
36 m dark green (foreground)
37 m White (foreground)
40 m Black (background color)
41 m red (background color)
42 m green (background color)
In general, it is the place where the content is hit, and then view it in linux, there will be a color, highlight and other prompts.
For example, logs can be used in this way. it is convenient to analyze logs and view logs.