[Python-checkins] cpython (merge 3.6 -> default): Issue #28333: Enables Unicode for ps1/ps2 and input() prompts. (Patch by Eryk

steve.dower python-checkins at python.org
Sat Oct 8 15:18:59 EDT 2016


https://hg.python.org/cpython/rev/cb62e921bd06
changeset: 104387:cb62e921bd06
parent: 104385:e3f044acb65a
parent: 104386:faf5493e6f61
user: Steve Dower <steve.dower at microsoft.com>
date: Sat Oct 08 12:18:28 2016 -0700
summary:
 Issue #28333: Enables Unicode for ps1/ps2 and input() prompts. (Patch by Eryk Sun)
files:
 Misc/NEWS | 2 ++
 Parser/myreadline.c | 28 ++++++++++++++++++++++++----
 2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -222,6 +222,8 @@
 Windows
 -------
 
+- Issue #28333: Enables Unicode for ps1/ps2 and input() prompts
+
 - Issue #28251: Improvements to help manuals on Windows.
 
 - Issue #28110: launcher.msi has different product codes between 32-bit and
diff --git a/Parser/myreadline.c b/Parser/myreadline.c
--- a/Parser/myreadline.c
+++ b/Parser/myreadline.c
@@ -203,17 +203,37 @@
 
 #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);
 }
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /