const char *func,
const char *buffer) {
+ static int dumb = -1;
+
char location[256],
header_time[FORMAT_TIMESTAMP_MAX],
prefix[1 + DECIMAL_STR_MAX(int) + 2],
if (console_fd < 0)
return 0;
+ if (dumb < 0)
+ dumb = getenv_terminal_is_dumb();
+
if (LOG_PRI(level) > log_target_max_level[LOG_TARGET_CONSOLE])
return 0;
/* When writing to a TTY we output an extra '\r' (i.e. CR) first, to generate CRNL rather than just
* NL. This is a robustness thing in case the TTY is currently in raw mode (specifically: has the
* ONLCR flag off). We want that subsequent output definitely starts at the beginning of the line
- * again, after all. If the TTY is not in raw mode the extra CR should not hurt. */
- iovec[n++] = IOVEC_MAKE_STRING(check_console_fd_is_tty() ? "\r\n" : "\n");
+ * again, after all. If the TTY is not in raw mode the extra CR should not hurt. If we're writing to
+ * a dumb terminal, only write NL as CRNL might be interpreted as a double newline. */
+ iovec[n++] = IOVEC_MAKE_STRING(check_console_fd_is_tty() && !dumb ? "\r\n" : "\n");
if (writev(console_fd, iovec, n) < 0) {
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;
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. */
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;
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) {
}
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);