summaryrefslogtreecommitdiffstats
path: root/osdep/terminal-unix.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-18 15:03:08 +0100
committerwm4 <wm4@nowhere>2013-12-20 21:07:57 +0100
commit4d4b82217126de3160299b3aefba1f6941623d30 (patch)
treee72cfa8070e7abfd6b5ef62176b19dd2e84e9673 /osdep/terminal-unix.c
parenta4fe95b0d8d339ba5afbdb5346ad8fd367a4a1c1 (diff)
downloadmpv-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.c22
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;
+}