From 00fbdde550c9ba97c95d1f217f6a7d79c0a1289e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Wed, 28 Oct 2015 23:13:50 +0100 Subject: [PATCH] Align all edge numbers to same length when formatting output 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. --- src/build.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/build.cc b/src/build.cc index e4820d06a8..57da61f921 100644 --- a/src/build.cc +++ b/src/build.cc @@ -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; @@ -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;