]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/core/show-status.c
core: Check for TERM=dumb in show_status()
[thirdparty/systemd.git] / src / core / show-status.c
index 81b6b23fd7dd253d6f65a7d85905c5718a067814..57ad4db30b5adc433b0305d5227cb64075108026 100644 (file)
@@ -39,6 +39,7 @@ int parse_show_status(const char *v, ShowStatus *ret) {
 int status_vprintf(const char *status, ShowStatusFlags flags, const char *format, va_list ap) {
         static const char status_indent[] = "         "; /* "[" STATUS "] " */
         static bool prev_ephemeral = false;
+        static int dumb = -1;
 
         _cleanup_free_ char *s = NULL;
         _cleanup_close_ int fd = -EBADF;
@@ -47,6 +48,9 @@ int status_vprintf(const char *status, ShowStatusFlags flags, const char *format
 
         assert(format);
 
+        if (dumb < 0)
+                dumb = getenv_terminal_is_dumb();
+
         /* This is independent of logging, as status messages are
          * optional and go exclusively to the console. */
 
@@ -62,7 +66,7 @@ int status_vprintf(const char *status, ShowStatusFlags flags, const char *format
         if (fd < 0)
                 return fd;
 
-        if (FLAGS_SET(flags, SHOW_STATUS_ELLIPSIZE)) {
+        if (FLAGS_SET(flags, SHOW_STATUS_ELLIPSIZE) && !dumb) {
                 char *e;
                 size_t emax, sl;
                 int c;
@@ -82,7 +86,7 @@ int status_vprintf(const char *status, ShowStatusFlags flags, const char *format
                         free_and_replace(s, e);
         }
 
-        if (prev_ephemeral)
+        if (prev_ephemeral && !dumb)
                 iovec[n++] = IOVEC_MAKE_STRING(ANSI_REVERSE_LINEFEED "\r" ANSI_ERASE_TO_END_OF_LINE);
 
         if (status) {
@@ -95,9 +99,11 @@ int status_vprintf(const char *status, ShowStatusFlags flags, const char *format
         }
 
         iovec[n++] = IOVEC_MAKE_STRING(s);
-        iovec[n++] = IOVEC_MAKE_STRING("\r\n"); /* use CRNL instead of just NL, to be robust towards TTYs in raw mode */
+        /* use CRNL instead of just NL, to be robust towards TTYs in raw mode. If we're writing to a dumb
+         * terminal, use NL as CRNL might be interpreted as a double newline. */
+        iovec[n++] = IOVEC_MAKE_STRING(dumb ? "\n" : "\r\n");
 
-        if (prev_ephemeral && !FLAGS_SET(flags, SHOW_STATUS_EPHEMERAL))
+        if (prev_ephemeral && !FLAGS_SET(flags, SHOW_STATUS_EPHEMERAL) && !dumb)
                 iovec[n++] = IOVEC_MAKE_STRING(ANSI_ERASE_TO_END_OF_LINE);
         prev_ephemeral = FLAGS_SET(flags, SHOW_STATUS_EPHEMERAL);