From: Tomsod M Date: Sun, 20 May 2018 15:58:58 +0000 (+0300) Subject: show-status: add newline to ephemeral messages X-Git-Tag: v240~998 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8255430754d3836b5f4713733341d6e2e8bd8b98;p=thirdparty%2Fsystemd.git show-status: add newline to ephemeral messages Fixes #6712. The newline is later reversed, naturally. --- diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index c0bd0e67a69..38c382c47c5 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -50,6 +50,9 @@ /* Erase characters until the end of the line */ #define ANSI_ERASE_TO_END_OF_LINE "\x1B[K" +/* Move cursor up one line */ +#define ANSI_REVERSE_LINEFEED "\x1BM" + /* Set cursor to top left corner and clear screen */ #define ANSI_HOME_CLEAR "\x1B[H\x1B[2J" diff --git a/src/core/show-status.c b/src/core/show-status.c index 63262cc7169..fd9aeb9416f 100644 --- a/src/core/show-status.c +++ b/src/core/show-status.c @@ -32,7 +32,7 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char static const char status_indent[] = " "; /* "[" STATUS "] " */ _cleanup_free_ char *s = NULL; _cleanup_close_ int fd = -1; - struct iovec iovec[6] = {}; + struct iovec iovec[7] = {}; int n = 0; static bool prev_ephemeral; @@ -76,8 +76,7 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char } if (prev_ephemeral) - iovec[n++] = IOVEC_MAKE_STRING("\r" ANSI_ERASE_TO_END_OF_LINE); - prev_ephemeral = ephemeral; + iovec[n++] = IOVEC_MAKE_STRING(ANSI_REVERSE_LINEFEED "\r" ANSI_ERASE_TO_END_OF_LINE); if (status) { if (!isempty(status)) { @@ -89,8 +88,11 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char } iovec[n++] = IOVEC_MAKE_STRING(s); - if (!ephemeral) - iovec[n++] = IOVEC_MAKE_STRING("\n"); + iovec[n++] = IOVEC_MAKE_STRING("\n"); + + if (prev_ephemeral && !ephemeral) + iovec[n++] = IOVEC_MAKE_STRING(ANSI_ERASE_TO_END_OF_LINE); + prev_ephemeral = ephemeral; if (writev(fd, iovec, n) < 0) return -errno;