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:
+8
-11
@@ -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
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user