Added support for screen clearing.
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 4a30d5c · Browse files · 5 files·+37 added−3 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+37 added−3 removed
- other:+37 added−3 removed
Provenance
- Commit
09ba1e9- Tree
5624b8b- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
4a30d5c
5 files changed+37 added−3 removed
modified:click/__init__.py+2 added-2 removed
31 unmodified lines32 format_filename, get_app_dir33 34 # Terminal functions35 from .termui import prompt, confirm, get_terminal_size, echo_via_pager, \36- progressbar36+ progressbar, clear37 38 # Exceptions39 from .exceptions import ClickException, UsageError, BadParameter, \40 FileError, Abort24 unmodified lines65 'get_app_dir',66 67 # Terminal functions68 'prompt', 'confirm', 'get_terminal_size', 'echo_via_pager',69- 'progressbar',69+ 'progressbar', 'clear',70 71 # Exceptions72 'ClickException', 'UsageError', 'BadParameter', 'FileError',73 'Abort',7 unmodified linesmodified:click/termui.py+17 added-1 removed
1 unmodified line2 import sys3 import struct4 5 from ._compat import raw_input, PY2, text_type, string_types, \6- get_best_encoding6+ get_best_encoding, colorama7 from .utils import echo8 from .exceptions import Abort, UsageError9 from .types import convert_type10 238 unmodified lines249 item_show_func=item_show_func, fill_char=fill_char,250 empty_char=empty_char, bar_template=bar_template,251 info_sep=info_sep, file=file, label=label,252 width=width)253+254+255+def clear():256+ """Clears the terminal screen. This will have the effect of clearing257+ the whole visible space of the terminal and moving the cursor to the258+ top left.259+260+ .. versionadded:: 2.0261+ """262+ # If we're on windows and we don't have colorama available, then we263+ # clear the screen by shelling out. Otherwise we can use an escape264+ # sequence.265+ if sys.platform.startswith('win') and colorama is None:266+ os.system('cls')267+ else:268+ sys.stdout.write('\033[2J\033[1;1H')modified:docs/api.rst+2 added
42 unmodified lines43 .. autofunction:: confirm44 45 .. autofunction:: progressbar46 47+.. autofunction:: clear48+49 .. autofunction:: format_filename50 51 .. autofunction:: get_terminal_size52 101 unmodified linesmodified:docs/utils.rst+15 added
63 unmodified lines64 65 .. _colorama: https://pypi.python.org/pypi/colorama66 67 68+Screen Clearing69+---------------70+71+.. versionadded:: 2.072+73+To clear the terminal screen you can use the :func:`clear` function that74+is provided starting with Click 2.0. It does what the name suggests: it75+clears the entire visible screen in a platform agnostic way:76+77+::78+79+ import click80+ click.clear()81+82+83 Printing Filenames84 ------------------85 86 Because filenames might not be unicode, formatting them can be a bit113 unmodified linesmodified:CHANGES+1 added
17 unmodified lines18 - added :func:`get_app_dir`; a function to calculate the home folder19 for configs.20 - Added transparent handling for ANSI codes into the :func:`echo`21 function through `colorama`.22+- Added :func:`clear` function.23 24 Version 1.125 -----------26 11 unmodified lines