Skip to content
Myr

Also use the console emulation on Python 3. Refs #442

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

authored by Armin Ronacher · committed by Armin Ronacher · parent dde42ed · Browse files · 3 files+29 added−15 removed
This commit

State

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

Diff stats

3 files+29 added−15 removed

  • other:+29 added−15 removed

3 files+29 added−15 removed

modified:click/_compat.py+13 added-3 removed
172 unmodified lines
173 return '<%s name=%r>' % (174 self.__class__.__name__,175 self.name,176 )177178 from ._winconsole import _get_windows_console_stream177 else:178 set_binary_mode = lambda x: x181 _get_windows_console_stream = lambda *x: None179180 def isidentifier(x):181 return _identifier_re.search(x) is not None182
190 unmodified lines
373 'stream for sys.stderr.')374 return writer375376 def get_text_stdin(encoding=None, errors=None):377 rv = _get_windows_console_stream(sys.stdin, encoding, errors)378 if rv is not None:379 return rv380 return _force_correct_text_reader(sys.stdin, encoding, errors)381382 def get_text_stdout(encoding=None, errors=None):383 rv = _get_windows_console_stream(sys.stdout, encoding, errors)384 if rv is not None:385 return rv386 return _force_correct_text_writer(sys.stdout, encoding, errors)387388 def get_text_stderr(encoding=None, errors=None):389 rv = _get_windows_console_stream(sys.stderr, encoding, errors)390 if rv is not None:391 return rv392 return _force_correct_text_writer(sys.stderr, encoding, errors)393394 def filename_to_ui(value):395 if isinstance(value, bytes):
134 unmodified lines
530if WIN:531 # Windows has a smaller terminal532 DEFAULT_COLUMNS = 79533534 from ._winconsole import _get_windows_console_stream535536 def _get_argv_encoding():537 import locale538 return locale.getpreferredencoding()539
51 unmodified lines
591else:592 def _get_argv_encoding():593 return getattr(sys.stdin, 'encoding', None) or get_filesystem_encoding()594595 _get_windows_console_stream = lambda *x: None596597598def term_len(x):599 return len(strip_ansi(x))600601
45 unmodified lines
modified:click/_winconsole.py+12 added-8 removed
9 unmodified lines
1011import io12import sys13import ctypes14from click._compat import _NonClosingTextIOWrapper, text_type14from click._compat import _NonClosingTextIOWrapper, text_type, PY215from ctypes import byref, POINTER, pythonapi, c_int, c_char, c_char_p, \16 c_void_p, py_object, c_ssize_t, c_ulong, windll, WINFUNCTYPE17from ctypes.wintypes import LPWSTR, LPCWSTR18
171 unmodified lines
190 self.encoding,191 )192193194def _get_text_stdin():194def _get_text_stdin(buffer_stream):195 text_stream = _NonClosingTextIOWrapper(196 io.BufferedReader(_WindowsConsoleReader(STDIN_HANDLE)),197 'utf-16-le', 'strict', line_buffering=True)198 return ConsoleStream(text_stream, sys.stdin)198 return ConsoleStream(text_stream, buffer_stream)199200201def _get_text_stdout():201def _get_text_stdout(buffer_stream):202 text_stream = _NonClosingTextIOWrapper(203 _WindowsConsoleWriter(STDOUT_HANDLE),204 'utf-16-le', 'strict', line_buffering=True)205 return ConsoleStream(text_stream, sys.stdout)205 return ConsoleStream(text_stream, buffer_stream)206207208def _get_text_stderr():208def _get_text_stderr(buffer_stream):209 text_stream = _NonClosingTextIOWrapper(210 _WindowsConsoleWriter(STDERR_HANDLE),211 'utf-16-le', 'strict', line_buffering=True)212 return ConsoleStream(text_stream, sys.stderr)212 return ConsoleStream(text_stream, buffer_stream)213214215def _get_windows_argv():216 argc = c_int(0)
28 unmodified lines
245 and errors in ('strict', None) and \246 hasattr(f, 'isatty') and f.isatty():247 func = _stream_factories.get(f.fileno())248 if func is not None:249 if not PY2:250 f = getattr(f, 'buffer')251 if f is None:252 return None249 return func()253 return func(f)
modified:CHANGES+4 added-4 removed
27 unmodified lines
28 unicode by default in the `Path` type which means that this can29 introduce small bugs for code not aware of this.30- Added a `type` parameter to `Path` to force a specific string type31 on the value.32- For users running Python 2 the echo() and prompt() functions now work33 with unicode in the Python windows console. For Python 3 the work34 is delegated to the Python interpreter as general support for Unicode35 in the console is implemented to some degree.32- For users running Python on Windows the `echo`) and `prompt` functions33 now work with full unicode functionality in the Python windows console34 by emulating an output stream. This also applies to getting the35 virtual output and input streams via `click.get_text_stream(...)`.36- Unittests now always force a certain virtual terminal width.3738Version 5.139-----------
252 unmodified lines