aboutsummaryrefslogtreecommitdiff
path: root/src/libmain/progress-bar.cc
diff options
context:
space:
mode:
authorQyriad <qyriad@qyriad.me>2024-06-20 13:50:31 -0600
committerQyriad <qyriad@qyriad.me>2024-06-23 16:30:38 +0000
commitce4dee0fa55b15d89e443bdce247a204bf3abeb1 (patch)
tree992710c9362d8dade0cfc817f7cd3ef52628b10d /src/libmain/progress-bar.cc
parent5f0062285c4b39cdf59ca09b46121a8eba771c1b (diff)
mildly refactor the renderActivity if hell-chain
This is primarily for readability, but iwrc chaining std::string's operator+ is also pretty scuffed performance-wise, and this was doing a lot of operator+ chainging. Change-Id: I9f25235df153eb2bbb491f1ff7ebbeed9a8ec985
Diffstat (limited to 'src/libmain/progress-bar.cc')
-rw-r--r--src/libmain/progress-bar.cc66
1 files changed, 47 insertions, 19 deletions
diff --git a/src/libmain/progress-bar.cc b/src/libmain/progress-bar.cc
index b3b46fc21..28bb14863 100644
--- a/src/libmain/progress-bar.cc
+++ b/src/libmain/progress-bar.cc
@@ -402,31 +402,59 @@ std::string ProgressBar::getStatus(State & state)
expected = std::max(expected, act.expected);
- std::string s;
+ std::string rendered;
if (running || done || expected || failed) {
- if (running)
- if (expected != 0)
- s = fmt(ANSI_BLUE + numberFmt + ANSI_NORMAL "/" ANSI_GREEN + numberFmt + ANSI_NORMAL "/" + numberFmt,
- running / unit, done / unit, expected / unit);
- else
- s = fmt(ANSI_BLUE + numberFmt + ANSI_NORMAL "/" ANSI_GREEN + numberFmt + ANSI_NORMAL,
- running / unit, done / unit);
- else if (expected != done)
- if (expected != 0)
- s = fmt(ANSI_GREEN + numberFmt + ANSI_NORMAL "/" + numberFmt,
- done / unit, expected / unit);
- else
- s = fmt(ANSI_GREEN + numberFmt + ANSI_NORMAL, done / unit);
- else
- s = fmt(done ? ANSI_GREEN + numberFmt + ANSI_NORMAL : numberFmt, done / unit);
- s = fmt(itemFmt, s);
+ if (running) {
+ if (expected != 0) {
+ auto const runningPart = fmt(numberFmt, running / unit);
+ auto const donePart = fmt(numberFmt, done / unit);
+ auto const expectedPart = fmt(numberFmt, expected / unit);
+ rendered = fmt(
+ ANSI_BLUE "%s" ANSI_NORMAL "/" ANSI_GREEN "%s" ANSI_NORMAL "/%s",
+ runningPart,
+ donePart,
+ expectedPart
+ );
+ } else {
+ auto const runningPart = fmt(numberFmt, running / unit);
+ auto const donePart = fmt(numberFmt, done / unit);
+ rendered = fmt(
+ 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)
- 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) {