]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
show-status: add newline to ephemeral messages
authorTomsod M <tomsod-m@ya.ru>
Sun, 20 May 2018 15:58:58 +0000 (18:58 +0300)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 6 Jul 2018 14:35:22 +0000 (16:35 +0200)
Fixes #6712.  The newline is later reversed, naturally.

src/basic/terminal-util.h
src/core/show-status.c

index c0bd0e67a69192e4caacaba47a5858b09ac08244..38c382c47c5e60c2b527d2f6d283e4b98b06c06e 100644 (file)
@@ -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"
 
index 63262cc7169af1c7c878c03d648cf1dba7204a19..fd9aeb9416f82a3dbe681fd40472da561fd99bbf 100644 (file)
@@ -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;