diff --git a/include/nestlog/concat.hpp b/include/nestlog/concat.hpp new file mode 100644 index 00000000..31bd6b43 --- /dev/null +++ b/include/nestlog/concat.hpp @@ -0,0 +1,37 @@ +/* @file concat.hpp */ + +#pragma once + +#include +#include // for std::move() + +namespace xo { + template + struct concat_impl { + public: + concat_impl(T1 && x1, T2 && x2) + : x1_{std::forward(x1)}, x2_{std::forward(x2)} {} + + T1 const & x1() const { return x1_; } + T2 const & x2() const { return x2_; } + + private: + T1 x1_; + T2 x2_; + }; /*concat_impl*/ + + template + concat_impl concat(T1 && x1, T2 && x2) { + return concat_impl(std::move(x1), std::move(x2)); + } /*concat*/ + + template + inline std::ostream & + operator<<(std::ostream & os, concat_impl const & x) { + os << x.x1() << x.x2(); + return os; + } /*operator<<*/ + +} /*namespace xo*/ + +/* end concat.hpp */ diff --git a/include/nestlog/log_config.hpp b/include/nestlog/log_config.hpp index b0a3780e..00e49249 100644 --- a/include/nestlog/log_config.hpp +++ b/include/nestlog/log_config.hpp @@ -4,7 +4,7 @@ #include "log_level.hpp" #include "function.hpp" -#include "nestlog/color.hpp" +#include "color.hpp" #include namespace xo { diff --git a/include/nestlog/tag.hpp b/include/nestlog/tag.hpp index 7ac62023..258b432f 100644 --- a/include/nestlog/tag.hpp +++ b/include/nestlog/tag.hpp @@ -2,7 +2,10 @@ #pragma once -#include "nestlog/quoted.hpp" +#include "tag_config.hpp" +#include "concat.hpp" +#include "quoted.hpp" +#include "color.hpp" #include // STRINGIFY(xyz) -> "xyz" @@ -93,7 +96,7 @@ namespace xo { if(PrefixSpace) s << " "; - s << ":" << tag.name() + s << with_color(tag_config::encoding, tag_config::tag_color, concat((char const *)":", tag.name())) << " " << unq(tag.value()); return s; diff --git a/include/nestlog/tag_config.hpp b/include/nestlog/tag_config.hpp new file mode 100644 index 00000000..d4a67cb7 --- /dev/null +++ b/include/nestlog/tag_config.hpp @@ -0,0 +1,34 @@ +/* @file tag_config.hpp */ + +#pragma once + +#include "color.hpp" +#include + +namespace xo { + /* Tag here b/c we want header-only library */ + template + struct tag_config_impl { + /* color encoding */ + static color_encoding encoding; + /* color to use for tags + * os << tag("foo", foovalue) + * to produces output like + * :foo foovalue + * with :foo using .tag_color + */ + static std::uint32_t tag_color; + }; /*tag_config_impl*/ + + template + color_encoding + tag_config_impl::encoding = CE_Xterm; + + template + std::uint32_t + tag_config_impl::tag_color = 245; + + using tag_config = tag_config_impl; +} /*namespace xo*/ + +/* end tag_config.hpp */