Skip to content
Myr

Added an echo function with pager 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 a6f9401 · Browse files · 4 files+32 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

4 files+32 added−2 removed

  • other:+32 added−2 removed

4 files+32 added−2 removed

modified:click/__init__.py+2 added-2 removed
25 unmodified lines
26# Types27from .types import ParamType, File, Choice, STRING, INT, FLOAT, BOOL, UUID2829# Helper functions30from .helpers import prompt, confirm, get_terminal_size, echo30from .helpers import prompt, confirm, get_terminal_size, echo, echo_via_pager3132# Exceptions33from .exceptions import UsageError, Abort34
14 unmodified lines
49 # Types50 'ParamType', 'File', 'Choice', 'STRING', 'INT', 'FLOAT', 'BOOL', 'UUID',5152 # Helper functions53 'prompt', 'confirm', 'get_terminal_size', 'echo',53 'prompt', 'confirm', 'get_terminal_size', 'echo', 'echo_via_pager',5455 # Exceptions56 'UsageError', 'Abort',57
3 unmodified lines
modified:click/helpers.py+25 added
170 unmodified lines
171 message = message.encode(encoding, 'replace')172 file.write(message)173 file.write('\n')174 file.flush()175176177def _isatty(f):178 return getattr(f, 'isatty', lambda x: False)()179180181def echo_via_pager(text):182 """This function takes a text and shows it via an environment specific183 pager on stdout.184185 :param text: the text to page.186 """187 if not isinstance(text, string_types):188 text = text_type(text)189190 if PY2 and isinstance(text, text_type):191 encoding = get_best_encoding(sys.stdout)192 text = text.encode(encoding, 'replace')193194 # Pydoc's pager is badly broken with LANG=C on Python 3 to the point195 # where it will corrupt the terminal. http://bugs.python.org/issue21398196 # I don't feel like reimplementing it given that it works on Python 2197 # and seems reasonably stable otherwise.198 import pydoc199 pydoc.pager(text)
modified:docs/api.rst+2 added
34 unmodified lines
35----------------3637.. autofunction:: echo3839.. autofunction:: echo_via_pager4041.. autofunction:: prompt4243.. autofunction:: confirm44
66 unmodified lines
modified:docs/python3.rst+3 added
147 unmodified lines
148* `Use surrogateescape as default error handler149 <http://bugs.python.org/issue19977>`_150* `Python 3 raises Unicode errors in the C locale151 <http://bugs.python.org/issue19846>`_152* `LC_CTYPE=C: pydoc leaves terminal in an unusable state153 <http://bugs.python.org/issue21398>`_ (this is relevant to Click154 because the pager support is provided by the stdlib pydoc module)