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
Provenance
- Commit
a85c5b7- Tree
6db7a2e- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent 1
1697599- Parent 2
1cceb6d
5 files changed+24 added−18 removed
modified:click/_compat.py+3 added-3 removed
5 unmodified lines6 from weakref import WeakKeyDictionary7 8 9 PY2 = sys.version_info[0] == 210+WIN = sys.platform.startswith('win')11 DEFAULT_COLUMNS = 8012 13 14 _ansi_re = re.compile('\033\[((?:\d|;)*)([a-zA-Z])')137 unmodified lines152 # 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 lines458 459 # If we're on Windows, we provide transparent integration through460 # colorama. This will make ANSI colors through the echo function461 # work automatically.461-if sys.platform.startswith('win'):462+if WIN:463 # Windows has a smaller terminal464 DEFAULT_COLUMNS = 79465 466 try:39 unmodified lines506 colorama.win32.STDOUT).srWindow507 return win.Right - win.Left, win.Bottom - win.Top508 509 509-510 def strip_ansi(value):511 return _ansi_re.sub('', value)512 513 44 unmodified linesmodified:click/_termui_impl.py+7 added-7 removed
12 unmodified lines13 import sys14 import time15 import math16 from ._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, WIN18 from .utils import echo19 from .exceptions import ClickException20 21 231 unmodified lines253 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 lines342 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 editor24 unmodified lines375 text += '\n'376 377 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 lines427 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 lines461 if ch == '\x04':462 raise EOFError()463 464 465-if sys.platform.startswith('win'):465+if WIN:466 import msvcrt467 468 def getchar(echo):469 rv = msvcrt.getch()37 unmodified linesmodified:click/termui.py+2 added-2 removed
2 unmodified lines3 import struct4 5 from ._compat import raw_input, text_type, string_types, \6 colorama, isatty, strip_ansi, get_winterm_size, \7- DEFAULT_COLUMNS7+ DEFAULT_COLUMNS, WIN8 from .utils import echo9 from .exceptions import Abort, UsageError10 from .types import convert_type11 266 unmodified lines278 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 linesmodified:click/utils.py+10 added-6 removed
3 unmodified lines4 5 from ._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, WIN9 10 if not PY2:11 from ._compat import _find_binary_writer12 231 unmodified lines244 return245 246 # 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)259 260 if message:261 file.write(message)262 if nl:85 unmodified lines348 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 linesmodified:CHANGES+2 added
26 unmodified lines27 28 (bugfix release, release date to be decided)29 30 - Fixed an incorrectly formatted help record for count options.'31+- Add support for ansi code stripping on Windows if colorama32+ is not available.33 34 Version 2.235 -----------36 78 unmodified lines