From 3091d0a84da74a2c2d8a0e2857a468ff9560ad57 Mon Sep 17 00:00:00 2001 From: Toni500git Date: Sun, 1 Sep 2024 16:52:53 +0200 Subject: [PATCH] parse: fully fix aligning ascii art and layout why I didn't do it in commit 326a0b5 --- src/parse.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/parse.cpp b/src/parse.cpp index 1d8258f..8554c31 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -198,16 +198,20 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s if (static_cast(endBracketIndex) == -1) die("PARSER: Opened tag is not closed at index {} in string {}", dollarSignIndex, output); - const std::string& strToRemove = fmt::format("${}{}{}", opentag, command, type); - const size_t start_pos = pureOutput.find(strToRemove); - if (start_pos != std::string::npos) - pureOutput.erase(start_pos, strToRemove.length()); + const std::string& strToReplace = fmt::format("${}{}{}", opentag, command, type); + const size_t start_pos = pureOutput.find(strToReplace); switch (type) { case ')': - output = output.replace(dollarSignIndex, (endBracketIndex + 1) - dollarSignIndex, shell_exec(command)); - break; + { + const std::string& shell_cmd = shell_exec(command); + output = output.replace(dollarSignIndex, (endBracketIndex + 1) - dollarSignIndex, shell_cmd); + + if (!parsingLaoyut && start_pos != std::string::npos) + pureOutput.replace(start_pos, command.length() + 3, shell_cmd); + + } break; case '>': { const size_t& dot_pos = command.find('.'); @@ -220,6 +224,10 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s output = output.replace(dollarSignIndex, (endBracketIndex + 1) - dollarSignIndex, getInfoFromName(systemInfo, moduleName, moduleValueName)); + + if (!parsingLaoyut && start_pos != std::string::npos) + pureOutput.replace(start_pos, command.length() + 3, + getInfoFromName(systemInfo, moduleName, moduleValueName)); } break; case '}': // please pay very attention when reading this unreadable and godawful code @@ -427,7 +435,10 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s } if (config.gui && firstrun_noclr) - output += ""; + output += ""; + + if (!parsingLaoyut && start_pos != std::string::npos) + pureOutput.erase(start_pos, strToReplace.length()); } }