Porytiles
Loading...
Searching...
No Matches
porytiles::Style Class Reference

Text styling class supporting formatting, foreground colors, and background colors. More...

#include <text_formatter.hpp>

Collaboration diagram for porytiles::Style:
[legend]

Public Member Functions

constexpr Style ()=default
 Default constructor creating a style with no attributes.
 
constexpr Style operator| (const Style &other) const
 Combines two Style values using the | operator.
 
constexpr bool has_bold () const
 Checks if this Style has bold formatting.
 
constexpr bool has_faint () const
 Checks if this Style has faint formatting.
 
constexpr bool has_italic () const
 Checks if this Style has italic formatting.
 
constexpr bool has_underline () const
 Checks if this Style has underline formatting.
 
constexpr bool has_blink () const
 Checks if this Style has blink formatting.
 
constexpr bool has_fg_color () const
 Checks if this Style has a foreground color set.
 
constexpr bool has_bg_color () const
 Checks if this Style has a background color set.
 
constexpr bool is_fg_rgb () const
 Checks if the foreground color is in RGB mode.
 
constexpr bool is_bg_rgb () const
 Checks if the background color is in RGB mode.
 
constexpr RgbColor fg_rgb () const
 Returns the foreground RGB color.
 
constexpr RgbColor bg_rgb () const
 Returns the background RGB color.
 
constexpr PredefinedColor fg_predefined () const
 Returns the predefined foreground color.
 
constexpr PredefinedColor bg_predefined () const
 Returns the predefined background color.
 

Static Public Attributes

static const Style none {}
 No styling applied.
 
static const Style bold {Style::FormatFlagTag::bold}
 Bold text formatting.
 
static const Style faint {Style::FormatFlagTag::faint}
 Faint text formatting.
 
static const Style italic {Style::FormatFlagTag::italic}
 Italic text formatting.
 
static const Style underline {Style::FormatFlagTag::underline}
 Underline text formatting.
 
static const Style blink {Style::FormatFlagTag::blink}
 Blink text formatting.
 
static const Style black {Style::FgColorTag::predefined, PredefinedColor::black}
 Black foreground color.
 
static const Style red {Style::FgColorTag::predefined, PredefinedColor::red}
 Red foreground color.
 
static const Style green {Style::FgColorTag::predefined, PredefinedColor::green}
 Green foreground color.
 
static const Style yellow {Style::FgColorTag::predefined, PredefinedColor::yellow}
 Yellow foreground color.
 
static const Style blue {Style::FgColorTag::predefined, PredefinedColor::blue}
 Blue foreground color.
 
static const Style magenta {Style::FgColorTag::predefined, PredefinedColor::magenta}
 Magenta foreground color.
 
static const Style cyan {Style::FgColorTag::predefined, PredefinedColor::cyan}
 Cyan foreground color.
 
static const Style white {Style::FgColorTag::predefined, PredefinedColor::white}
 White foreground color.
 
static const Style bg_black {Style::BgColorTag::predefined, PredefinedColor::black}
 Black background color.
 
static const Style bg_red {Style::BgColorTag::predefined, PredefinedColor::red}
 Red background color.
 
static const Style bg_green {Style::BgColorTag::predefined, PredefinedColor::green}
 Green background color.
 
static const Style bg_yellow {Style::BgColorTag::predefined, PredefinedColor::yellow}
 Yellow background color.
 
static const Style bg_blue {Style::BgColorTag::predefined, PredefinedColor::blue}
 Blue background color.
 
static const Style bg_magenta {Style::BgColorTag::predefined, PredefinedColor::magenta}
 Magenta background color.
 
static const Style bg_cyan {Style::BgColorTag::predefined, PredefinedColor::cyan}
 Cyan background color.
 
static const Style bg_white {Style::BgColorTag::predefined, PredefinedColor::white}
 White background color.
 

Friends

constexpr Style rgb_fg_style (std::uint8_t r, std::uint8_t g, std::uint8_t b)
 Creates a Style value with a custom RGB foreground color.
 
constexpr Style rgb_bg_style (std::uint8_t r, std::uint8_t g, std::uint8_t b)
 Creates a Style value with a custom RGB background color.
 

Detailed Description

Text styling class supporting formatting, foreground colors, and background colors.

Style is a class that allows multiple styling attributes to be combined using the | operator. It supports:

  • Format attributes: bold, italic
  • Foreground colors: predefined (8 ANSI colors) or custom RGB
  • Background colors: predefined (8 ANSI colors) or custom RGB

Styles can be combined using the | operator to apply multiple attributes simultaneously:

++
Style::bold | Style::red // Bold red foreground
Style::red | Style::bg_blue // Red foreground on blue background
rgb_fg_style(255, 128, 0) | Style::bg_black // Orange foreground on black background
static const Style bg_blue
Blue background color.
static const Style bg_black
Black background color.
static const Style red
Red foreground color.
static const Style bold
Bold text formatting.
friend constexpr Style rgb_fg_style(std::uint8_t r, std::uint8_t g, std::uint8_t b)
Creates a Style value with a custom RGB foreground color.

The class maintains backward compatibility with the previous enum-based API while providing more flexibility for combining foreground and background colors.

Definition at line 66 of file text_formatter.hpp.

Constructor & Destructor Documentation

◆ Style()

constexpr porytiles::Style::Style ( )
constexprdefault

Default constructor creating a style with no attributes.

Member Function Documentation

◆ bg_predefined()

constexpr PredefinedColor porytiles::Style::bg_predefined ( ) const
inlineconstexpr

Returns the predefined background color.

Precondition
!is_bg_rgb() must be true (background is not RGB)
Returns
The PredefinedColor for the background

Definition at line 276 of file text_formatter.hpp.

◆ bg_rgb()

constexpr RgbColor porytiles::Style::bg_rgb ( ) const
inlineconstexpr

Returns the background RGB color.

Precondition
is_bg_rgb() must be true
Returns
The RgbColor representing the background color

Definition at line 254 of file text_formatter.hpp.

◆ fg_predefined()

constexpr PredefinedColor porytiles::Style::fg_predefined ( ) const
inlineconstexpr

Returns the predefined foreground color.

Precondition
!is_fg_rgb() must be true (foreground is not RGB)
Returns
The PredefinedColor for the foreground

Definition at line 265 of file text_formatter.hpp.

◆ fg_rgb()

constexpr RgbColor porytiles::Style::fg_rgb ( ) const
inlineconstexpr

Returns the foreground RGB color.

Precondition
is_fg_rgb() must be true
Returns
The RgbColor representing the foreground color

Definition at line 243 of file text_formatter.hpp.

◆ has_bg_color()

constexpr bool porytiles::Style::has_bg_color ( ) const
inlineconstexpr

Checks if this Style has a background color set.

Returns
True if a background color (predefined or RGB) is set

Definition at line 212 of file text_formatter.hpp.

◆ has_blink()

constexpr bool porytiles::Style::has_blink ( ) const
inlineconstexpr

Checks if this Style has blink formatting.

Returns
True if blink formatting is set

Definition at line 192 of file text_formatter.hpp.

◆ has_bold()

constexpr bool porytiles::Style::has_bold ( ) const
inlineconstexpr

Checks if this Style has bold formatting.

Returns
True if bold formatting is set

Definition at line 152 of file text_formatter.hpp.

◆ has_faint()

constexpr bool porytiles::Style::has_faint ( ) const
inlineconstexpr

Checks if this Style has faint formatting.

Returns
True if faint formatting is set

Definition at line 162 of file text_formatter.hpp.

◆ has_fg_color()

constexpr bool porytiles::Style::has_fg_color ( ) const
inlineconstexpr

Checks if this Style has a foreground color set.

Returns
True if a foreground color (predefined or RGB) is set

Definition at line 202 of file text_formatter.hpp.

◆ has_italic()

constexpr bool porytiles::Style::has_italic ( ) const
inlineconstexpr

Checks if this Style has italic formatting.

Returns
True if italic formatting is set

Definition at line 172 of file text_formatter.hpp.

◆ has_underline()

constexpr bool porytiles::Style::has_underline ( ) const
inlineconstexpr

Checks if this Style has underline formatting.

Returns
True if underline formatting is set

Definition at line 182 of file text_formatter.hpp.

◆ is_bg_rgb()

constexpr bool porytiles::Style::is_bg_rgb ( ) const
inlineconstexpr

Checks if the background color is in RGB mode.

Returns
True if background uses custom RGB color

Definition at line 232 of file text_formatter.hpp.

◆ is_fg_rgb()

constexpr bool porytiles::Style::is_fg_rgb ( ) const
inlineconstexpr

Checks if the foreground color is in RGB mode.

Returns
True if foreground uses custom RGB color

Definition at line 222 of file text_formatter.hpp.

◆ operator|()

constexpr Style porytiles::Style::operator| ( const Style other) const
inlineconstexpr

Combines two Style values using the | operator.

Merges styling attributes from two Style values:

  • Format flags (bold, italic) are combined with bitwise OR
  • Foreground color: right-hand side wins if both have foreground colors
  • Background color: right-hand side wins if both have background colors
Parameters
otherThe Style value to combine with
Returns
A new Style value with combined attributes

Definition at line 113 of file text_formatter.hpp.

Friends And Related Symbol Documentation

◆ rgb_bg_style

constexpr Style rgb_bg_style ( std::uint8_t  r,
std::uint8_t  g,
std::uint8_t  b 
)
friend

Creates a Style value with a custom RGB background color.

Constructs a Style value with an RGB background color using the provided red, green, and blue channel values. The resulting Style can be combined with formatting flags and foreground colors using the | operator:

++
Style custom = rgb_bg_style(64, 64, 64) | Style::bold;
Style with_fg = Style::red | rgb_bg_style(255, 255, 0);
Text styling class supporting formatting, foreground colors, and background colors.
friend constexpr Style rgb_bg_style(std::uint8_t r, std::uint8_t g, std::uint8_t b)
Creates a Style value with a custom RGB background color.
Parameters
rRed channel value (0-255)
gGreen channel value (0-255)
bBlue channel value (0-255)
Returns
A Style value with RGB background color

Definition at line 380 of file text_formatter.hpp.

◆ rgb_fg_style

constexpr Style rgb_fg_style ( std::uint8_t  r,
std::uint8_t  g,
std::uint8_t  b 
)
friend

Creates a Style value with a custom RGB foreground color.

Constructs a Style value with an RGB foreground color using the provided red, green, and blue channel values. The resulting Style can be combined with formatting flags and background colors using the | operator:

++
Style custom = rgb_fg_style(255, 128, 0) | Style::bold;
Style with_bg = rgb_fg_style(255, 128, 0) | Style::bg_black;
Parameters
rRed channel value (0-255)
gGreen channel value (0-255)
bBlue channel value (0-255)
Returns
A Style value with RGB foreground color

Definition at line 359 of file text_formatter.hpp.

Member Data Documentation

◆ bg_black

const Style porytiles::Style::bg_black {Style::BgColorTag::predefined, PredefinedColor::black}
static

Black background color.

Definition at line 87 of file text_formatter.hpp.

◆ bg_blue

const Style porytiles::Style::bg_blue {Style::BgColorTag::predefined, PredefinedColor::blue}
static

Blue background color.

Definition at line 91 of file text_formatter.hpp.

◆ bg_cyan

const Style porytiles::Style::bg_cyan {Style::BgColorTag::predefined, PredefinedColor::cyan}
static

Cyan background color.

Definition at line 93 of file text_formatter.hpp.

◆ bg_green

const Style porytiles::Style::bg_green {Style::BgColorTag::predefined, PredefinedColor::green}
static

Green background color.

Definition at line 89 of file text_formatter.hpp.

◆ bg_magenta

const Style porytiles::Style::bg_magenta {Style::BgColorTag::predefined, PredefinedColor::magenta}
static

Magenta background color.

Definition at line 92 of file text_formatter.hpp.

◆ bg_red

const Style porytiles::Style::bg_red {Style::BgColorTag::predefined, PredefinedColor::red}
static

Red background color.

Definition at line 88 of file text_formatter.hpp.

◆ bg_white

const Style porytiles::Style::bg_white {Style::BgColorTag::predefined, PredefinedColor::white}
static

White background color.

Definition at line 94 of file text_formatter.hpp.

◆ bg_yellow

const Style porytiles::Style::bg_yellow {Style::BgColorTag::predefined, PredefinedColor::yellow}
static

Yellow background color.

Definition at line 90 of file text_formatter.hpp.

◆ black

const Style porytiles::Style::black {Style::FgColorTag::predefined, PredefinedColor::black}
static

Black foreground color.

Definition at line 77 of file text_formatter.hpp.

◆ blink

const Style porytiles::Style::blink {Style::FormatFlagTag::blink}
static

Blink text formatting.

Definition at line 74 of file text_formatter.hpp.

◆ blue

const Style porytiles::Style::blue {Style::FgColorTag::predefined, PredefinedColor::blue}
static

Blue foreground color.

Definition at line 81 of file text_formatter.hpp.

◆ bold

const Style porytiles::Style::bold {Style::FormatFlagTag::bold}
static

Bold text formatting.

Definition at line 70 of file text_formatter.hpp.

◆ cyan

const Style porytiles::Style::cyan {Style::FgColorTag::predefined, PredefinedColor::cyan}
static

Cyan foreground color.

Definition at line 83 of file text_formatter.hpp.

◆ faint

const Style porytiles::Style::faint {Style::FormatFlagTag::faint}
static

Faint text formatting.

Definition at line 71 of file text_formatter.hpp.

◆ green

const Style porytiles::Style::green {Style::FgColorTag::predefined, PredefinedColor::green}
static

Green foreground color.

Definition at line 79 of file text_formatter.hpp.

◆ italic

const Style porytiles::Style::italic {Style::FormatFlagTag::italic}
static

Italic text formatting.

Definition at line 72 of file text_formatter.hpp.

◆ magenta

const Style porytiles::Style::magenta {Style::FgColorTag::predefined, PredefinedColor::magenta}
static

Magenta foreground color.

Definition at line 82 of file text_formatter.hpp.

◆ none

const Style porytiles::Style::none {}
static

No styling applied.

Definition at line 69 of file text_formatter.hpp.

◆ red

const Style porytiles::Style::red {Style::FgColorTag::predefined, PredefinedColor::red}
static

Red foreground color.

Definition at line 78 of file text_formatter.hpp.

◆ underline

const Style porytiles::Style::underline {Style::FormatFlagTag::underline}
static

Underline text formatting.

Definition at line 73 of file text_formatter.hpp.

◆ white

const Style porytiles::Style::white {Style::FgColorTag::predefined, PredefinedColor::white}
static

White foreground color.

Definition at line 84 of file text_formatter.hpp.

◆ yellow

const Style porytiles::Style::yellow {Style::FgColorTag::predefined, PredefinedColor::yellow}
static

Yellow foreground color.

Definition at line 80 of file text_formatter.hpp.


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