Added click.pause
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 525cc94 · Browse files · 5 files·+53 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
5 files+53 added−2 removed
- other:+53 added−2 removed
Provenance
- Commit
c9eb780- Tree
23945a9- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
525cc94
5 files changed+53 added−2 removed
modified:click/__init__.py+3 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- progressbar, clear, style, unstyle, secho, edit, launch, getchar36+ progressbar, clear, style, unstyle, secho, edit, launch, getchar, \37+ pause38 39 # Exceptions40 from .exceptions import ClickException, UsageError, BadParameter, \41 FileError, Abort25 unmodified lines67 68 # Terminal functions69 'prompt', 'confirm', 'get_terminal_size', 'echo_via_pager',70 'progressbar', 'clear', 'style', 'unstyle', 'secho', 'edit', 'launch',70- 'getchar',71+ 'getchar', 'pause',72 73 # Exceptions74 'ClickException', 'UsageError', 'BadParameter', 'FileError',75 'Abort',10 unmodified linesmodified:click/termui.py+24 added
459 unmodified lines460 f = _getchar461 if f is None:462 from ._termui_impl import getchar as f463 return f(echo)464+465+466+def pause(info='Press any key to continue ...'):467+ """This command stops execution and waits for the user to press any468+ key to continue. This is similar to the Windows batch "pause"469+ command. If the program is not run through a terminal this command470+ will do nothing instead.471+472+ .. versionadded:: 2.0473+474+ :param info: the info string to print before pausing.475+ """476+ if not isatty(sys.stdin) or not isatty(sys.stdout):477+ return478+ try:479+ if info:480+ echo(info, nl=False)481+ try:482+ getchar()483+ except (KeyboardInterrupt, EOFError):484+ pass485+ finally:486+ if info:487+ echo()modified:docs/api.rst+2 added
56 unmodified lines57 .. autofunction:: launch58 59 .. autofunction:: getchar60 61+.. autofunction:: pause62+63 .. autofunction:: get_terminal_size64 65 .. autofunction:: get_binary_stream66 101 unmodified linesmodified:docs/utils.rst+21 added
147 unmodified lines148 too easy to forget about that and to create scripts that cannot be149 properly exited.150 151 152+Waiting for Key Press153+---------------------154+155+.. versionadded:: 2.0156+157+Sometimes it's useful to pause until the user presses any key on the158+keyboard. This is especially useful on windows where ``cmd.exe`` by159+default will close the window at the end of the command execution instead160+of waiting.161+162+In click this can be accomplished by the :func:`pause` function. This163+function will print a quick message to the terminal (which can be164+customized) and wait for the user to press a key. In addition to that165+it will also become a noop if the script is not run interactively.166+167+Example::168+169+ import click170+ click.pause()171+172+173 Launching Editors174 -----------------175 176 .. versionadded:: 2.0160 unmodified linesmodified:CHANGES+3 added
34 unmodified lines35 - added :func:`getchar` to fetch a single character from the terminal.36 - errors now go to stderr as intended.37 - fixed various issues with more exotic parameter formats like DOS/Windows38 style arguments.39+- added :func:`pause` which works similar to the windows ``pause`` cmd40+ built in but becomes an automatic noop if the application is not run41+ through a terminal.42 43 Version 1.144 -----------45 11 unmodified lines