slang::TextStyle class

Describes the styling (foreground color, background color, and emphasis) to apply to a run of terminal text.

Constructors, destructors, conversion operators

TextStyle() defaulted constexpr
Constructs a style with no color and no emphasis.
TextStyle(TextEmphasis emphasis) constexpr noexcept
Constructs a style with the given emphasis and no color.

Public functions

bool hasForeground() const constexpr noexcept
bool hasBackground() const constexpr noexcept
TextColor foreground() const constexpr noexcept
TextColor background() const constexpr noexcept
uint8_t emphasis() const constexpr noexcept
TextStyle& operator|=(const TextStyle& rhs) constexpr noexcept
Merges the styling of rhs into this style.

Friends

TextStyle operator|(TextStyle lhs, const TextStyle& rhs) constexpr noexcept
Merges two styles together. See operator|=.
TextStyle fg(TextColor color) constexpr noexcept
Creates a text style that sets the given foreground color.
TextStyle bg(TextColor color) constexpr noexcept
Creates a text style that sets the given background color.

Function documentation

bool slang::TextStyle::hasForeground() const constexpr noexcept

Returns true if a foreground color has been set, otherwise false.

bool slang::TextStyle::hasBackground() const constexpr noexcept

Returns true if a background color has been set, otherwise false.

TextColor slang::TextStyle::foreground() const constexpr noexcept

Returns the foreground color. Only valid if hasForeground() is true.

TextColor slang::TextStyle::background() const constexpr noexcept

Returns the background color. Only valid if hasBackground() is true.

uint8_t slang::TextStyle::emphasis() const constexpr noexcept

Returns the combined emphasis flags as a raw bitmask.

TextStyle& slang::TextStyle::operator|=(const TextStyle& rhs) constexpr noexcept

Merges the styling of rhs into this style.

Colors set in rhs take precedence, and emphasis flags are combined together.