Skip to content
Myr

Refactored prompts a bit

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 f69bc7b · Browse files · 1 file+17 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−7 removed

  • other:+17 added−7 removed

1 file+17 added−7 removed

modified:click/termui.py+17 added-7 removed
16 unmodified lines
17 import getpass18 return getpass.getpass(prompt)192021def _build_prompt(text, suffix, show_default=False, default=None):22 prompt = text23 if default is not None and show_default:24 prompt = '%s [%s]' % (prompt, default)25 return prompt + suffix262728def prompt(text, default=None, hide_input=False,29 confirmation_prompt=False, type=None,23 value_proc=None):30 value_proc=None, prompt_suffix=': ', show_default=True):31 """Prompts a user for input. This is a convenience function that can32 be used to prompt a user for input later.3334 If the user aborts the input by sending a interrupt signal this
8 unmodified lines
43 :param type: the type to use to check the value against.44 :param value_proc: if this parameter is provided it's a function that45 is invoked instead of the type conversion to46 convert a value.47 :param prompt_suffix: a suffix that should be added to the prompt.48 :param show_default: shows or hides the default value in the prompt.49 """50 result = None5152 def prompt_func(text):
5 unmodified lines
5859 if value_proc is None:60 value_proc = convert_type(type, default)6153 prompt = text54 if default is not None:55 prompt = '%s [%s]' % (prompt, default)56 prompt += ': '62 prompt = _build_prompt(text, prompt_suffix, show_default, default)6364 while 1:65 while 1:66 value = prompt_func(prompt)
19 unmodified lines
86 return result87 echo('Error: the two entered values do not match')888984def confirm(text, default=False, abort=False):90def confirm(text, default=False, abort=False, prompt_suffix=': ',91 show_default=True):92 """Prompts for confirmation (yes/no question).9394 If the user aborts the input by sending a interrupt signal this95 function will catch it and raise a :exc:`Abort` exception.
1 unmodified line
97 :param text: the question to ask.98 :param default: the default for the prompt.99 :param abort: if this is set to `True` a negative answer aborts the100 exception by raising :exc:`Abort`.101 :param prompt_suffix: a suffix that should be added to the prompt.102 :param show_default: shows or hides the default value in the prompt.103 """95 prompt = '%s [%s]: ' % (text, default and 'Yn' or 'yN')104 prompt = _build_prompt(text, prompt_suffix, show_default,105 default and 'Yn' or 'yN')106 while 1:107 try:108 value = visible_prompt_func(prompt).lower().strip()109 except (KeyboardInterrupt, EOFError):
73 unmodified lines