mildly refactor the formatting in the renderActivity hell if-chain

Change-Id: I9f25235df153eb2bbb491f1ff7ebbeed9a8ec985
This commit is contained in:
Qyriad 2024-06-19 22:24:12 -06:00
parent 7e6542d511
commit 9580b6846e

View file

@ -366,31 +366,59 @@ std::string ProgressBar::getStatus(State & state)
expected = std::max(expected, act.expected); expected = std::max(expected, act.expected);
std::string s; std::string rendered;
if (running || done || expected || failed) { if (running || done || expected || failed) {
if (running) if (running) {
if (expected != 0) if (expected != 0) {
s = fmt(ANSI_BLUE + numberFmt + ANSI_NORMAL "/" ANSI_GREEN + numberFmt + ANSI_NORMAL "/" + numberFmt, auto const runningPart = fmt(numberFmt, running / unit);
running / unit, done / unit, expected / unit); auto const donePart = fmt(numberFmt, done / unit);
else auto const expectedPart = fmt(numberFmt, expected / unit);
s = fmt(ANSI_BLUE + numberFmt + ANSI_NORMAL "/" ANSI_GREEN + numberFmt + ANSI_NORMAL, rendered = fmt(
running / unit, done / unit); ANSI_BLUE "%s" ANSI_NORMAL "/" ANSI_GREEN "%s" ANSI_NORMAL "/%s",
else if (expected != done) runningPart,
if (expected != 0) donePart,
s = fmt(ANSI_GREEN + numberFmt + ANSI_NORMAL "/" + numberFmt, expectedPart
done / unit, expected / unit); );
else } else {
s = fmt(ANSI_GREEN + numberFmt + ANSI_NORMAL, done / unit); auto const runningPart = fmt(numberFmt, running / unit);
else auto const donePart = fmt(numberFmt, done / unit);
s = fmt(done ? ANSI_GREEN + numberFmt + ANSI_NORMAL : numberFmt, done / unit); rendered = fmt(
s = fmt(itemFmt, s); ANSI_BLUE "%s" ANSI_NORMAL "/" ANSI_GREEN "%s" ANSI_NORMAL,
runningPart,
donePart
);
}
} else if (expected != done) {
if (expected != 0) {
auto const donePart = fmt(numberFmt, done / unit);
auto const expectedPart = fmt(numberFmt, expected / unit);
rendered = fmt(
ANSI_GREEN "%s" ANSI_NORMAL "/%s",
donePart,
expectedPart
);
} else {
auto const donePart = fmt(numberFmt, done / unit);
rendered = fmt(ANSI_GREEN "%s" ANSI_NORMAL, donePart);
}
} else {
auto const donePart = fmt(numberFmt, done / unit);
// We only color if `done` is non-zero.
if (done) {
rendered = concatStrings(ANSI_GREEN, donePart, ANSI_NORMAL);
} else {
rendered = donePart;
}
}
rendered = fmt(itemFmt, rendered);
if (failed) if (failed)
s += fmt(" (" ANSI_RED "%d failed" ANSI_NORMAL ")", failed / unit); rendered += fmt(" (" ANSI_RED "%d failed" ANSI_NORMAL ")", failed / unit);
} }
return s; return rendered;
}; };
auto showActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) { auto showActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {