Qt 4.8
ColorOutput Class Reference

Outputs colored messages to stderr. More...

Detailed Description

Outputs colored messages to stderr.

Since
4.4
Note
This class or function is not reentrant.
Warning
This function is not part of the public interface.

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.

Usage

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.

enum MyMessage
{
Important
};
ColorOutput output;
output.insertMapping(Error, ColorOutput::RedForeground);
output.insertMapping(Import, ColorOutput::BlueForeground);
output.write("This is important", Important);
output.write("Jack, I'm only the selected official!", Error);
See also
{http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html} {Bash Prompt HOWTO, 6.1. Colours} {http://linuxgazette.net/issue51/livingston-blade.html} {Linux Gazette, Tweaking Eterm, Edward Livingston-Blade} {http://www.ecma-international.org/publications/standards/Ecma-048.htm} {Standard ECMA-48, Control Functions for Coded Character Sets, ECMA International}, {http://en.wikipedia.org/wiki/ANSI_escape_code} {Wikipedia, ANSI escape code} {http://linuxgazette.net/issue65/padala.html} {Linux Gazette, So You Like Color!, Pradeep Padala}

The documentation for this class was generated from the following file: