diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2013-02-27 22:52:43 +0100 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2013-02-28 02:23:27 +0100 |
commit | 984a2be450abac81474889b8bea4b3fbeddb26c5 (patch) | |
tree | c6476cd51f3335afb6275c3d8bfd503127c0db9f /src/shared | |
parent | 297d0749dd82ea2442203d53c23ee401bdf46fca (diff) |
util, core: add support for ephemeral status lines
Ephemeral status lines do not end with a newline and they expect to be
overwritten by the next printed status line.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/util.c | 16 | ||||
-rw-r--r-- | src/shared/util.h | 5 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index f5adedc531..cc415894a5 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -2859,12 +2859,13 @@ cpu_set_t* cpu_set_malloc(unsigned *ncpus) { } } -int status_vprintf(const char *status, bool ellipse, const char *format, va_list ap) { +int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) { static const char status_indent[] = " "; /* "[" STATUS "] " */ _cleanup_free_ char *s = NULL; _cleanup_close_ int fd = -1; - struct iovec iovec[5]; + struct iovec iovec[6]; int n = 0; + static bool prev_ephemeral; assert(format); @@ -2902,6 +2903,10 @@ int status_vprintf(const char *status, bool ellipse, const char *format, va_list zero(iovec); + if (prev_ephemeral) + IOVEC_SET_STRING(iovec[n++], "\r" ANSI_ERASE_TO_END_OF_LINE); + prev_ephemeral = ephemeral; + if (status) { if (!isempty(status)) { IOVEC_SET_STRING(iovec[n++], "["); @@ -2912,7 +2917,8 @@ int status_vprintf(const char *status, bool ellipse, const char *format, va_list } IOVEC_SET_STRING(iovec[n++], s); - IOVEC_SET_STRING(iovec[n++], "\n"); + if (!ephemeral) + IOVEC_SET_STRING(iovec[n++], "\n"); if (writev(fd, iovec, n) < 0) return -errno; @@ -2920,14 +2926,14 @@ int status_vprintf(const char *status, bool ellipse, const char *format, va_list return 0; } -int status_printf(const char *status, bool ellipse, const char *format, ...) { +int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) { va_list ap; int r; assert(format); va_start(ap, format); - r = status_vprintf(status, ellipse, format, ap); + r = status_vprintf(status, ellipse, ephemeral, format, ap); va_end(ap); return r; diff --git a/src/shared/util.h b/src/shared/util.h index 19cc36af84..f8957bca42 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -59,6 +59,7 @@ union dirent_storage { #define ANSI_HIGHLIGHT_GREEN_ON "\x1B[1;32m" #define ANSI_HIGHLIGHT_YELLOW_ON "\x1B[1;33m" #define ANSI_HIGHLIGHT_OFF "\x1B[0m" +#define ANSI_ERASE_TO_END_OF_LINE "\x1B[K" size_t page_size(void); #define PAGE_ALIGN(l) ALIGN_TO((l), page_size()) @@ -354,8 +355,8 @@ int pipe_eof(int fd); cpu_set_t* cpu_set_malloc(unsigned *ncpus); -int status_vprintf(const char *status, bool ellipse, const char *format, va_list ap); -int status_printf(const char *status, bool ellipse, const char *format, ...); +int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap); +int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...); int status_welcome(void); int fd_columns(int fd); |