summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorMartin Herkt <lachs0r@srsfckn.biz>2011-10-22 16:24:16 +0200
committerUoti Urpala <uau@mplayer2.org>2012-03-09 20:48:54 +0200
commitf891939b4db79bce39c5f257771557904da4d535 (patch)
tree1bf77e2d384b7f736f451b9a0cb7922ab219cebf /osdep
parenta1244111a790bbc4bf91b078ebcad3f415da79da (diff)
downloadmpv-f891939b4db79bce39c5f257771557904da4d535.tar.bz2
mpv-f891939b4db79bce39c5f257771557904da4d535.tar.xz
windows: terminal: unicode, --msgcolor, size change
Make mp_msg() support unicode output, --msgcolor and variable screen sizes. Patch reintegrated by wm4.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/getch2-win.c6
-rw-r--r--osdep/io.c58
-rw-r--r--osdep/io.h2
3 files changed, 66 insertions, 0 deletions
diff --git a/osdep/getch2-win.c b/osdep/getch2-win.c
index 3e6eeff086..326cf1a7d0 100644
--- a/osdep/getch2-win.c
+++ b/osdep/getch2-win.c
@@ -55,6 +55,12 @@ int screen_height=24;
char * erase_to_end_of_line = NULL;
void get_screen_size(void){
+ CONSOLE_SCREEN_BUFFER_INFO cinfo;
+ if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cinfo))
+ {
+ screen_width = cinfo.dwMaximumWindowSize.X;
+ screen_height = cinfo.dwMaximumWindowSize.Y;
+ }
}
static HANDLE in;
diff --git a/osdep/io.c b/osdep/io.c
index 88433184f4..e3e750e30b 100644
--- a/osdep/io.c
+++ b/osdep/io.c
@@ -92,6 +92,64 @@ int mp_stat(const char *path, struct stat *buf)
return res;
}
+int mp_fprintf(FILE *stream, const char *format, ...)
+{
+ va_list args;
+ int done = 0;
+
+ va_start(args, format);
+
+ if (stream == stdout || stream == stderr)
+ {
+ HANDLE *wstream = GetStdHandle(stream == stdout ?
+ STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
+ if (wstream != INVALID_HANDLE_VALUE)
+ {
+ // figure out whether we're writing to a console
+ unsigned int filetype = GetFileType(wstream);
+ if (!((filetype == FILE_TYPE_UNKNOWN) &&
+ (GetLastError() != ERROR_SUCCESS)))
+ {
+ int isConsole;
+ filetype &= ~(FILE_TYPE_REMOTE);
+ if (filetype == FILE_TYPE_CHAR)
+ {
+ DWORD ConsoleMode;
+ int ret = GetConsoleMode(wstream, &ConsoleMode);
+ if (!ret && (GetLastError() == ERROR_INVALID_HANDLE))
+ isConsole = 0;
+ else
+ isConsole = 1;
+ }
+ else
+ isConsole = 0;
+
+ if (isConsole)
+ {
+ int nchars = vsnprintf(NULL, 0, format, args) + 1;
+ char *buf = talloc_array(NULL, char, nchars);
+ if (buf)
+ {
+ vsnprintf(buf, nchars, format, args);
+ wchar_t *out = mp_from_utf8(NULL, buf);
+ size_t nchars = wcslen(out);
+ talloc_free(buf);
+ done = WriteConsoleW(wstream, out, nchars, NULL, NULL);
+ talloc_free(out);
+ }
+ }
+ else
+ done = vfprintf(stream, format, args);
+ }
+ }
+ }
+ else
+ done = vfprintf(stream, format, args);
+
+ va_end(args);
+
+ return done;
+}
int mp_open(const char *filename, int oflag, ...)
{
diff --git a/osdep/io.h b/osdep/io.h
index 514030afca..462a84917b 100644
--- a/osdep/io.h
+++ b/osdep/io.h
@@ -46,6 +46,7 @@ char *mp_to_utf8(void *talloc_ctx, const wchar_t *s);
void mp_get_converted_argv(int *argc, char ***argv);
int mp_stat(const char *path, struct stat *buf);
+int mp_fprintf(FILE *stream, const char *format, ...);
int mp_open(const char *filename, int oflag, ...);
int mp_creat(const char *filename, int mode);
FILE *mp_fopen(const char *filename, const char *mode);
@@ -57,6 +58,7 @@ int mp_mkdir(const char *path, int mode);
// NOTE: Stat is not overridden with mp_stat, because MinGW-w64 defines it as
// macro.
+#define fprintf(...) mp_fprintf(__VA_ARGS__)
#define open(...) mp_open(__VA_ARGS__)
#define creat(...) mp_creat(__VA_ARGS__)
#define fopen(...) mp_fopen(__VA_ARGS__)