diff options
author | wm4 <wm4@nowhere> | 2013-12-18 15:03:08 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-12-20 21:07:57 +0100 |
commit | 4d4b82217126de3160299b3aefba1f6941623d30 (patch) | |
tree | e72cfa8070e7abfd6b5ef62176b19dd2e84e9673 /osdep/terminal-unix.c | |
parent | a4fe95b0d8d339ba5afbdb5346ad8fd367a4a1c1 (diff) | |
download | mpv-4d4b82217126de3160299b3aefba1f6941623d30.tar.bz2 mpv-4d4b82217126de3160299b3aefba1f6941623d30.tar.xz |
terminal: abstract terminal color handling
Instead of making msg.c an ifdef hell for unix vs. windows code, move
the code to separate functions defined in terminal-unix.c/terminal-
win.c.
Drop the code that selects random colors for --msgmodule prefixes.
Diffstat (limited to 'osdep/terminal-unix.c')
-rw-r--r-- | osdep/terminal-unix.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c index 050b97b9d1..f61cb5e367 100644 --- a/osdep/terminal-unix.c +++ b/osdep/terminal-unix.c @@ -227,7 +227,7 @@ static void termcap_add_extra_f_keys(void) { #endif -int load_termcap(char *termtype){ +static int load_termcap(char *termtype){ #if HAVE_TERMINFO || HAVE_TERMCAP #if HAVE_TERMINFO @@ -578,3 +578,23 @@ void getch2_disable(void){ getch2_enabled = 0; } + +bool terminal_in_background(void) +{ + return isatty(2) && tcgetpgrp(2) != getpgrp(); +} + +void terminal_set_foreground_color(FILE *stream, int c) +{ + if (c == -1) { + fprintf(stream, "\033[0m"); + } else { + fprintf(stream, "\033[%d;3%dm", c >> 3, c & 7); + } +} + +int terminal_init(void) +{ + load_termcap(NULL); + return 0; +} |