summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-10-29 21:32:28 +0100
committerLennart Poettering <lennart@poettering.net>2024-10-29 21:37:26 +0100
commit91d640435d0fd79fe74f6c558d69ffdcbdf86234 (patch)
treeff8c75d0c5c5c5b6d12e44d830a8b47e8f4d2de9 /src/shared
parentpretty-print: rename draw_progress_bar_impl()→draw_progress_bar_unbuffered() (diff)
downloadsystemd-91d640435d0fd79fe74f6c558d69ffdcbdf86234.tar.xz
systemd-91d640435d0fd79fe74f6c558d69ffdcbdf86234.zip
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.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/pretty-print.c16
-rw-r--r--src/shared/pretty-print.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/src/shared/pretty-print.c b/src/shared/pretty-print.c
index 18b2da15d4..df1c20fa24 100644
--- a/src/shared/pretty-print.c
+++ b/src/shared/pretty-print.c
@@ -548,6 +548,22 @@ void draw_progress_bar(const char *prefix, double percentage) {
draw_progress_bar_unbuffered(prefix, percentage);
}
+int draw_progress_barf(double percentage, const char *prefixf, ...) {
+ _cleanup_free_ char *s = NULL;
+ va_list ap;
+ int r;
+
+ va_start(ap, prefixf);
+ r = vasprintf(&s, prefixf, ap);
+ va_end(ap);
+
+ if (r < 0)
+ return -ENOMEM;
+
+ draw_progress_bar(s, percentage);
+ return 0;
+}
+
void clear_progress_bar(const char *prefix) {
WITH_BUFFERED_STDERR;
clear_progress_bar_unbuffered(prefix);
diff --git a/src/shared/pretty-print.h b/src/shared/pretty-print.h
index 0c073b6092..8ea1e964a3 100644
--- a/src/shared/pretty-print.h
+++ b/src/shared/pretty-print.h
@@ -54,6 +54,7 @@ int terminal_tint_color(double hue, char **ret);
bool shall_tint_background(void);
void draw_progress_bar(const char *prefix, double percentage);
+int draw_progress_barf(double percentage, const char *prefixf, ...) _printf_(2, 3);
void clear_progress_bar(const char *prefix);
void draw_progress_bar_unbuffered(const char *prefix, double percentage);
void clear_progress_bar_unbuffered(const char *prefix);