ttx 0.1.0
Loading...
Searching...
No Matches
graphics_rendition.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/container/string/prelude.h"
4#include "di/reflect/prelude.h"
5#include "di/types/integers.h"
6#include "di/vocab/optional/prelude.h"
7#include "di/vocab/span/prelude.h"
8#include "ttx/params.h"
9
10namespace ttx {
11struct Color {
32
33 Color() = default;
34 constexpr Color(Palette c) : c(c) {}
35 constexpr Color(u8 r, u8 g, u8 b) : c(Palette::Custom), r(r), g(g), b(b) {}
36
38 u8 r = 0;
39 u8 g = 0;
40 u8 b = 0;
41
42 auto operator==(Color const& other) const -> bool = default;
43
44 constexpr friend auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<Color>) {
45 return di::make_fields<"Color">(di::field<"c", &Color::c>, di::field<"r", &Color::r>, di::field<"g", &Color::g>,
46 di::field<"b", &Color::b>);
47 }
48};
49
50constexpr auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<Color::Palette>) {
51 using enum Color::Palette;
52 return di::make_enumerators<"Color::Palette">(
53 di::enumerator<"None", None>, di::enumerator<"Custom", Custom>, di::enumerator<"Black", Black>,
54 di::enumerator<"Red", Red>, di::enumerator<"Green", Green>, di::enumerator<"Brown", Brown>,
55 di::enumerator<"Blue", Blue>, di::enumerator<"Magenta", Magenta>, di::enumerator<"Cyan", Cyan>,
56 di::enumerator<"LightGrey", LightGrey>, di::enumerator<"DarkGrey", DarkGrey>,
57 di::enumerator<"LightRed", LightRed>, di::enumerator<"LightGreen", LightGreen>,
58 di::enumerator<"Yellow", Yellow>, di::enumerator<"LightBlue", LightBlue>,
59 di::enumerator<"LightMagenta", LightMagenta>, di::enumerator<"LightCyan", LightCyan>,
60 di::enumerator<"White", White>);
61}
62
63enum class BlinkMode : u8 {
67};
68
69constexpr auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<BlinkMode>) {
70 using enum BlinkMode;
71 return di::make_enumerators<"BlinkMode">(di::enumerator<"None", None>, di::enumerator<"Normal", Normal>,
72 di::enumerator<"Rapid", Rapid>);
73}
74
75enum class FontWeight : u8 {
79};
80
81constexpr auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<FontWeight>) {
82 using enum FontWeight;
83 return di::make_enumerators<"FontWeight">(di::enumerator<"None", None>, di::enumerator<"Bold", Bold>,
84 di::enumerator<"Dim", Dim>);
85}
86
87enum class UnderlineMode : u8 {
88 None = 0,
89 Normal = 1,
90 Double = 2,
91 Curly = 3,
92 Dotted = 4,
93 Dashed = 5,
94};
95
96constexpr auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<UnderlineMode>) {
97 using enum UnderlineMode;
98 return di::make_enumerators<"UnderlineMode">(di::enumerator<"None", None>, di::enumerator<"Normal", Normal>,
99 di::enumerator<"Double", Double>, di::enumerator<"Curly", Curly>,
100 di::enumerator<"Dotted", Dotted>, di::enumerator<"Dashed", Dashed>);
101}
102
107
111 bool italic { false };
112 bool overline { false };
113 bool inverted { false };
114 bool invisible { false };
115 bool strike_through { false };
116
117 static auto from_csi_params(Params const& params) {
118 auto result = GraphicsRendition {};
120 return result;
121 }
123 auto as_csi_params() const -> di::Vector<Params>;
124
125 auto operator==(GraphicsRendition const& other) const -> bool = default;
126
127 constexpr friend auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<GraphicsRendition>) {
128 return di::make_fields<"GraphicsRendition">(
129 di::field<"fg", &GraphicsRendition::fg>, di::field<"bg", &GraphicsRendition::bg>,
130 di::field<"underline_color", &GraphicsRendition::underline_color>,
131 di::field<"font_weight", &GraphicsRendition::font_weight>,
132 di::field<"blink_mode", &GraphicsRendition::blink_mode>,
133 di::field<"underline_mode", &GraphicsRendition::underline_mode>,
134 di::field<"italic", &GraphicsRendition::italic>, di::field<"overline", &GraphicsRendition::overline>,
135 di::field<"inverted", &GraphicsRendition::inverted>, di::field<"invisible", &GraphicsRendition::invisible>,
136 di::field<"strike_through", &GraphicsRendition::strike_through>);
137 }
138};
139}
Definition params.h:67
Definition test_params.cpp:4
Definition cursor_style.h:5
BlinkMode
Definition graphics_rendition.h:63
@ None
Definition graphics_rendition.h:64
@ Normal
Definition graphics_rendition.h:65
@ Rapid
Definition graphics_rendition.h:66
@ None
Definition direction.h:8
constexpr auto tag_invoke(di::Tag< di::reflect >, di::InPlaceType< CursorStyle >)
Definition cursor_style.h:16
UnderlineMode
Definition graphics_rendition.h:87
@ None
Definition graphics_rendition.h:88
@ Dotted
Definition graphics_rendition.h:92
@ Double
Definition graphics_rendition.h:90
@ Curly
Definition graphics_rendition.h:91
@ Dashed
Definition graphics_rendition.h:93
FontWeight
Definition graphics_rendition.h:75
@ Bold
Definition graphics_rendition.h:77
@ None
Definition graphics_rendition.h:76
@ Dim
Definition graphics_rendition.h:78
Definition graphics_rendition.h:11
Palette
Definition graphics_rendition.h:12
@ LightGreen
Definition graphics_rendition.h:25
@ DarkGrey
Definition graphics_rendition.h:23
@ LightCyan
Definition graphics_rendition.h:29
@ Yellow
Definition graphics_rendition.h:26
@ Custom
Definition graphics_rendition.h:14
@ Red
Definition graphics_rendition.h:16
@ Brown
Definition graphics_rendition.h:18
@ LightRed
Definition graphics_rendition.h:24
@ Cyan
Definition graphics_rendition.h:21
@ None
Definition graphics_rendition.h:13
@ LightGrey
Definition graphics_rendition.h:22
@ LightMagenta
Definition graphics_rendition.h:28
@ Blue
Definition graphics_rendition.h:19
@ LightBlue
Definition graphics_rendition.h:27
@ Green
Definition graphics_rendition.h:17
@ White
Definition graphics_rendition.h:30
@ Magenta
Definition graphics_rendition.h:20
@ Black
Definition graphics_rendition.h:15
constexpr friend auto tag_invoke(di::Tag< di::reflect >, di::InPlaceType< Color >)
Definition graphics_rendition.h:44
Palette c
Definition graphics_rendition.h:37
u8 r
Definition graphics_rendition.h:38
auto operator==(Color const &other) const -> bool=default
u8 b
Definition graphics_rendition.h:40
u8 g
Definition graphics_rendition.h:39
constexpr Color(u8 r, u8 g, u8 b)
Definition graphics_rendition.h:35
Color()=default
constexpr Color(Palette c)
Definition graphics_rendition.h:34
Definition graphics_rendition.h:103
static auto from_csi_params(Params const &params)
Definition graphics_rendition.h:117
bool strike_through
Definition graphics_rendition.h:115
bool italic
Definition graphics_rendition.h:111
BlinkMode blink_mode
Definition graphics_rendition.h:109
auto as_csi_params() const -> di::Vector< Params >
Definition graphics_rendition.cpp:261
constexpr friend auto tag_invoke(di::Tag< di::reflect >, di::InPlaceType< GraphicsRendition >)
Definition graphics_rendition.h:127
Color fg
Definition graphics_rendition.h:104
UnderlineMode underline_mode
Definition graphics_rendition.h:110
void update_with_csi_params(Params const &params)
Definition graphics_rendition.cpp:81
Color underline_color
Definition graphics_rendition.h:106
Color bg
Definition graphics_rendition.h:105
bool invisible
Definition graphics_rendition.h:114
FontWeight font_weight
Definition graphics_rendition.h:108
bool overline
Definition graphics_rendition.h:112
bool inverted
Definition graphics_rendition.h:113