nomlib
Loading...
Searching...
No Matches
nom::ConsoleOutput Class Reference

Platform-independent color output interface. More...

#include <ConsoleOutput.hpp>

Inheritance diagram for nom::ConsoleOutput:
[legend]

Public Types

enum  Color {
  FG_WHITE , FG_RED , FG_GREEN , FG_BLUE ,
  FG_MAGENTA , FG_YELLOW , FG_ORANGE , FG_PURPLE
}
enum  : uint32 { STYLE_NONE = 0 , STYLE_BOLD = 0x1 , STYLE_UNDERLINED = 0x2 }

Public Member Functions

 ConsoleOutput ()
 Default constructor; initializes the output stream to use std::cerr (the standard error stream).
 ConsoleOutput (std::ostream &os)
 Construct a console output object with a custom output stream.
ConsoleOutput::Color color () const
 Get the last color that was set.
bool use_color () const
 Get the current use state of colored output logging.
virtual void set_color (ConsoleOutput::Color color)
virtual void set_style (uint32 style)
virtual void endl ()
 Reset the colors that have been set.

Protected Attributes

std::ostream & out_
 The output stream to use; i.e.: std::cout or std::cerr.
ConsoleOutput::Color lcolor_
 The last color used.

Private Member Functions

std::string env (const std::string &path) const
 Get the value of an environment variable.

Private Attributes

std::unique_ptr< ConsoleOutputimpl_
 The platform-dependent implementation to use.

Detailed Description

Platform-independent color output interface.

Remarks
This is intended to be a minimal interface for debug logging aid.
See also
nom::SDL2Logger

Definition at line 43 of file ConsoleOutput.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : uint32
Enumerator
STYLE_NONE 

Resets the text colors.

Definition at line 1 of file ConsoleOutput.hpp.

◆ Color

Enumerator
FG_RED 
Todo
Implement in UnixConsoleOutput
FG_PURPLE 
Todo
Implement in WindowsConsoleOutput

Definition at line 46 of file ConsoleOutput.hpp.

Constructor & Destructor Documentation

◆ ConsoleOutput()

nom::ConsoleOutput::ConsoleOutput ( std::ostream & os)

Construct a console output object with a custom output stream.

Parameters
osstd::cerr, std::cout, std::ofstream, etc.

Member Function Documentation

◆ color()

ConsoleOutput::Color nom::ConsoleOutput::color ( ) const

Get the last color that was set.

Remarks
The last color used is updated upon every successful call to ::set_color.

◆ endl()

virtual void nom::ConsoleOutput::endl ( )
virtual

Reset the colors that have been set.

Remarks
The intention of this call is to restore the screen buffer back to its previous state (before modification from our process).

Reimplemented in nom::UnixConsoleOutput, and nom::WindowsConsoleOutput.

◆ env()

std::string nom::ConsoleOutput::env ( const std::string & path) const
private

Get the value of an environment variable.

Returns
A null-terminated string (zero length) upon err, such as an non-existent environment variable.

◆ set_color()

virtual void nom::ConsoleOutput::set_color ( ConsoleOutput::Color color)
virtual

◆ set_style()

virtual void nom::ConsoleOutput::set_style ( uint32 style)
virtual

◆ use_color()

bool nom::ConsoleOutput::use_color ( ) const

Get the current use state of colored output logging.

Returns
Boolean TRUE when the platform's environment variable NOM_COLOR is set to 'true, 'always', 'yes' or "1", otherwise boolean FALSE is returned (the default).
Todo
The environment variable's value is case-sensitive.
Todo
Provide 'auto' option for NOM_COLOR; this could be tested on Unix platforms with the value of TERM equaling xterm-color or such; see also: gtest.cc.

Member Data Documentation

◆ impl_

std::unique_ptr<ConsoleOutput> nom::ConsoleOutput::impl_
private

The platform-dependent implementation to use.

See also
nom::UnixConsoleOutput, nom::WindowsConsoleOutput

Definition at line 126 of file ConsoleOutput.hpp.

◆ lcolor_

ConsoleOutput::Color nom::ConsoleOutput::lcolor_
protected

The last color used.

Remarks
Used in SDL2Logger::log_message for rotating the two colors used for a message – the logging priority and the message contents.

Definition at line 114 of file ConsoleOutput.hpp.

◆ out_

std::ostream& nom::ConsoleOutput::out_
protected

The output stream to use; i.e.: std::cout or std::cerr.

Definition at line 108 of file ConsoleOutput.hpp.


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