From a51355417a69dca172bec7e9a07136dd1c790294 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 18 Sep 2023 12:45:57 -0400 Subject: [PATCH] indentlog: refactor: use color_spec in code_location_impl<> inserter --- include/indentlog/code_location.hpp | 13 +++++-------- include/indentlog/function.hpp | 2 -- include/indentlog/log_state.hpp | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/include/indentlog/code_location.hpp b/include/indentlog/code_location.hpp index e0460225..4e4bab21 100644 --- a/include/indentlog/code_location.hpp +++ b/include/indentlog/code_location.hpp @@ -19,13 +19,12 @@ namespace xo { public: code_location_impl(std::string_view file, std::uint32_t line, - color_encoding encoding = CE_Ansi, - std::uint32_t color = 31 /*red*/) - : file_{file}, line_{line}, encoding_{encoding}, color_{color} {} + color_spec colorspec) + : file_{file}, line_{line}, color_spec_{colorspec} {} void print_code_location(std::ostream & os) const { os << "[" - << with_color(color_spec(encoding_, color_), basename(file_)) + << with_color(color_spec_, basename(file_)) << ":" << line_ << "]"; @@ -36,10 +35,8 @@ namespace xo { std::string_view file_; /* __LINE__ */ std::uint32_t line_ = 0; - /* color encoding for file,line */ - color_encoding encoding_ = CE_Ansi; - /* color for file,line */ - std::uint32_t color_ = 0; + /* color encoding for [file:line] */ + color_spec color_spec_; }; /*code_location_impl*/ using code_location = code_location_impl; diff --git a/include/indentlog/function.hpp b/include/indentlog/function.hpp index 1de2301f..bfb107e8 100644 --- a/include/indentlog/function.hpp +++ b/include/indentlog/function.hpp @@ -32,8 +32,6 @@ namespace xo { function_style style() const { return style_; } color_spec const & colorspec() const { return color_spec_; } - //color_encoding encoding() const { return color_spec_.encoding(); } - //std::uint32_t color() const { return color_spec_.code(); } std::string_view const & pretty() const { return pretty_; } /* e.g. diff --git a/include/indentlog/log_state.hpp b/include/indentlog/log_state.hpp index ad92c08e..e99ef44a 100644 --- a/include/indentlog/log_state.hpp +++ b/include/indentlog/log_state.hpp @@ -348,7 +348,7 @@ namespace xo { std::stringstream ss; ss << code_location(this->file_, this->line_, - log_config::encoding, log_config::code_location_color); + color_spec(log_config::encoding, log_config::code_location_color)); std::string ss_str = std::move(ss.str()); /*c++20*/ sbuf2->sputn(ss_str.c_str(), ss_str.size());