UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
Utils::Console Class Reference

Class to handle console output with different styles and levels. More...

#include <Console.hxx>

Public Member Functions

 Console ()=delete
 Deleted default constructor.
 
 Console (Console const &)=delete
 Deleted copy constructor.
 
 Console (ostream_type *stream=&std::cout, int level=4)
 Constructor with stream and level parameters.
 
 ~Console ()
 Destructor.
 
void change_level (int new_level)
 Change the message level.
 
void changeLevel (int new_level)
 Change the message level.
 
void change_stream (ostream_type *new_stream)
 Change the output stream.
 
void changeStream (ostream_type *new_stream)
 Change the output stream.
 
int get_level () const
 Get the current message level.
 
int getLevel () const
 Get the current message level.
 
ostream_typeget_stream () const
 Get the current output stream.
 
ostream_typegetStream () const
 Get the current output stream.
 
void flush () const
 Flush the output stream.
 
void message (string_view msg, int msg_level=4) const
 Output a message at a specified level.
 
void semaphore (unsigned ryg, string_view msg, int msg_level=0) const
 Output a semaphore message.
 
void colors (unsigned c, string_view msg, int msg_level=0) const
 Output a message with specified colors.
 
void warning (string_view msg) const
 Output a warning message.
 
void error (string_view msg) const
 Output an error message.
 
void fatal (string_view msg) const
 Output a fatal message.
 
void black (string_view msg, int msg_level=0) const
 Output a message in black color.
 
void red (string_view msg, int msg_level=0) const
 Output a message in red color.
 
void green (string_view msg, int msg_level=0) const
 Output a message in green color.
 
void yellow (string_view msg, int msg_level=0) const
 Output a message in yellow color.
 
void blue (string_view msg, int msg_level=0) const
 Output a message in blue color.
 
void magenta (string_view msg, int msg_level=0) const
 Output a message in magenta color.
 
void cyan (string_view msg, int msg_level=0) const
 Output a message in cyan color.
 
void gray (string_view msg, int msg_level=0) const
 Output a message in gray color.
 
void black_reversed (string_view msg, int msg_level=0) const
 Output a message in black reversed color.
 
void red_reversed (string_view msg, int msg_level=0) const
 Output a message in red reversed color.
 
void green_reversed (string_view msg, int msg_level=0) const
 Output a message in green reversed color.
 
void yellow_reversed (string_view msg, int msg_level=0) const
 Output a message in yellow reversed color.
 
void blue_reversed (string_view msg, int msg_level=0) const
 Output a message in blue reversed color.
 
void magenta_reversed (string_view msg, int msg_level=0) const
 Output a message in magenta reversed color.
 
void cyan_reversed (string_view msg, int msg_level=0) const
 Output a message in cyan reversed color.
 
void gray_reversed (string_view msg, int msg_level=0) const
 Output a message in gray reversed color.
 
void set_message_style (rang::style const &s, rang::fg const &f, rang::bg const &b)
 
void setMessageStyle (rang::style const &s, rang::fg const &f, rang::bg const &b)
 
void set_warning_style (rang::style const &s, rang::fg const &f, rang::bg const &b)
 
void setWarningStyle (rang::style const &s, rang::fg const &f, rang::bg const &b)
 
void set_error_style (rang::style const &s, rang::fg const &f, rang::bg const &b)
 
void setErrorStyle (rang::style const &s, rang::fg const &f, rang::bg const &b)
 
void set_fatal_style (rang::style const &s, rang::fg const &f, rang::bg const &b)
 
void setFatalStyle (rang::style const &s, rang::fg const &f, rang::bg const &b)
 
void set_off () const
 
void setOff () const
 
void set_auto () const
 
void setAuto () const
 

Detailed Description

Class to handle console output with different styles and levels.

Note
messages are printed only if the level priority is greather than internal level stored in internal variable m_level. The method change_level set m_level in the range from -1 to 4. Each print message has a level, if level is less or equal to m_level the message is printed. Message with level=0 are high priority message that are always printed unless m_level is set to -1 which suppress all message. The default for m_level is 4 which means all messages are printed.

Constructor & Destructor Documentation

◆ Console() [1/3]

Utils::Console::Console ( )
delete

Deleted default constructor.

◆ Console() [2/3]

Utils::Console::Console ( Console const & )
delete

Deleted copy constructor.

◆ Console() [3/3]

Utils::Console::Console ( ostream_type * stream = &std::cout,
int level = 4 )
explicit

Constructor with stream and level parameters.

Parameters
streamPointer to output stream (default is std::cout).
levelMinimum message level to output (default is 4).

◆ ~Console()

Utils::Console::~Console ( )
inline

Destructor.

Member Function Documentation

◆ black()

void Utils::Console::black ( string_view msg,
int msg_level = 0 ) const

Output a message in black color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ black_reversed()

void Utils::Console::black_reversed ( string_view msg,
int msg_level = 0 ) const

Output a message in black reversed color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ blue()

void Utils::Console::blue ( string_view msg,
int msg_level = 0 ) const

Output a message in blue color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ blue_reversed()

void Utils::Console::blue_reversed ( string_view msg,
int msg_level = 0 ) const

Output a message in blue reversed color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ change_level()

void Utils::Console::change_level ( int new_level)

Change the message level.

Parameters
new_levelNew level for message output.

The admissible levels runs from -1 up to 4.

  • Level -1 means that all messages are suppressed.
  • Level 4 means that all messages are printed

◆ change_stream()

void Utils::Console::change_stream ( ostream_type * new_stream)
inline

Change the output stream.

Parameters
new_streamPointer to the new output stream.

◆ changeLevel()

void Utils::Console::changeLevel ( int new_level)
inline

Change the message level.

Parameters
new_levelNew level for message output.
Deprecated

◆ changeStream()

void Utils::Console::changeStream ( ostream_type * new_stream)
inline

Change the output stream.

Parameters
new_streamPointer to the new output stream.
Deprecated

◆ colors()

void Utils::Console::colors ( unsigned c,
string_view msg,
int msg_level = 0 ) const

Output a message with specified colors.

Parameters
cColor code.
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ cyan()

void Utils::Console::cyan ( string_view msg,
int msg_level = 0 ) const

Output a message in cyan color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ cyan_reversed()

void Utils::Console::cyan_reversed ( string_view msg,
int msg_level = 0 ) const

Output a message in cyan reversed color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ error()

void Utils::Console::error ( string_view msg) const

Output an error message.

Parameters
msgThe error message to output.

◆ fatal()

void Utils::Console::fatal ( string_view msg) const

Output a fatal message.

Parameters
msgThe fatal message to output.

◆ flush()

void Utils::Console::flush ( ) const
inline

Flush the output stream.

◆ get_level()

int Utils::Console::get_level ( ) const
inline

Get the current message level.

Returns
Current message level.

◆ get_stream()

ostream_type * Utils::Console::get_stream ( ) const
inline

Get the current output stream.

Returns
Pointer to the current output stream.

◆ getLevel()

int Utils::Console::getLevel ( ) const
inline

Get the current message level.

Returns
Current message level.
Deprecated

◆ getStream()

ostream_type * Utils::Console::getStream ( ) const
inline

Get the current output stream.

Returns
Pointer to the current output stream.
Deprecated

◆ gray()

void Utils::Console::gray ( string_view msg,
int msg_level = 0 ) const

Output a message in gray color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ gray_reversed()

void Utils::Console::gray_reversed ( string_view msg,
int msg_level = 0 ) const

Output a message in gray reversed color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ green()

void Utils::Console::green ( string_view msg,
int msg_level = 0 ) const

Output a message in green color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ green_reversed()

void Utils::Console::green_reversed ( string_view msg,
int msg_level = 0 ) const

Output a message in green reversed color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ magenta()

void Utils::Console::magenta ( string_view msg,
int msg_level = 0 ) const

Output a message in magenta color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ magenta_reversed()

void Utils::Console::magenta_reversed ( string_view msg,
int msg_level = 0 ) const

Output a message in magenta reversed color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ message()

void Utils::Console::message ( string_view msg,
int msg_level = 4 ) const

Output a message at a specified level.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 4).

◆ red()

void Utils::Console::red ( string_view msg,
int msg_level = 0 ) const

Output a message in red color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ red_reversed()

void Utils::Console::red_reversed ( string_view msg,
int msg_level = 0 ) const

Output a message in red reversed color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ semaphore()

void Utils::Console::semaphore ( unsigned ryg,
string_view msg,
int msg_level = 0 ) const

Output a semaphore message.

Parameters
rygSemaphore indicator (red, yellow, green).
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ set_auto()

void Utils::Console::set_auto ( ) const
inline

Sets coloring to automatic mode. Enables automatic color control in terminals depending on the operating system.

◆ set_error_style()

void Utils::Console::set_error_style ( rang::style const & s,
rang::fg const & f,
rang::bg const & b )
inline

Sets the error style.

Parameters
sThe text style.
fThe foreground color.
bThe background color.

◆ set_fatal_style()

void Utils::Console::set_fatal_style ( rang::style const & s,
rang::fg const & f,
rang::bg const & b )
inline

Sets the fatal error style.

Parameters
sThe text style.
fThe foreground color.
bThe background color.

◆ set_message_style()

void Utils::Console::set_message_style ( rang::style const & s,
rang::fg const & f,
rang::bg const & b )
inline

Sets the message style.

Parameters
sThe text style (e.g., bold, underline).
fThe foreground color of the text.
bThe background color of the text.

◆ set_off()

void Utils::Console::set_off ( ) const
inline

Disables coloring. Turns off color control in non-Windows terminals.

◆ set_warning_style()

void Utils::Console::set_warning_style ( rang::style const & s,
rang::fg const & f,
rang::bg const & b )
inline

Sets the warning style.

Parameters
sThe text style.
fThe foreground color.
bThe background color.

◆ setAuto()

void Utils::Console::setAuto ( ) const
inline

Sets coloring to automatic mode. Enables automatic color control in terminals depending on the operating system.

Deprecated
use set_auto

◆ setErrorStyle()

void Utils::Console::setErrorStyle ( rang::style const & s,
rang::fg const & f,
rang::bg const & b )
inline

Sets the error style.

Parameters
sThe text style.
fThe foreground color.
bThe background color.
Deprecated
use set_error_style

◆ setFatalStyle()

void Utils::Console::setFatalStyle ( rang::style const & s,
rang::fg const & f,
rang::bg const & b )
inline

Sets the fatal error style.

Parameters
sThe text style.
fThe foreground color.
bThe background color.
Deprecated
use set_fatal_style

◆ setMessageStyle()

void Utils::Console::setMessageStyle ( rang::style const & s,
rang::fg const & f,
rang::bg const & b )
inline

Sets the message style using a higher-level function.

Parameters
sThe text style.
fThe foreground color.
bThe background color.
Deprecated
use set_message_style

◆ setOff()

void Utils::Console::setOff ( ) const
inline

Disables coloring. Turns off color control in non-Windows terminals.

Deprecated
use set_off

◆ setWarningStyle()

void Utils::Console::setWarningStyle ( rang::style const & s,
rang::fg const & f,
rang::bg const & b )
inline

Sets the warning style.

Parameters
sThe text style.
fThe foreground color.
bThe background color.
Deprecated
use set_warning_style

◆ warning()

void Utils::Console::warning ( string_view msg) const

Output a warning message.

Parameters
msgThe warning message to output.

◆ yellow()

void Utils::Console::yellow ( string_view msg,
int msg_level = 0 ) const

Output a message in yellow color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

◆ yellow_reversed()

void Utils::Console::yellow_reversed ( string_view msg,
int msg_level = 0 ) const

Output a message in yellow reversed color.

Parameters
msgThe message to output.
msg_levelThe level of the message (default is 0).

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