Skip to content
Myr

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

5 files+53 added−2 removed

modified:click/__init__.py+3 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 progressbar, clear, style, unstyle, secho, edit, launch, getchar36 progressbar, clear, style, unstyle, secho, edit, launch, getchar, \37 pause3839# Exceptions40from .exceptions import ClickException, UsageError, BadParameter, \41 FileError, Abort
25 unmodified lines
6768 # Terminal functions69 'prompt', 'confirm', 'get_terminal_size', 'echo_via_pager',70 'progressbar', 'clear', 'style', 'unstyle', 'secho', 'edit', 'launch',70 'getchar',71 'getchar', 'pause',7273 # Exceptions74 'ClickException', 'UsageError', 'BadParameter', 'FileError',75 'Abort',
10 unmodified lines
modified:click/termui.py+24 added
459 unmodified lines
460 f = _getchar461 if f is None:462 from ._termui_impl import getchar as f463 return f(echo)464465466def 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.471472 .. versionadded:: 2.0473474 :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 lines
57.. autofunction:: launch5859.. autofunction:: getchar6061.. autofunction:: pause6263.. autofunction:: get_terminal_size6465.. autofunction:: get_binary_stream66
101 unmodified lines
modified:docs/utils.rst+21 added
147 unmodified lines
148too easy to forget about that and to create scripts that cannot be149properly exited.150151152Waiting for Key Press153---------------------154155.. versionadded:: 2.0156157Sometimes it's useful to pause until the user presses any key on the158keyboard. This is especially useful on windows where ``cmd.exe`` by159default will close the window at the end of the command execution instead160of waiting.161162In click this can be accomplished by the :func:`pause` function. This163function will print a quick message to the terminal (which can be164customized) and wait for the user to press a key. In addition to that165it will also become a noop if the script is not run interactively.166167Example::168169 import click170 click.pause()171172173Launching Editors174-----------------175176.. versionadded:: 2.0
160 unmodified lines
modified:CHANGES+3 added
34 unmodified lines
35- 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.4243Version 1.144-----------45
11 unmodified lines