Skip to content

Commit

Permalink
parse: fully fix aligning ascii art and layout
Browse files Browse the repository at this point in the history
why I didn't do it in commit 326a0b5
  • Loading branch information
Toni500github committed Sep 1, 2024
1 parent c8ebfcb commit 3091d0a
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,20 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
if (static_cast<int>(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('.');
Expand All @@ -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
Expand Down Expand Up @@ -427,7 +435,10 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
}

if (config.gui && firstrun_noclr)
output += "</span>";
output += "</span>";

if (!parsingLaoyut && start_pos != std::string::npos)
pureOutput.erase(start_pos, strToReplace.length());
}
}

Expand Down

0 comments on commit 3091d0a

Please sign in to comment.