Skip to content
Myr

Improved windows terminal support.

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 d5b2191 · Browse files · 3 files+21 added−2 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+21 added−2 removed

  • other:+21 added−2 removed

3 files+21 added−2 removed

modified:click/_compat.py+11 added
5 unmodified lines
6from weakref import WeakKeyDictionary789PY2 = sys.version_info[0] == 210DEFAULT_COLUMNS = 80111213_ansi_re = re.compile('\033\[((?:\d|;)*)([a-zA-Z])')14
432 unmodified lines
447448449auto_wrap_for_ansi = None450colorama = None451get_winterm_size = None452453454# If we're on Windows, we provide transparent integration through455# colorama. This will make ANSI colors through the echo function456# work automatically.457if sys.platform.startswith('win'):458 # Windows has a smaller terminal459 DEFAULT_COLUMNS = 79460461 try:462 import colorama463 except ImportError:464 pass
30 unmodified lines
495 except Exception:496 pass497 return rv498499 def get_winterm_size():500 win = colorama.win32.GetConsoleScreenBufferInfo(501 colorama.win32.STDOUT).srWindow502 return win.Right - win.Left, win.Bottom - win.Top503504505506def strip_ansi(value):507 return _ansi_re.sub('', value)508509
44 unmodified lines
modified:click/termui.py+6 added-2 removed
1 unmodified line
2import sys3import struct45from ._compat import raw_input, text_type, string_types, \6 colorama, isatty, strip_ansi6 colorama, isatty, strip_ansi, get_winterm_size, \7 DEFAULT_COLUMNS8from .utils import echo9from .exceptions import Abort, UsageError10from .types import convert_type11
134 unmodified lines
146 if shutil_get_terminal_size:147 sz = shutil_get_terminal_size()148 return sz.columns, sz.lines149150 if get_winterm_size is not None:151 return get_winterm_size()152153 def ioctl_gwinsz(fd):154 try:155 import fcntl156 import termios
14 unmodified lines
171 except Exception:172 pass173 if not cr or not cr[0] or not cr[1]:174 cr = (os.environ.get('LINES', 25),171 os.environ.get('COLUMNS', 80))175 os.environ.get('COLUMNS', DEFAULT_COLUMNS))176 return int(cr[1]), int(cr[0])177178179def echo_via_pager(text):
312 unmodified lines
modified:CHANGES+4 added
9 unmodified lines
1011- fixed the :func:`launch` function on windows.12- improved the colorama support on windows to try hard to not13 screw up the console if the application is interrupted.14- fixed windows terminals incorrectly being reported to be 8015 characters wide instead of 7916- use colorama win32 bindings if available to get the correct17 dimensions of a windows terminal.1819Version 2.020-----------21
53 unmodified lines