libfly  6.2.2
C++20 utility library for Linux, macOS, and Windows
fly::logger::Styler Class Reference

#include <styler.hpp>

Public Member Functions

template<Modifier ModifierType>
 Styler (ModifierType &&modifier) noexcept
 
template<Modifier ModifierType, Modifier... ModifierTypes>
 Styler (ModifierType &&modifier, ModifierTypes &&...modifiers) noexcept
 

Friends

detail::StylerProxyoperator<< (std::ostream &stream, const Styler &styler)
 

Detailed Description

IO manipulator to stylize a std::ostream with style and color. This manipulator allows for applying any number of styles (e.g. bold, italic), a foreground color, and background color to the std::ostream. It also allows for modifying the cursor position within the stream.

Upon destruction, the styles and colors applied by this manipulator are reverted. Manipulations of the cursor position are not reverted.

Only standard output and error streams are supported. Any other streams will remain unmanipulated.

Not all styles and colors are supported on all platforms. Unsupported styles and colors will be silently ignored.

Callers may invoke and stream a Styler instance inline, or hold onto a Styler instance for as long as desired (in which case, it will not take effect until streamed onto the std::ostream).

Stream inline:

std::cout << fly::Styler(fly::Style::Bold, fly::Color::Red) << "This is bold and red\n";
std::cout << "This is neither bold nor red\n";

Scoped instance:

{
    fly::Styler styler(fly::Style::Bold, fly::Color::Red);
    std::cout << "This is neither bold nor red\n";
    std::cout << styler << "This is bold and red\n";
    std::cout << "This is also bold and red\n";
}
std::cout << "This is neither bold nor red\n";
Author
Timothy Flynn (trfly.nosp@m.nn89.nosp@m.@pm.m.nosp@m.e)
Version
July 11, 2020

Constructor & Destructor Documentation

◆ Styler() [1/2]

template<Modifier ModifierType>
fly::logger::Styler::Styler ( ModifierType &&  modifier)
inlineexplicitnoexcept

Construct a Styler with a single modifier. The template modifier type must be one of [Style, Color, Color::StandardColor, Cursor, Cursor::Direction]. The enumeration [Style are coverted to their parent structure types.

Template Parameters
ModifierTypeThe type of the modifier to apply to the std::ostream.
Parameters
modifierThe modifier to apply to the std::ostream.

◆ Styler() [2/2]

template<Modifier ModifierType, Modifier... ModifierTypes>
fly::logger::Styler::Styler ( ModifierType &&  modifier,
ModifierTypes &&...  modifiers 
)
inlinenoexcept

Construct a Styler with multiple modifiers. The template modifier types must be one of [Style, Color, Color::StandardColor, Cursor, Cursor::Direction]. The enumeration types are coverted to their parent structure types.

Any number of Style and Cursor instances may be used and will be combined in the Styler. Only one foreground and one background Color instance may be used; if more than one of each is provided, only the last instance provided will take effect.

Template Parameters
ModifierTypeThe type of the modifier to apply to the std::ostream.
ModifierTypesVariadic types of the remaining modifiers to apply to the std::ostream.
Parameters
modifierThe modifier to apply to the std::ostream.
modifiersThe remaining modifiers to apply to the std::ostream.

Friends And Related Function Documentation

◆ operator<<

detail::StylerProxy& operator<< ( std::ostream &  stream,
const Styler styler 
)
friend

Stream a Styler onto a std::ostream. The Styler creates a StylerProxy instance responsible for performing the underlying stream manipulations. That instance is active until the streamed Styler goes out of scope.

Parameters
streamThe stream to manipulate.
stylerThe Styler holding the manipulation to apply to the stream.
Returns
A reference to the created StylerProxy instance.

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