![]() |
Qt 4.8
|
Outputs colored messages to stderr.
More...
Outputs colored messages to stderr.
ColorOutput is a convenience class for outputting messages to stderr using color escape codes, as mandated in ECMA-48. ColorOutput will only color output when it is detected to be suitable. For instance, if stderr is detected to be attached to a file instead of a TTY, no coloring will be done.
ColorOutput does its best attempt. but it is generally undefined what coloring or effect the various coloring flags has. It depends strongly on what terminal software that is being used.
When using echo -e 'my escape sequence', \033 works as an initiator but not when printing from a C++ program, despite having escaped the backslash. That's why we below use characters with value 0x1B.
It can be convenient to subclass ColorOutput with a private scope, such that the functions are directly available in the class using it.
To output messages, call write() or writeUncolored(). write() takes as second argument an integer, which ColorOutput uses as a lookup key to find the color it should color the text in. The mapping from keys to colors is done using insertMapping(). Typically this is used by having enums for the various kinds of messages, which subsequently are registered.