diff options
author | wm4 <wm4@nowhere> | 2014-10-23 19:11:31 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-10-23 19:27:49 +0200 |
commit | a037f7b4647c07d9f33bc849fd6f0ae3e3422754 (patch) | |
tree | a486f8b664bd67f6a9ed49cb640a56bc2c6c02ff /osdep | |
parent | c9234d769df83b7280f68f9dc24445029f84041a (diff) | |
download | mpv-a037f7b4647c07d9f33bc849fd6f0ae3e3422754.tar.bz2 mpv-a037f7b4647c07d9f33bc849fd6f0ae3e3422754.tar.xz |
terminal: strictly don't read terminal input if stdout is not a terminal
Doing that doesn't make sense anyway: it's meant for interactive input,
and if the output of the player is not on the terminal, how will you
interact with it?
It was also quite in the way when trying to read verbose output with
e.g. less while the player was running, because the player would grab
half of all input meant for less (simply because stdin is still
connected to the terminal).
Remove the now redundant special-casing of pipe input.
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/terminal-unix.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c index f17524c0f1..8912d8234d 100644 --- a/osdep/terminal-unix.c +++ b/osdep/terminal-unix.c @@ -653,10 +653,11 @@ static bool getch2(struct input_ctx *input_ctx) static volatile int getch2_active = 0; static volatile int getch2_enabled = 0; +static bool read_terminal; static void do_activate_getch2(void) { - if (getch2_active || !isatty(STDOUT_FILENO)) + if (getch2_active || !read_terminal) return; enable_kx(true); @@ -759,7 +760,7 @@ static void quit_request_sighandler(int signum) static void *terminal_thread(void *ptr) { mpthread_set_name("terminal"); - bool stdin_ok = isatty(STDIN_FILENO); // if false, we still wait for SIGTERM + bool stdin_ok = read_terminal; // if false, we still wait for SIGTERM while (1) { struct pollfd fds[2] = { {.events = POLLIN, .fd = death_pipe[0]}, @@ -833,7 +834,7 @@ void terminal_uninit(void) bool terminal_in_background(void) { - return isatty(STDERR_FILENO) && tcgetpgrp(STDERR_FILENO) != getpgrp(); + return read_terminal && tcgetpgrp(STDERR_FILENO) != getpgrp(); } void terminal_get_size(int *w, int *h) @@ -848,10 +849,13 @@ void terminal_get_size(int *w, int *h) int terminal_init(void) { + assert(!getch2_enabled); + getch2_enabled = 1; + if (isatty(STDOUT_FILENO)) load_termcap(); - assert(!getch2_enabled); + read_terminal = isatty(STDIN_FILENO) && isatty(STDOUT_FILENO); // handlers to fix terminal settings setsigaction(SIGCONT, continue_sighandler, 0, true); @@ -861,6 +865,5 @@ int terminal_init(void) do_activate_getch2(); - getch2_enabled = 1; return 0; } |