From 346eef69a42cdbc17cf9c991a230ef64f1db9d8a Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 18 Sep 2023 13:06:28 -0400 Subject: [PATCH] indentlog: refactor: color_spec -> color_spec_type --- example/ex3/ex3.cpp | 6 +-- include/indentlog/code_location.hpp | 4 +- include/indentlog/color.hpp | 62 ++++++++++++++--------------- include/indentlog/function.hpp | 6 +-- include/indentlog/log_config.hpp | 24 +++++------ include/indentlog/log_state.hpp | 2 +- include/indentlog/tag.hpp | 2 +- 7 files changed, 53 insertions(+), 53 deletions(-) diff --git a/example/ex3/ex3.cpp b/example/ex3/ex3.cpp index ab343dd4..cc592a5b 100644 --- a/example/ex3/ex3.cpp +++ b/example/ex3/ex3.cpp @@ -31,9 +31,9 @@ main(int argc, char ** argv) { log_config::indent_width = 4; log_config::max_indent_width = 30; log_config::location_tab = 80; - log_config::function_entry_color = color_spec::xterm(69); - log_config::function_exit_color = color_spec::xterm(70); - log_config::code_location_color = color_spec::xterm(166); + log_config::function_entry_color = color_spec_type::xterm(69); + log_config::function_exit_color = color_spec_type::xterm(70); + log_config::code_location_color = color_spec_type::xterm(166); int n = 3; diff --git a/include/indentlog/code_location.hpp b/include/indentlog/code_location.hpp index 4e4bab21..cd6c9308 100644 --- a/include/indentlog/code_location.hpp +++ b/include/indentlog/code_location.hpp @@ -19,7 +19,7 @@ namespace xo { public: code_location_impl(std::string_view file, std::uint32_t line, - color_spec colorspec) + color_spec_type colorspec) : file_{file}, line_{line}, color_spec_{colorspec} {} void print_code_location(std::ostream & os) const { @@ -36,7 +36,7 @@ namespace xo { /* __LINE__ */ std::uint32_t line_ = 0; /* color encoding for [file:line] */ - color_spec color_spec_; + color_spec_type color_spec_; }; /*code_location_impl*/ using code_location = code_location_impl; diff --git a/include/indentlog/color.hpp b/include/indentlog/color.hpp index 32661d9b..52548b5a 100644 --- a/include/indentlog/color.hpp +++ b/include/indentlog/color.hpp @@ -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 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)} {} - 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 - color_impl with_color(color_spec spec, Contents && contents) { + color_impl with_color(color_spec_type spec, Contents && contents) { return color_impl(CF_All, spec, std::forward(contents)); } /*with_color*/ inline color_impl - color_on(color_spec spec) { + color_on(color_spec_type spec) { return color_impl(CF_ColorOn, spec, 0); } /*color_on*/ inline color_impl color_off() { - /* any spec other than color_spec::none() works here */ - return color_impl(CF_ColorOff, color_spec::white(), 0); + /* any spec other than color_spec_type::none() works here */ + return color_impl(CF_ColorOff, color_spec_type::white(), 0); } /*color_off*/ template diff --git a/include/indentlog/function.hpp b/include/indentlog/function.hpp index bfb107e8..d68c75b9 100644 --- a/include/indentlog/function.hpp +++ b/include/indentlog/function.hpp @@ -26,12 +26,12 @@ namespace xo { * 31 = red */ function_name_impl(function_style style, - color_spec const & spec, + color_spec_type const & spec, std::string_view pretty) : style_{style}, color_spec_{spec}, pretty_{pretty} {} function_style style() const { return style_; } - color_spec const & colorspec() const { return color_spec_; } + color_spec_type const & colorspec() const { return color_spec_; } std::string_view const & pretty() const { return pretty_; } /* e.g. @@ -231,7 +231,7 @@ namespace xo { /* FS_Simple | FS_Pretty (= FS_Literal) | FS_Streamlined */ function_style style_; /* terminal color (controls vt100 escape) */ - color_spec color_spec_; + color_spec_type color_spec_; /* e.g. __PRETTY_FUNCTION__ */ std::string_view pretty_; }; /*function_name_impl*/ diff --git a/include/indentlog/log_config.hpp b/include/indentlog/log_config.hpp index ff63ade1..22371bb7 100644 --- a/include/indentlog/log_config.hpp +++ b/include/indentlog/log_config.hpp @@ -26,20 +26,20 @@ namespace xo { /* if true enable explicit nesting level display [nnn] */ static bool nesting_level_enabled; /* color to use for explicit nesting level */ - static color_spec nesting_level_color; + static color_spec_type nesting_level_color; /* display style for function names. FS_Simple|FS_Pretty|FS_Streamlined */ static function_style style; /* color to use for function name, on entry/exit (xo::scope creation/destruction) * (ansi color codes, see Select Graphics Rendition subset) */ - static color_spec function_entry_color; - static color_spec function_exit_color; + static color_spec_type function_entry_color; + static color_spec_type function_exit_color; /* if true, append [file:line] to output */ static bool location_enabled; /* when .location_enabled, write [file:line] starting this many chars from left margin */ static std::uint32_t location_tab; /* color to use for code location */ - static color_spec code_location_color; + static color_spec_type code_location_color; }; /*log_config_impl*/ template @@ -71,20 +71,20 @@ namespace xo { log_config_impl::nesting_level_enabled = true; template - color_spec - log_config_impl::nesting_level_color = color_spec::xterm(195); + color_spec_type + log_config_impl::nesting_level_color = color_spec_type::xterm(195); template function_style log_config_impl::style = FS_Streamlined; template - color_spec - log_config_impl::function_entry_color = color_spec::ansi(34); + color_spec_type + log_config_impl::function_entry_color = color_spec_type::ansi(34); template - color_spec - log_config_impl::function_exit_color = color_spec::ansi(32); + color_spec_type + log_config_impl::function_exit_color = color_spec_type::ansi(32); template bool @@ -95,8 +95,8 @@ namespace xo { log_config_impl::location_tab = 80; template - color_spec - log_config_impl::code_location_color = color_spec::red(); + color_spec_type + log_config_impl::code_location_color = color_spec_type::red(); using log_config = log_config_impl; } /*namespace xo*/ diff --git a/include/indentlog/log_state.hpp b/include/indentlog/log_state.hpp index c1450779..66f1e15d 100644 --- a/include/indentlog/log_state.hpp +++ b/include/indentlog/log_state.hpp @@ -194,7 +194,7 @@ namespace xo { this->indent(' '); char ee_label = '\0'; - color_spec fn_color; + color_spec_type fn_color; /* mnemonic for scope entry/exit */ switch(entryexit) { diff --git a/include/indentlog/tag.hpp b/include/indentlog/tag.hpp index a6825bee..7b22e67b 100644 --- a/include/indentlog/tag.hpp +++ b/include/indentlog/tag.hpp @@ -96,7 +96,7 @@ namespace xo { if(PrefixSpace) s << " "; - s << with_color(color_spec(tag_config::encoding, tag_config::tag_color), concat((char const *)":", tag.name())) + s << with_color(color_spec_type(tag_config::encoding, tag_config::tag_color), concat((char const *)":", tag.name())) << " " << unq(tag.value()); return s;