Skip to content

Commit

Permalink
parse: fix linuxlite_small ASCII logo + remove bypass '\\$' backslash
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Sep 23, 2024
1 parent 2ba9938 commit 1ac0c10
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 49 deletions.
38 changes: 19 additions & 19 deletions assets/ascii/centos.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
${c1} ..
.PLTJ.
<><><><>
${c2}KKSSV' 4KKK ${c1}LJ${c4} KKKL.'VSSKK
${c2}KKV' 4KKKKK ${c1}LJ${c4} KKKKAL 'VKK
${c2}V' ' 'VKKKK ${c1}LJ${c4} KKKKV' ' 'V
${c2}.4MA.' 'VKK ${c1}LJ${c4} KKV' '.4Mb.
${c4} . ${c2}KKKKKA.' 'V ${c1}LJ${c4} V' '.4KKKKK ${c3}.
${c4} .4D ${c2}KKKKKKKA.'' ${c1}LJ${c4} ''.4KKKKKKK ${c3}FA.
${c4}<QDD ++++++++++++ ${c3}++++++++++++ GFD>
${c4} 'VD ${c3}KKKKKKKK'.. ${c2}LJ ${c1}..'KKKKKKKK ${c3}FV
${c4} ' ${c3}VKKKKK'. .4 ${c2}LJ ${c1}K. .'KKKKKV ${c3}'
${c3} 'VK'. .4KK ${c2}LJ ${c1}KKA. .'KV'
${c3}A. . .4KKKK ${c2}LJ ${c1}KKKKA. . .4
${c3}KKA. 'KKKKK ${c2}LJ ${c1}KKKKK' .4KK
${c3}KKSSA. VKKK ${c2}LJ ${c1}KKKV .4SSKK
${c2} <><><><>
'MKKM'
''
${yellow} ..
${yellow} .PLTJ.
${yellow} <><><><>
${green}KKSSV' 4KKK ${yellow}LJ${magenta} KKKL.'VSSKK
${green}KKV' 4KKKKK ${yellow}LJ${magenta} KKKKAL 'VKK
${green}V' ' 'VKKKK ${yellow}LJ${magenta} KKKKV' ' 'V
${green}.4MA.' 'VKK ${yellow}LJ${magenta} KKV' '.4Mb.
${magenta} . ${green}KKKKKA.' 'V ${yellow}LJ${magenta} V' '.4KKKKK ${blue}.
${magenta} .4D ${green}KKKKKKKA.'' ${yellow}LJ${magenta} ''.4KKKKKKK ${blue}FA.
${magenta}<QDD ++++++++++++ ${blue}++++++++++++ GFD>
${magenta} 'VD ${blue}KKKKKKKK'.. ${green}LJ ${yellow}..'KKKKKKKK ${blue}FV
${magenta} ' ${blue}VKKKKK'. .4 ${green}LJ ${yellow}K. .'KKKKKV ${blue}'
${blue} 'VK'. .4KK ${green}LJ ${yellow}KKA. .'KV'
${blue}A. . .4KKKK ${green}LJ ${yellow}KKKKA. . .4
${blue}KKA. 'KKKKK ${green}LJ ${yellow}KKKKK' .4KK
${blue}KKSSA. VKKK ${green}LJ ${yellow}KKKV .4SSKK
${green} <><><><>
${green} 'MKKM'
${green} ''
14 changes: 7 additions & 7 deletions assets/ascii/centos_small.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
${c2} ____${c1}^${c4}____
${c2} |\\ ${c1}|${c4} /|
${c2} | \\ ${c1}|${c4} / |
${c4}<---- ${c3}---->
${c3} | / ${c2}|${c1} \\ |
${c3} |/__${c2}|${c1}__\\|
${c2} v
${green} ____${yellow}^${magenta}____
${green} |\ ${yellow}|${magenta} /|
${green} | \ ${yellow}|${magenta} / |
${magenta}<---- ${blue}---->
${blue} | / ${green}|${yellow} \ |
${blue} |/__${green}|${yellow}__\|
${green} v
10 changes: 5 additions & 5 deletions assets/ascii/linuxlite_small.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
${yellow} /\\
${yellow} / \\
${yellow} /\
${yellow} / \
${yellow} / ${1}/ ${yellow}/
${yellow}> ${1}/ ${yellow}/
${yellow}\\ ${1}\\ ${yellow}\\
${yellow} \\_${1}\\${yellow}_\\
${1} \\
${yellow}\ ${1}\ ${yellow}\
${yellow} \_${1}\\${yellow}_\
${1} \
2 changes: 1 addition & 1 deletion assets/ascii/raspbian_small.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
${red}${green} .. ,.
${green} :oo: .:oo:
${green} 'o\\o o/o:
${green} 'o\o o/o:
${red} :: . :: . ::
${red}:: ::: ::: ::
${red}:' '',.'' ':
Expand Down
3 changes: 1 addition & 2 deletions include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::string name_from_entry(size_t dev_entry_pos);
std::string vendor_from_entry(size_t vendor_entry_pos, const std::string_view vendor_id);
std::string binarySearchPCIArray(const std::string_view vendor_id, const std::string_view pci_id);
std::string binarySearchPCIArray(const std::string_view vendor_id);
std::string shell_exec(const std::string_view cmd);
std::string read_shell_exec(const std::string_view cmd);
void getFileValue(u_short& iterIndex, const std::string_view line, std::string& str, const size_t& amount);
byte_units_t auto_devide_bytes(const size_t num);
bool is_file_image(const unsigned char* bytes);
Expand All @@ -72,7 +72,6 @@ std::string str_toupper(std::string str);
void strip(std::string& input);
std::string read_by_syspath(const std::string_view path);
fmt::rgb hexStringToColor(const std::string_view hexstr);
void shorten_vendor_name_inplace(std::string& vendor);
std::string shorten_vendor_name(std::string vendor);
std::string getHomeConfigDir();
std::string getConfigDir();
Expand Down
2 changes: 1 addition & 1 deletion src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

std::string Display::detect_distro(const Config& config)
{
debug("/etc/os-release = \n{}", shell_exec("cat /etc/os-release"));
debug("/etc/os-release = \n{}", read_shell_exec("cat /etc/os-release"));

if (!config.m_custom_distro.empty())
{
Expand Down
32 changes: 26 additions & 6 deletions src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
size_t dollarSignIndex = 0;
size_t oldDollarSignIndex = 0;
bool start = false;
bool skip_bypass = false;

// we only use it in GUI mode,
// prevent issue where in the ascii art,
Expand Down Expand Up @@ -216,9 +217,28 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
// btw the second part checks if it has a \ before it and NOT a \ before the backslash, (check for escaped
// backslash) example: \$ is bypassed, \\$ is NOT bypassed. this will not make an effort to check multiple
// backslashes, thats your fault atp.
if (dollarSignIndex > 0 and
(output[dollarSignIndex - 1] == '\\' and (dollarSignIndex == 1 or output[dollarSignIndex - 2] != '\\')))
continue;
if (skip_bypass)
{
if (dollarSignIndex > 0 and
(output[dollarSignIndex - 1] == '\\' and (dollarSignIndex == 1 or output[dollarSignIndex - 2] != '\\')))
{
skip_bypass = false;
continue;
}
}

// maybe let's remove the bypass '\\$'
if (output[dollarSignIndex - 1] == '\\' and output[dollarSignIndex - 2] == '\\')
{
skip_bypass = true;
output.erase(dollarSignIndex - 1, 1);

const size_t pos = pureOutput.find("\\\\$");
if (pos != pureOutput.npos)
pureOutput.erase(pos, 1);

dollarSignIndex--;
}

std::string command;
size_t endBracketIndex = -1;
Expand Down Expand Up @@ -269,13 +289,13 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
if (removetag)
command.erase(0,1);

const std::string& shell_cmd = shell_exec(command);
output.replace(dollarSignIndex, taglen, shell_cmd);
const std::string& cmd_output = read_shell_exec(command);
output.replace(dollarSignIndex, taglen, cmd_output);

if (!parsingLayout && tagpos != std::string::npos)
{
if (!removetag)
pureOutput.replace(tagpos, taglen, shell_cmd);
pureOutput.replace(tagpos, taglen, cmd_output);
else
pureOutput.erase(tagpos, taglen);
}
Expand Down
4 changes: 2 additions & 2 deletions src/query/unix/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ static std::string get_shell_version(const std::string_view shell_name)
std::string ret;

if (shell_name == "nu")
ret = shell_exec("nu -c \"version | get version\"");
ret = read_shell_exec("nu -c \"version | get version\"");
else
ret = shell_exec(fmt::format("{} -c 'echo \"${}_VERSION\"'", shell_name, str_toupper(shell_name.data())));
ret = read_shell_exec(fmt::format("{} -c 'echo \"${}_VERSION\"'", shell_name, str_toupper(shell_name.data())));

strip(ret);
return ret;
Expand Down
9 changes: 3 additions & 6 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void getFileValue(u_short& iterIndex, const std::string_view line, std::string&
iterIndex++;
}

void shorten_vendor_name_inplace(std::string& vendor)
std::string shorten_vendor_name(std::string vendor)
{
if (vendor.find("AMD") != vendor.npos ||
vendor.find("Advanced Micro") != vendor.npos)
Expand All @@ -220,11 +220,7 @@ void shorten_vendor_name_inplace(std::string& vendor)
size_t pos = 0;
if ((pos = vendor.rfind("Corporation")) != vendor.npos)
vendor.erase(pos - 1);
}

std::string shorten_vendor_name(std::string vendor)
{
shorten_vendor_name_inplace(vendor);
return vendor;
}

Expand Down Expand Up @@ -506,7 +502,7 @@ std::string binarySearchPCIArray(const std::string_view vendor_id_s)
}

// http://stackoverflow.com/questions/478898/ddg#478960
std::string shell_exec(const std::string_view cmd)
std::string read_shell_exec(const std::string_view cmd)
{
std::array<char, 1024> buffer;
std::string result;
Expand All @@ -522,6 +518,7 @@ std::string shell_exec(const std::string_view cmd)
// why there is a '\n' at the end??
if (!result.empty() && result.back() == '\n')
result.pop_back();

return result;
}

Expand Down

0 comments on commit 1ac0c10

Please sign in to comment.