diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2024-03-18 10:52:38 +0100 |
---|---|---|
committer | Kacper Michajłow <kasper93@gmail.com> | 2024-03-19 19:58:09 +0100 |
commit | bfd016d1013ad6cac9a190ec109e814744055d8c (patch) | |
tree | 2b114e9ee3793c8acb959c46b0e224bf6629e6fd | |
parent | fc55f355fc8225328cf0472e3deb4021eba96303 (diff) | |
download | mpv-bfd016d1013ad6cac9a190ec109e814744055d8c.tar.bz2 mpv-bfd016d1013ad6cac9a190ec109e814744055d8c.tar.xz |
win32: avoid multi byte string to wide conversion if not needed
-rw-r--r-- | osdep/terminal-win.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c index 90f89935a0..dc8e10407d 100644 --- a/osdep/terminal-win.c +++ b/osdep/terminal-win.c @@ -63,6 +63,7 @@ static void attempt_native_out_vt(HANDLE hOut, DWORD basemode) static bool is_console[STDERR_FILENO + 1]; static bool is_vt[STDERR_FILENO + 1]; +static bool utf8_output; static short stdoutAttrs = 0; // copied from the screen buffer on init static const unsigned char ansi2win32[8] = { 0, @@ -255,14 +256,24 @@ int mp_console_fputs(HANDLE wstream, bstr str) free_buf = !FlsSetValue(tmp_buffers_key, buffers); } - int wlen = bstr_to_wchar(buffers, str, &buffers->write_console_wbuf); - wchar_t *pos = buffers->write_console_wbuf; + bool vt = is_native_out_vt(wstream); + int wlen = 0; + wchar_t *pos = NULL; + if (!utf8_output || !vt) { + wlen = bstr_to_wchar(buffers, str, &buffers->write_console_wbuf); + pos = buffers->write_console_wbuf; + } - while (*pos) { - if (is_native_out_vt(wstream)) { + if (vt) { + if (utf8_output) { + WriteConsoleA(wstream, str.start, str.len, NULL, NULL); + } else { WriteConsoleW(wstream, pos, wlen, NULL, NULL); - break; } + goto done; + } + + while (*pos) { wchar_t *next = wcschr(pos, '\033'); if (!next) { WriteConsoleW(wstream, pos, wcslen(pos), NULL, NULL); @@ -399,6 +410,7 @@ int mp_console_fputs(HANDLE wstream, bstr str) pos = next; } +done:; int ret = buffers->write_console_buf.len; if (free_buf) @@ -496,4 +508,5 @@ void terminal_init(void) stdoutAttrs = cinfo.wAttributes; tmp_buffers_key = FlsAlloc((PFLS_CALLBACK_FUNCTION)talloc_free); + utf8_output = SetConsoleOutputCP(CP_UTF8); } |