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 1697599, 1cceb6d · Browse files · 5 files+24 added−18 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+24 added−18 removed

  • other:+24 added−18 removed

5 files+24 added−18 removed

modified:click/_compat.py+3 added-3 removed
5 unmodified lines
6from weakref import WeakKeyDictionary789PY2 = sys.version_info[0] == 210WIN = sys.platform.startswith('win')11DEFAULT_COLUMNS = 80121314_ansi_re = re.compile('\033\[((?:\d|;)*)([a-zA-Z])')
137 unmodified lines
152 # An option would be to do what Python 3 does and to open the file as153 # binary only, patch it back to the system, and then use a wrapper154 # stream that converts newlines. It's not quite clear what's the155 # correct option here.155 if sys.platform == 'win32':156 if WIN:157 import msvcrt158 def set_binary_mode(f):159 try:160 fileno = f.fileno()
297 unmodified lines
458459# If we're on Windows, we provide transparent integration through460# colorama. This will make ANSI colors through the echo function461# work automatically.461if sys.platform.startswith('win'):462if WIN:463 # Windows has a smaller terminal464 DEFAULT_COLUMNS = 79465466 try:
39 unmodified lines
506 colorama.win32.STDOUT).srWindow507 return win.Right - win.Left, win.Bottom - win.Top508509509510def strip_ansi(value):511 return _ansi_re.sub('', value)512513
44 unmodified lines
modified:click/_termui_impl.py+7 added-7 removed
12 unmodified lines
13import sys14import time15import math16from ._compat import _default_text_stdout, range_type, PY2, isatty, \17 open_stream, strip_ansi, term_len, get_best_encoding17 open_stream, strip_ansi, term_len, get_best_encoding, WIN18from .utils import echo19from .exceptions import ClickException2021
231 unmodified lines
253 stdout = _default_text_stdout()254 if not isatty(sys.stdin) or not isatty(stdout):255 return _nullpager(stdout, text, color)256 if 'PAGER' in os.environ:257 if sys.platform == 'win32':257 if WIN:258 return _tempfilepager(text, os.environ['PAGER'], color)259 return _pipepager(text, os.environ['PAGER'], color)260 if os.environ.get('TERM') in ('dumb', 'emacs'):261 return _nullpager(stdout, text, color)262 if sys.platform == 'win32' or sys.platform.startswith('os2'):262 if WIN or sys.platform.startswith('os2'):263 return _tempfilepager(text, 'more <', color)264 if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:265 return _pipepager(text, 'less', color)266
75 unmodified lines
342 for key in 'VISUAL', 'EDITOR':343 rv = os.environ.get(key)344 if rv:345 return rv346 if sys.platform.startswith('win'):346 if WIN:347 return 'notepad'348 for editor in 'vim', 'nano':349 if os.system('which %s &> /dev/null' % editor) == 0:350 return editor
24 unmodified lines
375 text += '\n'376377 fd, name = tempfile.mkstemp(prefix='editor-', suffix=self.extension)378 try:379 if sys.platform.startswith('win'):379 if WIN:380 encoding = 'utf-8-sig'381 text = text.replace('\n', '\r\n')382 else:383 encoding = 'utf-8'
43 unmodified lines
427 try:428 return subprocess.Popen(args, stderr=null).wait()429 finally:430 null.close()431 elif sys.platform.startswith('win'):431 elif WIN:432 if locate:433 url = _unquote_file(url)434 args = 'explorer /select,"%s"' % _unquote_file(435 url.replace('"', ''))
25 unmodified lines
461 if ch == '\x04':462 raise EOFError()463464465if sys.platform.startswith('win'):465if WIN:466 import msvcrt467468 def getchar(echo):469 rv = msvcrt.getch()
37 unmodified lines
modified:click/termui.py+2 added-2 removed
2 unmodified lines
3import struct45from ._compat import raw_input, text_type, string_types, \6 colorama, isatty, strip_ansi, get_winterm_size, \7 DEFAULT_COLUMNS7 DEFAULT_COLUMNS, WIN8from .utils import echo9from .exceptions import Abort, UsageError10from .types import convert_type11
266 unmodified lines
278 return279 # If we're on Windows and we don't have colorama available, then we280 # clear the screen by shelling out. Otherwise we can use an escape281 # sequence.282 if sys.platform.startswith('win') and colorama is None:282 if WIN and colorama is None:283 os.system('cls')284 else:285 sys.stdout.write('\033[2J\033[1;1H')286
210 unmodified lines
modified:click/utils.py+10 added-6 removed
3 unmodified lines
45from ._compat import text_type, open_stream, get_streerror, string_types, \6 PY2, binary_streams, text_streams, filename_to_ui, \7 auto_wrap_for_ansi, strip_ansi, isatty, _default_text_stdout, \8 is_bytes8 is_bytes, WIN910if not PY2:11 from ._compat import _find_binary_writer12
231 unmodified lines
244 return245246 # ANSI-style support. If there is no message or we are dealing with247 # bytes nothing is happening. If we are connected to a file we want248 # to strip colors. If we have support for wrapping streams (windows249 # through colorama) we want to do that.248 # to strip colors. If we are on windows we either wrap the stream249 # to strip the color or we use the colorama support to translate the250 # ansi codes to API calls.251 if message and not is_bytes(message):252 if not isatty(file):253 message = strip_ansi(message)254 elif WIN:253 elif auto_wrap_for_ansi is not None:254 file = auto_wrap_for_ansi(file)255 if auto_wrap_for_ansi is not None:256 file = auto_wrap_for_ansi(file)257 else:258 message = strip_ansi(message)259260 if message:261 file.write(message)262 if nl:
85 unmodified lines
348 folder will be stored in the home folder with a leading349 dot instead of the XDG config home or darwin's350 application support folder.351 """348 if sys.platform.startswith('win'):352 if WIN:353 key = roaming and 'APPDATA' or 'LOCALAPPDATA'354 folder = os.environ.get(key)355 if folder is None:356 folder = os.path.expanduser('~')
9 unmodified lines
modified:CHANGES+2 added
26 unmodified lines
2728(bugfix release, release date to be decided)2930- Fixed an incorrectly formatted help record for count options.'31- Add support for ansi code stripping on Windows if colorama32 is not available.3334Version 2.235-----------36
78 unmodified lines