From 05f45e174b75e1a87b3ce5e457c3e2b70e6f43e5 Mon Sep 17 00:00:00 2001 From: Toni500git Date: Tue, 3 Sep 2024 22:40:55 +0200 Subject: [PATCH] config: add sep-reset-after --- include/config.hpp | 6 ++++++ src/config.cpp | 1 + src/parse.cpp | 25 ++++++++++++++++++------- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/include/config.hpp b/include/config.hpp index 465d737..46a14ed 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -48,6 +48,7 @@ class Config std::uint16_t logo_padding_top = 0; std::uint16_t layout_padding_top = 0; bool gui = false; + bool sep_reset_after = false; // modules specific config std::string uptime_d_fmt; @@ -183,6 +184,11 @@ sep-title = "-" # Make it empty for disabling sep-reset = ":" +# Should we reset color after or before the separetor? +# true = after ("test:${0} ") +# false = before ("test${0}: ") +sep-reset-after = false + # Offset between the ascii art and the layout offset = 5 diff --git a/src/config.cpp b/src/config.cpp index 6939edc..04b3a4b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -40,6 +40,7 @@ void Config::loadConfigFile(const std::string_view filename, colors_t& colors) // Idk but with `this->` looks more readable this->layout = this->getValueArrayStr("config.layout", {}); this->gui = this->getValue("gui.enable", false); + this->sep_reset_after = this->getValue("config.sep-reset-after", false); this->ascii_logo_type = this->getValue("config.ascii-logo-type", ""); this->source_path = this->getValue("config.source-path", "os"); this->data_dir = this->getValue("config.data-dir", "/usr/share/customfetch"); diff --git a/src/parse.cpp b/src/parse.cpp index b23c657..0d3f112 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -129,12 +129,22 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s // theres at first either ${1} or ${0} // and that's a problem with pango markup bool firstrun_noclr = true; + + static std::vector auto_colors; if (!config.sep_reset.empty() && parsingLaoyut) { - replace_str(output, config.sep_reset, "${0}" + config.sep_reset); - replace_str(pureOutput, config.sep_reset, "${0}" + config.sep_reset); + if (config.sep_reset_after) + { + replace_str(output, config.sep_reset, config.sep_reset + "${0}"); + replace_str(pureOutput, config.sep_reset, config.sep_reset + "${0}"); + } + else + { + replace_str(output, config.sep_reset, "${0}" + config.sep_reset); + replace_str(pureOutput, config.sep_reset, "${0}" + config.sep_reset); + } } while (true) @@ -183,6 +193,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s if (type == ' ') continue; + // let's get what's inside the brackets for (size_t i = dollarSignIndex + 2; i < output.size(); i++) { if (output.at(i) == type && output[i - 1] != '\\') @@ -221,8 +232,8 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s if (dot_pos == std::string::npos) die("module name '{}' doesn't have a dot '.' for separiting module name and submodule", command); - const std::string& moduleName(command.substr(0, dot_pos)); - const std::string& moduleValueName(command.substr(dot_pos + 1)); + const std::string& moduleName = command.substr(0, dot_pos); + const std::string& moduleValueName = command.substr(dot_pos + 1); addValueFromModule(systemInfo, moduleName, moduleValueName, config); output = output.replace(dollarSignIndex, (endBracketIndex + 1) - dollarSignIndex, @@ -235,15 +246,15 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s case ']': { - const size_t condition_comma = command.find(','); + const size_t& condition_comma = command.find(','); if (condition_comma == command.npos) die("condition component {} doesn't have a comma for separiting the condition", command); - const size_t equalto_comma = command.find(',', condition_comma + 1); + const size_t& equalto_comma = command.find(',', condition_comma + 1); if (equalto_comma == command.npos) die("condition component {} doesn't have a comma for separiting the equalto", command); - const size_t true_comma = command.find(',', equalto_comma + 1); + const size_t& true_comma = command.find(',', equalto_comma + 1); if (true_comma == command.npos) die("condition component {} doesn't have a comma for separiting the true statment", command);