diff options
author | Steve Dower <steve.dower@microsoft.com> | 2016-10-08 19:18:16 (GMT) |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2016-10-08 19:18:16 (GMT) |
commit | 3cd187b9f51f37e351d5ea4c8448b4769f8a3d9f (patch) | |
tree | fea07dc505603f4f26135241e21343fc84c8d4e5 /Parser/myreadline.c | |
parent | c3215f530f62ab7e112e0b36b968bf7aa2b831ca (diff) | |
download | cpython-3cd187b9f51f37e351d5ea4c8448b4769f8a3d9f.zip cpython-3cd187b9f51f37e351d5ea4c8448b4769f8a3d9f.tar.gz cpython-3cd187b9f51f37e351d5ea4c8448b4769f8a3d9f.tar.bz2 |
Issue #28333: Enables Unicode for ps1/ps2 and input() prompts. (Patch by Eryk Sun)
Diffstat (limited to 'Parser/myreadline.c')
-rw-r--r-- | Parser/myreadline.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/Parser/myreadline.c b/Parser/myreadline.c index a8f23b7..4f7a9fc 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -203,17 +203,37 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) #ifdef MS_WINDOWS if (!Py_LegacyWindowsStdioFlag && sys_stdin == stdin) { - HANDLE hStdIn; + HANDLE hStdIn, hStdErr; _Py_BEGIN_SUPPRESS_IPH hStdIn = (HANDLE)_get_osfhandle(fileno(sys_stdin)); + hStdErr = (HANDLE)_get_osfhandle(fileno(stderr)); _Py_END_SUPPRESS_IPH if (_get_console_type(hStdIn) == 'r') { fflush(sys_stdout); - if (prompt) - fprintf(stderr, "%s", prompt); - fflush(stderr); + if (prompt) { + if (_get_console_type(hStdErr) == 'w') { + wchar_t *wbuf; + int wlen; + wlen = MultiByteToWideChar(CP_UTF8, 0, prompt, -1, + NULL, 0); + if (wlen++ && + (wbuf = PyMem_RawMalloc(wlen * sizeof(wchar_t)))) { + wlen = MultiByteToWideChar(CP_UTF8, 0, prompt, -1, + wbuf, wlen); + if (wlen) { + DWORD n; + fflush(stderr); + WriteConsoleW(hStdErr, wbuf, wlen, &n, NULL); + } + PyMem_RawFree(wbuf); + } + } else { + fprintf(stderr, "%s", prompt); + fflush(stderr); + } + } clearerr(sys_stdin); return _PyOS_WindowsConsoleReadline(hStdIn); } |