Skip to content

Commit

Permalink
Align all edge numbers to same length when formatting output
Browse files Browse the repository at this point in the history
So when updating status output on terminal, make sure that all numbers will
be always aligned at same length. Even if progress variables change number
of characters.
  • Loading branch information
pali committed Oct 28, 2015
1 parent 083b6b0 commit 00fbdde
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ string BuildStatus::FormatProgressStatus(
string out;
char buf[32];
int percent;
char total_edges_str[32];
snprintf(total_edges_str, sizeof(total_edges_str), "%d", total_edges_);
int total_edges_len = strlen(total_edges_str);
for (const char* s = progress_status_format; *s != '\0'; ++s) {
if (*s == '%') {
++s;
Expand All @@ -170,31 +173,30 @@ string BuildStatus::FormatProgressStatus(

// Started edges.
case 's':
snprintf(buf, sizeof(buf), "%d", started_edges_);
snprintf(buf, sizeof(buf), "%*d", total_edges_len, started_edges_);
out += buf;
break;

// Total edges.
case 't':
snprintf(buf, sizeof(buf), "%d", total_edges_);
out += buf;
out += total_edges_str;
break;

// Running edges.
case 'r':
snprintf(buf, sizeof(buf), "%d", started_edges_ - finished_edges_);
snprintf(buf, sizeof(buf), "%*d", total_edges_len, started_edges_ - finished_edges_);
out += buf;
break;

// Unstarted edges.
case 'u':
snprintf(buf, sizeof(buf), "%d", total_edges_ - started_edges_);
snprintf(buf, sizeof(buf), "%*d", total_edges_len, total_edges_ - started_edges_);
out += buf;
break;

// Finished edges.
case 'f':
snprintf(buf, sizeof(buf), "%d", finished_edges_);
snprintf(buf, sizeof(buf), "%*d", total_edges_len, finished_edges_);
out += buf;
break;

Expand Down

0 comments on commit 00fbdde

Please sign in to comment.