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
Provenance
- Commit
9740a74- Tree
f292901- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent 1
f8ede67- Parent 2
13aa9c5
5 files changed+53 added−10 removed
modified:click/_compat.py+28 added-1 removed
5 unmodified lines6 from weakref import WeakKeyDictionary7 8 9 PY2 = sys.version_info[0] == 210+DEFAULT_COLUMNS = 8011 12 13 _ansi_re = re.compile('\033\[((?:\d|;)*)([a-zA-Z])')14 432 unmodified lines447 448 449 auto_wrap_for_ansi = None450 colorama = None451+get_winterm_size = None452 453 454 # If we're on Windows, we provide transparent integration through455 # colorama. This will make ANSI colors through the echo function456 # work automatically.457 if sys.platform.startswith('win'):458+ # Windows has a smaller terminal459+ DEFAULT_COLUMNS = 79460+461 try:462 import colorama463 except ImportError:464 pass465 else:466 _ansi_stream_wrappers = WeakKeyDictionary()467 468 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.write484+485+ def _safe_write(s):486+ try:487+ return _write(s)488+ except:489+ ansi_wrapper.reset_all()490+ raise491+492+ rv.write = _safe_write493 try:494 _ansi_stream_wrappers[stream] = rv495 except Exception:496 pass497 return rv498 499+ def get_winterm_size():500+ win = colorama.win32.GetConsoleScreenBufferInfo(501+ colorama.win32.STDOUT).srWindow502+ return win.Right - win.Left, win.Bottom - win.Top503 504+505+506 def strip_ansi(value):507 return _ansi_re.sub('', value)508 509 44 unmodified linesmodified:click/_termui_impl.py+5 added-6 removed
410 unmodified lines411 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)421 422 try:423 if locate:424 url = os.path.dirname(_unquote_file(url)) or '.'63 unmodified linesmodified:click/termui.py+6 added-2 removed
1 unmodified line2 import sys3 import struct4 5 from ._compat import raw_input, text_type, string_types, \6- colorama, isatty, strip_ansi6+ colorama, isatty, strip_ansi, get_winterm_size, \7+ DEFAULT_COLUMNS8 from .utils import echo9 from .exceptions import Abort, UsageError10 from .types import convert_type11 134 unmodified lines146 if shutil_get_terminal_size:147 sz = shutil_get_terminal_size()148 return sz.columns, sz.lines149 150+ if get_winterm_size is not None:151+ return get_winterm_size()152+153 def ioctl_gwinsz(fd):154 try:155 import fcntl156 import termios14 unmodified lines171 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])177 178 179 def echo_via_pager(text):312 unmodified linesmodified:examples/termui/termui.py+1 added-1 removed
45 unmodified lines46 for item in items:47 if random.random() > 0.3:48 yield item49 50- 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 linesmodified:CHANGES+13 added
1 unmodified line2 ===============3 4 This contains all major version changes between click releases.5 6+Version 2.17+-----------8+9+(bugfix release, release date to be decided)10+11+- 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.18+19 Version 2.020 -----------21 22 (codename "tap tap tap", released on June 6th 2014)52 unmodified lines