Skip to content
Myr

Merge branch '2.x-maintenance'

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 · parents f8ede67, 13aa9c5 · Browse files · 5 files+53 added−10 removed
This commit

State

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

Diff stats

5 files+53 added−10 removed

  • other:+53 added−10 removed

5 files+53 added−10 removed

modified:click/_compat.py+28 added-1 removed
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 pass465 else:466 _ansi_stream_wrappers = WeakKeyDictionary()467468 def auto_wrap_for_ansi(stream):469 """This function wraps a stream so that calls through colorama470 are issued to the win32 console API to recolor on demand. It471 also ensures to reset the colors if a write call is interrupted472 to not destroy the console afterwards.473 """474 try:475 cached = _ansi_stream_wrappers.get(stream)476 except Exception:477 cached = None478 if cached is not None:479 return cached480 strip = not isatty(stream)471 rv = colorama.AnsiToWin32(stream, strip=strip).stream481 ansi_wrapper = colorama.AnsiToWin32(stream, strip=strip)482 rv = ansi_wrapper.stream483 _write = rv.write484485 def _safe_write(s):486 try:487 return _write(s)488 except:489 ansi_wrapper.reset_all()490 raise491492 rv.write = _safe_write493 try:494 _ansi_stream_wrappers[stream] = rv495 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_impl.py+5 added-6 removed
410 unmodified lines
411 null.close()412 elif sys.platform.startswith('win'):413 if locate:414 url = _unquote_file(url)415 args = ['explorer', '/select,"%s"' % _unquote_file(url)]415 args = 'explorer /select,"%s"' % _unquote_file(416 url.replace('"', ''))417 else:417 args = ['start']418 if wait:419 args.append('/WAIT')420 args.append(url)421 return subprocess.Popen(args).wait()418 args = 'start %s "" "%s"' % (419 wait and '/WAIT' or '', url.replace('"', ''))420 return os.system(args)421422 try:423 if locate:424 url = os.path.dirname(_unquote_file(url)) or '.'
63 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:examples/termui/termui.py+1 added-1 removed
45 unmodified lines
46 for item in items:47 if random.random() > 0.3:48 yield item4950 with click.progressbar(items, label='Processing user accounts',50 with click.progressbar(items, label='Processing accounts',51 fill_char=click.style('#', fg='green')) as bar:52 for item in bar:53 process_slowly(item)54
91 unmodified lines
modified:CHANGES+13 added
1 unmodified line
2===============34This contains all major version changes between click releases.56Version 2.17-----------89(bugfix release, release date to be decided)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-----------2122(codename "tap tap tap", released on June 6th 2014)
52 unmodified lines