ttx 0.1.0
Loading...
Searching...
No Matches
ttx::terminal::Color Struct Reference

#include <ttx/terminal/color.h>

Public Types

enum class  Type : u8 { Default , Palette , Custom , Dynamic }
enum  Palette : u8 {
  Black , Red , Green , Yellow ,
  Blue , Magenta , Cyan , LightGrey ,
  DarkGrey , LightRed , LightGreen , LightYellow ,
  LightBlue , LightMagenta , LightCyan , White
}
using IsAtom = void

Public Member Functions

 Color ()=default
constexpr Color (Palette c)
constexpr Color (u8 r, u8 g, u8 b)
constexpr Color (Type t)
auto is_default () const
auto is_palette () const
auto is_custom () const
auto is_dynamic () const
 Compute the perceived brightness of a color.
auto brightness () const -> f64
 Dim the given color by a percentage.
auto dimmed (u32 dim_factor) const -> Color
auto value_or (Color other) const
auto to_string () const -> di::String
auto operator== (Color const &other) const -> bool=default
auto operator<=> (Color const &other) const =default

Static Public Member Functions

static auto from_name (di::StringView color) -> di::Result< Color >
static auto from_string (di::StringView color) -> di::Result< Color >

Public Attributes

Type type = Type::Default
u8 r = 0
u8 g = 0
u8 b = 0

Friends

constexpr friend auto tag_invoke (di::Tag< di::parser::create_parser_in_place >, di::InPlaceType< Color >)

Member Typedef Documentation

◆ IsAtom

Member Enumeration Documentation

◆ Palette

Enumerator
Black 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
LightGrey 
DarkGrey 
LightRed 
LightGreen 
LightYellow 
LightBlue 
LightMagenta 
LightCyan 
White 

◆ Type

enum class ttx::terminal::Color::Type : u8
strong
Enumerator
Default 

Color is the default (unset SGR).

Palette 

Color is a palette color (256 colors are available).

Custom 

Color is true color (r, b, g fully specified).

Dynamic 

Color is dynamic (e.g. for selection use reverse video).

Constructor & Destructor Documentation

◆ Color() [1/4]

ttx::terminal::Color::Color ( )
default

◆ Color() [2/4]

ttx::terminal::Color::Color ( Palette c)
inlineconstexpr

◆ Color() [3/4]

ttx::terminal::Color::Color ( u8 r,
u8 g,
u8 b )
inlineconstexpr

◆ Color() [4/4]

ttx::terminal::Color::Color ( Type t)
inlineexplicitconstexpr

Member Function Documentation

◆ brightness()

auto ttx::terminal::Color::brightness ( ) const -> f64

Dim the given color by a percentage.

This has no affect on non rgb color types.

◆ dimmed()

auto ttx::terminal::Color::dimmed ( u32 dim_factor) const -> Color

◆ from_name()

auto ttx::terminal::Color::from_name ( di::StringView color) -> di::Result< Color >
static

◆ from_string()

auto ttx::terminal::Color::from_string ( di::StringView color) -> di::Result< Color >
static

◆ is_custom()

auto ttx::terminal::Color::is_custom ( ) const
inline

◆ is_default()

auto ttx::terminal::Color::is_default ( ) const
inline

◆ is_dynamic()

auto ttx::terminal::Color::is_dynamic ( ) const
inline

Compute the perceived brightness of a color.

   This is meant to determine if a color theme is "light" or "dark".
   This will return 0.0 for non rgb color types. 

◆ is_palette()

auto ttx::terminal::Color::is_palette ( ) const
inline

◆ operator<=>()

auto ttx::terminal::Color::operator<=> ( Color const & other) const
default

◆ operator==()

auto ttx::terminal::Color::operator== ( Color const & other) const -> bool=default
default

◆ to_string()

auto ttx::terminal::Color::to_string ( ) const -> di::String

◆ value_or()

auto ttx::terminal::Color::value_or ( Color other) const
inline

◆ tag_invoke

friend auto tag_invoke ( di::Tag< di::parser::create_parser_in_place > ,
di::InPlaceType< Color >  )
friend

Member Data Documentation

◆ b

u8 ttx::terminal::Color::b = 0

◆ g

u8 ttx::terminal::Color::g = 0

◆ r

u8 ttx::terminal::Color::r = 0

◆ type

Type ttx::terminal::Color::type = Type::Default

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