core: Check for TERM=dumb in show_status()

We shouldn't try to use any ANSI escape sequences if TERM=dumb.
Also, the "\r\n" we output can get interpreted as a double newline
(for example by Github Actions), so let's output just "\n" when
TERM=dumb to clean up the CI logs.
This commit is contained in:
Daan De Meyer
2024-04-22 13:27:27 +02:00
parent c3411932b1
commit 1b889631ed
4 changed files with 20 additions and 7 deletions
+8 -2
View File
@@ -434,6 +434,8 @@ static int write_to_console(
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],
@@ -445,6 +447,9 @@ static int write_to_console(
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;
@@ -491,8 +496,9 @@ static int write_to_console(
/* 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) {
+1 -1
View File
@@ -1296,7 +1296,7 @@ static bool on_dev_null(void) {
return cached_on_dev_null;
}
static bool getenv_terminal_is_dumb(void) {
bool getenv_terminal_is_dumb(void) {
const char *e;
e = getenv("TERM");
+1
View File
@@ -172,6 +172,7 @@ void columns_lines_cache_reset(int _unused_ signum);
void reset_terminal_feature_caches(void);
bool on_tty(void);
bool getenv_terminal_is_dumb(void);
bool terminal_is_dumb(void);
ColorMode get_color_mode(void);
bool underline_enabled(void);