From 13ed292ab054ba09f9257d9c510cd7ce39f4b7d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Thu, 4 Jan 2024 21:01:01 +0100 Subject: [PATCH] terminal: don't print escape sequence if not tty --- common/msg.c | 4 +++- osdep/terminal-unix.c | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/common/msg.c b/common/msg.c index f435d6e206..20f1ce0abb 100644 --- a/common/msg.c +++ b/common/msg.c @@ -257,7 +257,9 @@ void mp_msg_flush_status_line(struct mp_log *log, bool clear) goto done; if (!clear) { - fprintf(stderr, TERM_ESC_RESTORE_CURSOR "\n"); + if (log->root->isatty[STDERR_FILENO]) + fprintf(stderr, TERM_ESC_RESTORE_CURSOR); + fprintf(stderr, "\n"); log->root->blank_lines = 0; log->root->status_lines = 0; goto done; diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c index 72d0d14899..be0463b871 100644 --- a/osdep/terminal-unix.c +++ b/osdep/terminal-unix.c @@ -424,8 +424,10 @@ static MP_THREAD_VOID terminal_thread(void *ptr) (void)read(stop_cont_pipe[0], &c, 1); if (c == PIPE_STOP) { do_deactivate_getch2(); - (void)write(STDERR_FILENO, TERM_ESC_RESTORE_CURSOR, - sizeof(TERM_ESC_RESTORE_CURSOR) - 1); + if (isatty(STDERR_FILENO)) { + (void)write(STDERR_FILENO, TERM_ESC_RESTORE_CURSOR, + sizeof(TERM_ESC_RESTORE_CURSOR) - 1); + } // trying to reset SIGTSTP handler to default and raise it will // result in a race and there's no other way to invoke the // default handler. so just invoke SIGSTOP since it's