summaryrefslogtreecommitdiffstats
path: root/src/core/show-status.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-25 02:54:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-25 02:54:52 +0000
commit51fac37bb20c9440a9a4e0a20846c139364d6d13 (patch)
tree77c11a0dffc2c15542689f3a51d12d5076c477e8 /src/core/show-status.c
parentAdding upstream version 255.4. (diff)
downloadsystemd-51fac37bb20c9440a9a4e0a20846c139364d6d13.tar.xz
systemd-51fac37bb20c9440a9a4e0a20846c139364d6d13.zip
Adding upstream version 255.5.upstream/255.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/core/show-status.c')
-rw-r--r--src/core/show-status.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/core/show-status.c b/src/core/show-status.c
index 606237e..5b003ba 100644
--- a/src/core/show-status.c
+++ b/src/core/show-status.c
@@ -38,6 +38,8 @@ 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 int dumb = -1;
+
_cleanup_free_ char *s = NULL;
_cleanup_close_ int fd = -EBADF;
struct iovec iovec[7] = {};
@@ -46,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. */
@@ -61,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;
@@ -81,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) {
@@ -94,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);