pretty-print: add format-string version of draw_progress_bar()

We often format the prefix string via asprintf() before, let's hence add
a helper for that.
This commit is contained in:
Lennart Poettering
2024-10-29 21:37:26 +01:00
parent 21abc0a943
commit 91d640435d
8 changed files with 61 additions and 58 deletions
+8 -11
View File
@@ -124,17 +124,14 @@ static void raw_export_report_progress(RawExport *e) {
sd_notifyf(false, "X_IMPORT_PROGRESS=%u%%", percent);
if (isatty_safe(STDERR_FILENO)) {
_cleanup_free_ char *s = NULL;
if (asprintf(&s, "%s %s/%s",
special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
FORMAT_BYTES(e->written_uncompressed),
FORMAT_BYTES(e->st.st_size)) < 0)
return;
draw_progress_bar(s, percent);
} else
if (isatty_safe(STDERR_FILENO))
(void) draw_progress_barf(
percent,
"%s %s/%s",
special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
FORMAT_BYTES(e->written_uncompressed),
FORMAT_BYTES(e->st.st_size));
else
log_info("Exported %u%%.", percent);
e->last_percent = percent;
+8 -11
View File
@@ -134,17 +134,14 @@ static void tar_export_report_progress(TarExport *e) {
sd_notifyf(false, "X_IMPORT_PROGRESS=%u%%", percent);
if (isatty_safe(STDERR_FILENO)) {
_cleanup_free_ char *s = NULL;
if (asprintf(&s, "%s %s/%s",
special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
FORMAT_BYTES(e->written_uncompressed),
FORMAT_BYTES(e->quota_referenced)) < 0)
return;
draw_progress_bar(s, percent);
} else
if (isatty_safe(STDERR_FILENO))
(void) draw_progress_barf(
percent,
"%s %s/%s",
special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
FORMAT_BYTES(e->written_uncompressed),
FORMAT_BYTES(e->quota_referenced));
else
log_info("Exported %u%%.", percent);
e->last_percent = percent;
+8 -11
View File
@@ -151,17 +151,14 @@ static void raw_import_report_progress(RawImport *i) {
sd_notifyf(false, "X_IMPORT_PROGRESS=%u%%", percent);
if (isatty_safe(STDERR_FILENO)) {
_cleanup_free_ char *s = NULL;
if (asprintf(&s, "%s %s/%s",
special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
FORMAT_BYTES(i->written_compressed),
FORMAT_BYTES(i->input_stat.st_size)) < 0)
return;
draw_progress_bar(s, percent);
} else
if (isatty_safe(STDERR_FILENO))
(void) draw_progress_barf(
percent,
"%s %s/%s",
special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
FORMAT_BYTES(i->written_compressed),
FORMAT_BYTES(i->input_stat.st_size));
else
log_info("Imported %u%%.", percent);
i->last_percent = percent;
+8 -11
View File
@@ -152,17 +152,14 @@ static void tar_import_report_progress(TarImport *i) {
sd_notifyf(false, "X_IMPORT_PROGRESS=%u%%", percent);
if (isatty_safe(STDERR_FILENO)) {
_cleanup_free_ char *s = NULL;
if (asprintf(&s, "%s %s/%s",
special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
FORMAT_BYTES(i->written_compressed),
FORMAT_BYTES(i->input_stat.st_size)) < 0)
return;
draw_progress_bar(s, percent);
} else
if (isatty_safe(STDERR_FILENO))
(void) draw_progress_barf(
percent,
"%s %s/%s",
special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
FORMAT_BYTES(i->written_compressed),
FORMAT_BYTES(i->input_stat.st_size));
else
log_info("Imported %u%%.", percent);
i->last_percent = percent;