diff options
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/terminal-util.c | 4 | ||||
-rw-r--r-- | src/basic/terminal-util.h | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 8ded46f493..4172db12a5 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -1923,12 +1923,12 @@ int get_default_background_color(double *ret_red, double *ret_green, double *ret if (tcsetattr(STDIN_FILENO, TCSADRAIN, &new_termios) < 0) return -errno; - r = loop_write(STDOUT_FILENO, "\x1B]11;?\x07", SIZE_MAX); + r = loop_write(STDOUT_FILENO, "\x1B]11;?" ANSI_ST, SIZE_MAX); if (r < 0) goto finish; usec_t end = usec_add(now(CLOCK_MONOTONIC), 333 * USEC_PER_MSEC); - char buf[STRLEN("\x1B]11;rgb:0/0/0\x07")]; /* shortest possible reply */ + char buf[STRLEN("\x1B]11;rgb:0/0/0" ANSI_ST)]; /* shortest possible reply */ size_t buf_full = 0; BackgroundColorContext context = {}; diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index b446e547d6..3d02e92d0b 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -27,6 +27,13 @@ #define ANSI_WINDOW_TITLE_PUSH "\x1b[22;2t" #define ANSI_WINDOW_TITLE_POP "\x1b[23;2t" +/* ANSI "string terminator" character ("ST"). Terminal emulators typically allow three different ones: 0x07, + * 0x9c, and 0x1B 0x5C. We'll avoid 0x07 (BEL, aka ^G) since it might trigger unexpected TTY signal + * handling. And we'll avoid 0x9c since that's also valid regular codepoint in UTF-8 and elsewhere, and + * creates ambiguities. Because of that some terminal emulators explicitly choose not to support it. Hence we + * use 0x1B 0x5c */ +#define ANSI_ST "\e\\" + bool isatty_safe(int fd); int terminal_reset_defensive(int fd, bool switch_to_text); |