简体   繁体   中英

Does “%{\033[0m%}” (code zero) reset the font color to “tput setaf” or to Xterm default color?

I know that you can use escape sequence %{\\033[0m%} (code zero) to change the color of the prompt back to "default" color (usually, after the prompt).

But what is the "default" that is used for this?

  1. Default color of the terminal program itself?
  2. Default color set via tput setaf $COLOR , assuming you use it to set font color different from terminal's default color?
  3. Else?

It's terminal-dependent, but with regard to existing practice, it would have to be the former:

  1. the default color of the terminal (program).

The other suggested choice would not be correct, since tput setaf does not set a "default color", but rather a "current color". Whether any choice of tput setaf corresponds to the terminal's default color is (at best) terminal-specific, since there is no relevant standard one way or the other.

ECMA 48 gives terse (one line) descriptions of SGR 0 (which is what's mentioned in the question), and SGR 30-37 , 40-47 (the setaf/setab choices commonly used for terminal descriptions that tput would use).

There's another possible choice, ie, tput op (selecting the original color pair ), which is used in several terminal descriptions to send SGR 39 and 49 . Again, this is terminal-specific and its relationship to SGR 0 is not covered by any standard. Those happen to use the same "default color" for xterm and Linux console, but (read ECMA-48) the standard does not give that level of detail regarding "default color" and the absence of "video attributes".

Further reading:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM