From ca05767dffbefd432b02631dd76a5542a1140438 Mon Sep 17 00:00:00 2001 From: heck Date: Mon, 7 Jun 2021 12:57:14 +0200 Subject: [PATCH] std_utils: Add termCol support --- src/std_utils.cc | 26 +++++++++++++++++++++++++- src/std_utils.hh | 15 +++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/std_utils.cc b/src/std_utils.cc index e47a995..b78c385 100644 --- a/src/std_utils.cc +++ b/src/std_utils.cc @@ -110,7 +110,6 @@ namespace pEp { return outfile; } - void path_ensure_not_existing(const string &path) { while (path_exists(path)) { @@ -192,5 +191,30 @@ namespace pEp { return ret; } + string to_termcol(const Color& col) + { + switch (col) { + case Color::RESET: + return "\033[0m"; + case Color::BLACK: + return "\033[30m"; + case Color::RED: + return "\033[31m"; + case Color::GREEN: + return "\033[32m"; + case Color::YELLOW: + return "\033[33m"; + case Color::BLUE: + return "\033[34m"; + case Color::MAGENTA: + return "\033[35m"; + case Color::CYAN: + return "\033[36m"; + case Color::WHITE: + return "\033[37m"; + default: + return "\033[0m"; + } + } } // namespace Utils } // namespace pEp diff --git a/src/std_utils.hh b/src/std_utils.hh index de67c1f..35775f0 100644 --- a/src/std_utils.hh +++ b/src/std_utils.hh @@ -45,6 +45,21 @@ namespace pEp { //String formatting std::string padTo(const std::string &str, const size_t num, const char paddingChar); + enum class Color + { + RESET, + BLACK, + RED, + GREEN, + YELLOW, + BLUE, + MAGENTA, + CYAN, + WHITE, + }; + + std::string to_termcol(const Color& col); + } // namespace Utils } // namespace pEp