Skip to content
Myr

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

5 files+37 added−3 removed

modified:click/__init__.py+2 added-2 removed
31 unmodified lines
32 format_filename, get_app_dir3334# Terminal functions35from .termui import prompt, confirm, get_terminal_size, echo_via_pager, \36 progressbar36 progressbar, clear3738# Exceptions39from .exceptions import ClickException, UsageError, BadParameter, \40 FileError, Abort
24 unmodified lines
65 'get_app_dir',6667 # Terminal functions68 'prompt', 'confirm', 'get_terminal_size', 'echo_via_pager',69 'progressbar',69 'progressbar', 'clear',7071 # Exceptions72 'ClickException', 'UsageError', 'BadParameter', 'FileError',73 'Abort',
7 unmodified lines
modified:click/termui.py+17 added-1 removed
1 unmodified line
2import sys3import struct45from ._compat import raw_input, PY2, text_type, string_types, \6 get_best_encoding6 get_best_encoding, colorama7from .utils import echo8from .exceptions import Abort, UsageError9from .types import convert_type10
238 unmodified lines
249 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)253254255def 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.259260 .. 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 lines
43.. autofunction:: confirm4445.. autofunction:: progressbar4647.. autofunction:: clear4849.. autofunction:: format_filename5051.. autofunction:: get_terminal_size52
101 unmodified lines
modified:docs/utils.rst+15 added
63 unmodified lines
6465.. _colorama: https://pypi.python.org/pypi/colorama666768Screen Clearing69---------------7071.. versionadded:: 2.07273To clear the terminal screen you can use the :func:`clear` function that74is provided starting with Click 2.0. It does what the name suggests: it75clears the entire visible screen in a platform agnostic way:7677::7879 import click80 click.clear()818283Printing Filenames84------------------8586Because filenames might not be unicode, formatting them can be a bit
113 unmodified lines
modified:CHANGES+1 added
17 unmodified lines
18- 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.2324Version 1.125-----------26
11 unmodified lines