From 1be7001966c27e4d91d3b7592c3f2e17fd0e636a Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 18 Sep 2023 12:31:14 -0400 Subject: [PATCH] indentlog: refactor: promote use of color_spec --- include/indentlog/color.hpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/include/indentlog/color.hpp b/include/indentlog/color.hpp index 5caa1ace..508507ed 100644 --- a/include/indentlog/color.hpp +++ b/include/indentlog/color.hpp @@ -112,9 +112,10 @@ namespace xo { template class color_impl { public: - color_impl(color_flags flags, color_encoding encoding, std::uint32_t color, Contents && contents) - : flags_{flags}, spec_(encoding, color), contents_{std::forward(contents)} {} + color_impl(color_flags flags, color_spec spec, Contents && contents) + : flags_{flags}, spec_{spec}, contents_{std::forward(contents)} {} + color_spec const & spec() const { return spec_; } std::uint32_t color() const { return spec_.code(); } Contents const & contents() const { return contents_; } @@ -130,6 +131,11 @@ namespace xo { } /*print*/ private: + /* controls independently what to print + * \033[38;5;117m hello, world! \033[0m + * <------------> <-----------> <-----> + * CF_ColorOn CF_Contents CF_ColorOff + */ color_flags flags_ = CF_None; color_spec spec_; @@ -139,38 +145,38 @@ namespace xo { template color_impl with_ansi_color(std::uint32_t color, Contents && contents) { - return color_impl(CF_All, CE_Ansi, color, std::forward(contents)); + return color_impl(CF_All, color_spec::ansi(color), std::forward(contents)); } /*with_ansi_color*/ template color_impl with_xterm_color(std::uint32_t color, Contents && contents) { - return color_impl(CF_All, CE_Xterm, color, std::forward(contents)); + return color_impl(CF_All, color_spec::xterm(color), std::forward(contents)); } /*with_ansi_color*/ template color_impl with_color(color_encoding encoding, std::uint32_t color, Contents && contents) { - return color_impl(CF_All, encoding, color, std::forward(contents)); + return color_impl(CF_All, color_spec(encoding, color), std::forward(contents)); } /*with_color*/ inline color_impl color_on_ansi(std::uint32_t color) { - return color_impl(CF_ColorOn, CE_Ansi, color, 0); + return color_impl(CF_ColorOn, color_spec::ansi(color), 0); } /*color_on_ansi*/ inline color_impl color_on_xterm(std::uint32_t color) { - return color_impl(CF_ColorOn, CE_Xterm, color, 0); + return color_impl(CF_ColorOn, color_spec::xterm(color), 0); } /*color_on_xterm*/ inline color_impl color_on(color_encoding encoding, std::uint32_t color) { - return color_impl(CF_ColorOn, encoding, color, 0); + return color_impl(CF_ColorOn, color_spec(encoding, color), 0); } /*color_on*/ inline color_impl color_off() { - /* any non-zero value works here for color */ - return color_impl(CF_ColorOff, CE_Ansi, 1 /*color*/, 0); + /* any spec other than color_spec::none() works here */ + return color_impl(CF_ColorOff, color_spec::white(), 0); } /*color_off*/ template