summaryrefslogtreecommitdiffstats
path: root/osdep/terminal-win.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-win.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-win.c')
-rw-r--r--osdep/terminal-win.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c
index a56d1a409c..cee2ab395a 100644
--- a/osdep/terminal-win.c
+++ b/osdep/terminal-win.c
@@ -28,10 +28,25 @@
#include <stdint.h>
#include <string.h>
#include <windows.h>
+#include <io.h>
#include "input/keycodes.h"
#include "input/input.h"
#include "terminal.h"
+#define hSTDOUT GetStdHandle(STD_OUTPUT_HANDLE)
+#define hSTDERR GetStdHandle(STD_ERROR_HANDLE)
+static short stdoutAttrs = 0;
+static const unsigned char ansi2win32[8] = {
+ 0,
+ FOREGROUND_RED,
+ FOREGROUND_GREEN,
+ FOREGROUND_GREEN | FOREGROUND_RED,
+ FOREGROUND_BLUE,
+ FOREGROUND_BLUE | FOREGROUND_RED,
+ FOREGROUND_BLUE | FOREGROUND_GREEN,
+ FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED,
+};
+
int mp_input_slave_cmd_func(int fd, char *dest, int size)
{
DWORD retval;
@@ -64,11 +79,6 @@ void get_screen_size(void)
}
}
-int load_termcap(char *termtype)
-{
- return 0;
-}
-
static HANDLE in;
static int getch2_status = 0;
@@ -192,3 +202,31 @@ void getch2_disable(void)
return; // already disabled / never enabled
getch2_status = 0;
}
+
+bool terminal_in_background(void)
+{
+ return false;
+}
+
+void terminal_set_foreground_color(FILE *stream, int c)
+{
+ HANDLE *wstream = stream == stderr ? hSTDERR : hSTDOUT;
+ if (c < 0 || c >= 8) { // reset or invalid
+ SetConsoleTextAttribute(wstream, stdoutAttrs);
+ } else {
+ SetConsoleTextAttribute(wstream, ansi2win32[c] | FOREGROUND_INTENSITY);
+ }
+}
+
+int terminal_init(void)
+{
+ CONSOLE_SCREEN_BUFFER_INFO cinfo;
+ DWORD cmode = 0;
+ GetConsoleMode(hSTDOUT, &cmode);
+ cmode |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);
+ SetConsoleMode(hSTDOUT, cmode);
+ SetConsoleMode(hSTDERR, cmode);
+ GetConsoleScreenBufferInfo(hSTDOUT, &cinfo);
+ stdoutAttrs = cinfo.wAttributes;
+ return 0;
+}