]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
progress-bar: Put a space after the prefix
authorAdrian Vovk <adrianvovk@gmail.com>
Sat, 31 Aug 2024 01:25:37 +0000 (21:25 -0400)
committerAdrian Vovk <adrianvovk@gmail.com>
Sat, 31 Aug 2024 01:25:37 +0000 (21:25 -0400)
We always want a space there. So let's just put one in the drawing
routine, and adjust the call cites to avoid adding a second one.

src/import/importctl.c
src/partition/repart.c
src/shared/pretty-print.c
src/test/test-progress-bar.c

index 27c26a70e884777ba9689f20a5620d888d741914..85903bb8c69c9ca52dbd2d5021173dca4fa6a430 100644 (file)
@@ -45,7 +45,7 @@ static const char* arg_format = NULL;
 static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
 static ImageClass arg_image_class = _IMAGE_CLASS_INVALID;
 
-#define PROGRESS_PREFIX "Total: "
+#define PROGRESS_PREFIX "Total:"
 
 static int settle_image_class(void) {
 
index e14c9a4750b018bac1d05c82d9337d2a2f4c49d3..48b3b430137af9f506cf788879a6624958165fc7 100644 (file)
@@ -4553,7 +4553,7 @@ static int progress_bytes(uint64_t n_bytes, void *userdata) {
 
         p->copy_blocks_done += n_bytes;
 
-        if (asprintf(&s, "%s %s %s %s/%s ",
+        if (asprintf(&s, "%s %s %s %s/%s",
                      strna(p->copy_blocks_path),
                      special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
                      strna(p->definition_path),
index f361c4760a0c94287093f48dd6578b711199b2b6..b2a1393fceafe38841ac1e6d13b5d6d99cd3c52e 100644 (file)
@@ -469,12 +469,14 @@ void draw_progress_bar(const char *prefix, double percentage) {
         setvbuf(stderr, buffer, _IOFBF, sizeof(buffer));
 
         fputc('\r', stderr);
-        if (prefix)
+        if (prefix) {
                 fputs(prefix, stderr);
+                fputc(' ', stderr);
+        }
 
         if (!terminal_is_dumb()) {
                 size_t cols = columns();
-                size_t prefix_width = utf8_console_width(prefix);
+                size_t prefix_width = utf8_console_width(prefix) + 1 /* space */;
                 size_t length = cols > prefix_width + 6 ? cols - prefix_width - 6 : 0;
 
                 if (length > 5 && percentage >= 0.0 && percentage <= 100.0) {
@@ -533,8 +535,8 @@ void clear_progress_bar(const char *prefix) {
 
         if (terminal_is_dumb())
                 fputs(strrepa(" ",
-                              prefix ? utf8_console_width(prefix) + 4 :
-                              LESS_BY(columns(), 1U)), /* 4: %3.0f%% */
+                              prefix ? utf8_console_width(prefix) + 5 : /* %3.0f%% (4 chars) + space */
+                              LESS_BY(columns(), 1U)),
                       stderr);
         else
                 fputs(ANSI_ERASE_TO_END_OF_LINE, stderr);
index b47adf0c28974a4b18a47ec5407ae64cabca474c..abc1d292dcbd413f3b6ca487efa930472a01b800 100644 (file)
@@ -4,7 +4,7 @@
 #include "random-util.h"
 #include "tests.h"
 
-#define PROGRESS_PREFIX "test: "
+#define PROGRESS_PREFIX "test:"
 
 TEST(progress_bar) {