From aa8823c2d22f9b703ba309ba23a32ed6b326fc1c Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 7 Jan 2015 19:45:44 +0100 Subject: [PATCH] terminal: always print to stderr with --no-input-terminal The function terminal_in_background() reports whether the player was backgrounded. In this case, we don't want to annoy the user by still printing the status to stderr. If no terminal interaction is assumed, this mechanism is disabled, and stderr is always used. The read_terminal variable signals this case. Oddly, just redirecting stderr will disable output to stderr, because the background check with tcgetpgrp() is done on stderr, but read_terminal is still true (because that one depends on stdin and stdout). Explicitly disable this mechanism if --no-input-terminal is used by setting read_terminal to true only if terminal input is actually initialized. --- osdep/terminal-unix.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c index bc0dc8336b..d0f40f3a4c 100644 --- a/osdep/terminal-unix.c +++ b/osdep/terminal-unix.c @@ -416,6 +416,11 @@ void terminal_setup_getch(struct input_ctx *ictx) if (mp_make_wakeup_pipe(death_pipe) < 0) return; + // Disable reading from the terminal even if stdout is not a tty, to make + // mpv ... | less + // do the right thing. + read_terminal = isatty(STDIN_FILENO) && isatty(STDOUT_FILENO); + input_ctx = ictx; if (pthread_create(&input_thread, NULL, terminal_thread, NULL)) { @@ -455,6 +460,7 @@ void terminal_uninit(void) } getch2_enabled = 0; + read_terminal = false; } bool terminal_in_background(void) @@ -477,11 +483,6 @@ int terminal_init(void) assert(!getch2_enabled); getch2_enabled = 1; - // Disable reading from the terminal even if stdout is not a tty, to make - // mpv ... | less - // do the right thing. - read_terminal = isatty(STDIN_FILENO) && isatty(STDOUT_FILENO); - // handlers to fix terminal settings setsigaction(SIGCONT, continue_sighandler, 0, true); setsigaction(SIGTSTP, stop_sighandler, SA_RESETHAND, false);