Read the current text color in a xterm

前端 未结 4 570
情话喂你
情话喂你 2021-01-30 02:43

I\'m writing various utilities, and I\'m really liking colorized text. Nothing fancy, just using escape sequences. I\'ve created a simple class that has a pprint(msg, color) fun

4条回答
  •  清酒与你
    2021-01-30 03:31

    I don't believe that's possible and it's unlikely to be portable if it were. The best you can do is send sgr0 which resets all attributes to default (not previous). On xterms, sgr0 is Esc[m. If you want to reset the colors and not affect other attributes, send op which on xterms is Esc[39;49m.

    These codes should not be hardcoded. You should use terminfo, termcap or [n]curses.

提交回复
热议问题