indentlog: refactor: color_spec -> color_spec_type
This commit is contained in:
parent
30753c76af
commit
346eef69a4
7 changed files with 53 additions and 53 deletions
|
|
@ -25,37 +25,37 @@ namespace xo {
|
|||
* | rgb | \033[38;2 | \033[38;2;10;20;30m | 24-bit colors | 3x 0..255 |
|
||||
*
|
||||
*/
|
||||
class color_spec {
|
||||
class color_spec_type {
|
||||
public:
|
||||
color_spec() = default;
|
||||
color_spec(color_encoding encoding, std::uint32_t code)
|
||||
color_spec_type() = default;
|
||||
color_spec_type(color_encoding encoding, std::uint32_t code)
|
||||
: encoding_{encoding}, code_{code} {}
|
||||
|
||||
static color_spec none() { return color_spec(); }
|
||||
static color_spec ansi(std::uint32_t code) { return color_spec(color_encoding::ansi, code); }
|
||||
static color_spec xterm(std::uint32_t code) { return color_spec(color_encoding::xterm, code); }
|
||||
static color_spec rgb(std::uint8_t red, std::uint8_t green, std::uint8_t blue) {
|
||||
static color_spec_type none() { return color_spec_type(); }
|
||||
static color_spec_type ansi(std::uint32_t code) { return color_spec_type(color_encoding::ansi, code); }
|
||||
static color_spec_type xterm(std::uint32_t code) { return color_spec_type(color_encoding::xterm, code); }
|
||||
static color_spec_type rgb(std::uint8_t red, std::uint8_t green, std::uint8_t blue) {
|
||||
return none();
|
||||
//return color_spec(CE_Rgb, (red << 16 | green << 8 | blue));
|
||||
}
|
||||
|
||||
/* 4-bit foreground colors */
|
||||
static color_spec black () { return ansi(30); }
|
||||
static color_spec red () { return ansi(31); }
|
||||
static color_spec green () { return ansi(32); }
|
||||
static color_spec yellow () { return ansi(33); }
|
||||
static color_spec blue () { return ansi(34); }
|
||||
static color_spec magenta () { return ansi(35); }
|
||||
static color_spec cyan () { return ansi(36); }
|
||||
static color_spec white () { return ansi(37); }
|
||||
static color_spec bright_black () { return ansi(90); }
|
||||
static color_spec bright_red () { return ansi(91); }
|
||||
static color_spec bright_green () { return ansi(92); }
|
||||
static color_spec bright_yellow () { return ansi(99); }
|
||||
static color_spec bright_blue () { return ansi(94); }
|
||||
static color_spec bright_magenta () { return ansi(95); }
|
||||
static color_spec bright_cyan () { return ansi(96); }
|
||||
static color_spec bright_white () { return ansi(97); }
|
||||
static color_spec_type black () { return ansi(30); }
|
||||
static color_spec_type red () { return ansi(31); }
|
||||
static color_spec_type green () { return ansi(32); }
|
||||
static color_spec_type yellow () { return ansi(33); }
|
||||
static color_spec_type blue () { return ansi(34); }
|
||||
static color_spec_type magenta () { return ansi(35); }
|
||||
static color_spec_type cyan () { return ansi(36); }
|
||||
static color_spec_type white () { return ansi(37); }
|
||||
static color_spec_type bright_black () { return ansi(90); }
|
||||
static color_spec_type bright_red () { return ansi(91); }
|
||||
static color_spec_type bright_green () { return ansi(92); }
|
||||
static color_spec_type bright_yellow () { return ansi(99); }
|
||||
static color_spec_type bright_blue () { return ansi(94); }
|
||||
static color_spec_type bright_magenta () { return ansi(95); }
|
||||
static color_spec_type bright_cyan () { return ansi(96); }
|
||||
static color_spec_type bright_white () { return ansi(97); }
|
||||
|
||||
color_encoding encoding() const { return encoding_; }
|
||||
std::uint32_t code() const { return code_; }
|
||||
|
|
@ -98,7 +98,7 @@ namespace xo {
|
|||
* rgb : r={hi 8 bits}, g={mid 8 bits}, b={lo 8 bits}
|
||||
*/
|
||||
std::uint32_t code_ = 0;
|
||||
}; /*color_spec*/
|
||||
}; /*color_spec_type*/
|
||||
|
||||
enum color_flags {
|
||||
CF_None = 0x0,
|
||||
|
|
@ -112,10 +112,10 @@ namespace xo {
|
|||
template <typename Contents>
|
||||
class color_impl {
|
||||
public:
|
||||
color_impl(color_flags flags, color_spec spec, Contents && contents)
|
||||
color_impl(color_flags flags, color_spec_type spec, Contents && contents)
|
||||
: flags_{flags}, spec_{spec}, contents_{std::forward<Contents>(contents)} {}
|
||||
|
||||
color_spec const & spec() const { return spec_; }
|
||||
color_spec_type const & spec() const { return spec_; }
|
||||
std::uint32_t color() const { return spec_.code(); }
|
||||
Contents const & contents() const { return contents_; }
|
||||
|
||||
|
|
@ -138,25 +138,25 @@ namespace xo {
|
|||
*/
|
||||
color_flags flags_ = CF_None;
|
||||
|
||||
color_spec spec_;
|
||||
color_spec_type spec_;
|
||||
|
||||
Contents contents_;
|
||||
}; /*color_impl*/
|
||||
|
||||
template <typename Contents>
|
||||
color_impl<Contents> with_color(color_spec spec, Contents && contents) {
|
||||
color_impl<Contents> with_color(color_spec_type spec, Contents && contents) {
|
||||
return color_impl<Contents>(CF_All, spec, std::forward<Contents>(contents));
|
||||
} /*with_color*/
|
||||
|
||||
inline color_impl<int>
|
||||
color_on(color_spec spec) {
|
||||
color_on(color_spec_type spec) {
|
||||
return color_impl<int>(CF_ColorOn, spec, 0);
|
||||
} /*color_on*/
|
||||
|
||||
inline color_impl<int>
|
||||
color_off() {
|
||||
/* any spec other than color_spec::none() works here */
|
||||
return color_impl<int>(CF_ColorOff, color_spec::white(), 0);
|
||||
/* any spec other than color_spec_type::none() works here */
|
||||
return color_impl<int>(CF_ColorOff, color_spec_type::white(), 0);
|
||||
} /*color_off*/
|
||||
|
||||
template <typename Contents>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue