libfly
6.2.2
C++20 utility library for Linux, macOS, and Windows
|
#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::StylerProxy & | operator<< (std::ostream &stream, const Styler &styler) |
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";
|
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.
ModifierType | The type of the modifier to apply to the std::ostream. |
modifier | The modifier to apply to the std::ostream. |
|
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.
ModifierType | The type of the modifier to apply to the std::ostream. |
ModifierTypes | Variadic types of the remaining modifiers to apply to the std::ostream. |
modifier | The modifier to apply to the std::ostream. |
modifiers | The remaining modifiers to apply to the std::ostream. |
|
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.
stream | The stream to manipulate. |
styler | The Styler holding the manipulation to apply to the stream. |