Skip to content
Myr

Merge pull request #1135 from segevfiner/winconsole-detection-bug

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Detect a Windows console handle correctly using GetConsoleMode

authored by David Lord · committed by GitHub · parents b919ce7, 3f49ec2 · Browse files · 2 files+22 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+22 added−7 removed

  • other:+22 added−7 removed

2 files+22 added−7 removed

modified:click/_winconsole.py+16 added-2 removed
22 unmodified lines
23 PyObject_GetBuffer = pythonapi.PyObject_GetBuffer24 PyBuffer_Release = pythonapi.PyBuffer_Release25except ImportError:26 pythonapi = None27from ctypes.wintypes import LPWSTR, LPCWSTR, HANDLE27from ctypes.wintypes import DWORD, LPWSTR, LPCWSTR, HANDLE282930c_ssize_p = POINTER(c_ssize_t)3132kernel32 = windll.kernel3233GetStdHandle = kernel32.GetStdHandle34ReadConsoleW = kernel32.ReadConsoleW35WriteConsoleW = kernel32.WriteConsoleW36GetConsoleMode = kernel32.GetConsoleMode37GetLastError = kernel32.GetLastError38GetCommandLineW = WINFUNCTYPE(LPWSTR)(39 ('GetCommandLineW', windll.kernel32))40CommandLineToArgvW = WINFUNCTYPE(
246 unmodified lines
287 2: _get_text_stderr,288}289290291def _is_console(f):292 if not hasattr(f, 'fileno'):293 return False294295 try:296 fileno = f.fileno()297 except OSError:298 return False299300 handle = msvcrt.get_osfhandle(fileno)301 return bool(GetConsoleMode(handle, byref(DWORD())))302303304def _get_windows_console_stream(f, encoding, errors):305 if get_buffer is not None and \306 encoding in ('utf-16-le', None) \307 and errors in ('strict', None) and \294 hasattr(f, 'isatty') and f.isatty():308 _is_console(f):309 func = _stream_factories.get(f.fileno())310 if func is not None:311 if not PY2:312 f = getattr(f, 'buffer', None)
9 unmodified lines
modified:CHANGES.rst+6 added-5 removed
4 unmodified lines
56Unreleased78- Fix PyPI package name, "click" is lowercase again.9- Add ``no_args_is_help`` option to ``click.Command``, defaults to10 False :pr:`1167`9- Fix link in ``unicode_literals`` error message. :pr:`1151`10- Add support for colored output on UNIX Jupyter notebooks.11 :issue:`1185`12- Remove unused compat shim for ``bytes``. :pr:`1195`13- Expand testing around termui, especially getchar on Windows.14 :issue:`1116`15- Fix output on Windows Python 2.7 built with MSVC 14. :pr:`1342`18- Always return one of the passed choices for ``click.Choice``19 :issue:`1277`, :pr:`1318`16- Fix ``OSError`` when running in MSYS2. :issue:`1338`17- Fix ``OSError`` when redirecting to ``NUL`` stream on Windows.18 :issue:`1065`19- Fix error in new AppEngine environments. :issue:`1462`20- Always return one of the passed choices for ``click.Choice``21 :issue:`1277`, :pr:`1318`22- Add ``no_args_is_help`` option to ``click.Command``, defaults to23 False :pr:`1167`24- Add ``show_defaults`` parameter to ``Context`` to enable showing25 defaults globally. :issue:`1018`26272628Version 7.029-----------3031Released 2018-09-25
538 unmodified lines