Skip to content

Commit 4363eb8

Browse files
committed
parse (and ascii art): make it compilable in C++17 + fix bsd.txt for GUI
I said I don't want to support C++17 officially, but at the same time a small patch doesn't hurt anyone
1 parent 4d1a24f commit 4363eb8

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

assets/ascii/bsd.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ ${red} /- _ `-/ '
55
${red} (${1}/\/ \ ${red}\ /\
66
${red} ${1}/ / | ` ${red}\
77
${red} ${blue}O O ${1}) ${red}/ |
8-
${red} ${1}`-^--'${red}`< '
8+
${red} ${1}`-^--'${red}`\< '
99
${red} (_.) _ ) /
1010
${red} `.___/` /
1111
${red} `-----' /
12-
${yellow}<----. __ / __ \
13-
${yellow}<----|====${red}O)))${yellow}==${red}) \) /${yellow}====|
14-
${yellow}<----' ${red}`--' `.__,' \
12+
${yellow}\<----. __ / __ \
13+
${yellow}\<----|====${red}O)))${yellow}==${red}) \) /${yellow}====|
14+
${yellow}\<----' ${red}`--' `.__,' \
1515
${red} | |
1616
${red} \ / /\
1717
${cyan} ______${red}( (_ / \______/

src/parse.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
241241
if (static_cast<int>(endBracketIndex) == -1)
242242
die("PARSER: Opened tag is not closed at index {} in string {}", dollarSignIndex, output);
243243

244-
const std::string& strToReplace = fmt::format("${}{}{}", opentag, command, type);
245-
const size_t start_pos = pureOutput.find(strToReplace);
244+
const std::string& tagToReplace = fmt::format("${}{}{}", opentag, command, type);
245+
const size_t tagpos = pureOutput.find(tagToReplace);
246246
const size_t taglen = (endBracketIndex + 1) - dollarSignIndex;
247247

248248
switch (type)
@@ -252,8 +252,8 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
252252
const std::string& shell_cmd = shell_exec(command);
253253
output.replace(dollarSignIndex, taglen, shell_cmd);
254254

255-
if (!parsingLayout && start_pos != std::string::npos)
256-
pureOutput.replace(start_pos, taglen, shell_cmd);
255+
if (!parsingLayout && tagpos != std::string::npos)
256+
pureOutput.replace(tagpos, taglen, shell_cmd);
257257

258258
} break;
259259

@@ -270,8 +270,8 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
270270
output.replace(dollarSignIndex, taglen,
271271
getInfoFromName(systemInfo, moduleName, moduleMemberName));
272272

273-
if (!parsingLayout && start_pos != std::string::npos)
274-
pureOutput.replace(start_pos, taglen,
273+
if (!parsingLayout && tagpos != std::string::npos)
274+
pureOutput.replace(tagpos, taglen,
275275
getInfoFromName(systemInfo, moduleName, moduleMemberName));
276276
} break;
277277

@@ -407,7 +407,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
407407
const size_t pos = str_clr.find('#');
408408
if (pos != std::string::npos)
409409
{
410-
std::string tagfmt = "<span ";
410+
std::string tagfmt = "span ";
411411

412412
const std::string& opt_clr = str_clr.substr(0, pos);
413413

@@ -426,10 +426,9 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
426426
tagfmt += "style='italic' ";
427427

428428
tagfmt.pop_back();
429-
tagfmt += '>';
430429

431430
output.replace(dollarSignIndex, output.length() - dollarSignIndex,
432-
fmt::format("{}{}</span>",
431+
fmt::format("<{}>{}</span>",
433432
tagfmt, output.substr(endBracketIndex + 1)));
434433
}
435434

@@ -520,8 +519,8 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
520519
if (config.gui && firstrun_noclr)
521520
output += "</span>";
522521

523-
if (!parsingLayout && start_pos != std::string::npos)
524-
pureOutput.erase(start_pos, strToReplace.length());
522+
if (!parsingLayout && tagpos != std::string::npos)
523+
pureOutput.erase(tagpos, tagToReplace.length());
525524
}
526525
}
527526

@@ -549,8 +548,8 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
549548
return output;
550549
}
551550

552-
static std::string get_auto_uptime(const std::uint16_t days, const std::uint16_t hours, const std::uint16_t mins,
553-
const std::uint16_t secs, const Config& config)
551+
static std::string get_auto_uptime(const std::uint16_t days, const std::uint16_t hours, const std::uint16_t mins, const std::uint16_t secs,
552+
const Config& config)
554553
{
555554
if (days == 0 && hours == 0 && mins == 0)
556555
return fmt::format("{}{}", secs, config.uptime_s_fmt);
@@ -667,9 +666,11 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
667666
Query::System query_system;
668667

669668
std::chrono::seconds uptime_secs(query_system.uptime());
670-
auto uptime_mins = std::chrono::duration_cast<std::chrono::minutes>(uptime_secs);
671-
auto uptime_hours = std::chrono::duration_cast<std::chrono::hours>(uptime_secs);
672-
auto uptime_days = std::chrono::duration_cast<std::chrono::days>(uptime_secs);
669+
const auto& uptime_mins = std::chrono::duration_cast<std::chrono::minutes>(uptime_secs);
670+
const auto& uptime_hours = std::chrono::duration_cast<std::chrono::hours>(uptime_secs);
671+
672+
// let's support a little of C++17 without any `#if __cpluscplus` stuff
673+
const std::uint16_t uptime_days = uptime_secs.count() / (60 * 60 * 24);
673674

674675
if (sysInfo.find(moduleName) == sysInfo.end())
675676
sysInfo.insert({ moduleName, {} });
@@ -681,7 +682,7 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
681682
case "name"_fnv1a16: SYSINFO_INSERT(query_system.os_pretty_name()); break;
682683

683684
case "uptime"_fnv1a16:
684-
SYSINFO_INSERT(get_auto_uptime(uptime_days.count(), uptime_hours.count() % 24,
685+
SYSINFO_INSERT(get_auto_uptime(uptime_days, uptime_hours.count() % 24,
685686
uptime_mins.count() % 60, uptime_secs.count() % 60, config));
686687
break;
687688

@@ -691,7 +692,7 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
691692

692693
case "uptime_hours"_fnv1a16: SYSINFO_INSERT(static_cast<size_t>(uptime_hours.count()) % 24); break;
693694

694-
case "uptime_days"_fnv1a16: SYSINFO_INSERT(static_cast<size_t>(uptime_days.count())); break;
695+
case "uptime_days"_fnv1a16: SYSINFO_INSERT(static_cast<size_t>(uptime_days)); break;
695696

696697
case "kernel"_fnv1a16:
697698
SYSINFO_INSERT(query_system.kernel_name() + ' ' + query_system.kernel_version());

0 commit comments

Comments
 (0)