code: def prompt(
      text: str,
      default: t.Optional[t.Any] = None,
      hide_input: bool = False,
      confirmation_prompt: t.Union[bool, str] = False,
      type: t.Optional[t.Union[ParamType, t.Any]] = None,
      value_proc: t.Optional[t.Callable[[str], t.Any]] = None,
      prompt_suffix: str = ": ",
      show_default: bool = True,
      err: bool = False,
      show_choices: bool = True,
  ) -> t.Any:
      """Prompts a user for input.  This is a convenience function that can
      be used to prompt a user for input later.
  
      If the user aborts the input by sending an interrupt signal, this
      function will catch it and raise a :exc:`Abort` exception.
  
      :param text: the text to show for the prompt.
      :param default: the default value to use if no input happens.  If this
                      is not given it will prompt until it's aborted.
      :param hide_input: if this is set to true then the input value will
                         be hidden.
      :param confirmation_prompt: Prompt a second time to confirm the
          value. Can be set to a string instead of ``True`` to customize
          the message.
      :param type: the type to use to check the value against.
      :param value_proc: if this parameter is provided it's a function that
                         is invoked instead of the type conversion to
                         convert a value.
      :param prompt_suffix: a suffix that should be added to the prompt.
      :param show_default: shows or hides the default value in the prompt.
      :param err: if set to true the file defaults to ``stderr`` instead of
                  ``stdout``, the same as with echo.
      :param show_choices: Show or hide choices if the passed type is a Choice.
                           For example if type is a Choice of either day or week,
                           show_choices is true and text is "Group by" then the
                           prompt will be "Group by (day, week): ".
  
      .. versionadded:: 8.0
          ``confirmation_prompt`` can be a custom string.
  
      .. versionadded:: 7.0
          Added the ``show_choices`` parameter.
  
      .. versionadded:: 6.0
          Added unicode support for cmd.exe on Windows.
  
      .. versionadded:: 4.0
          Added the `err` parameter.
  
      """
  
      def prompt_func(text: str) -> str:
          f = hidden_prompt_func if hide_input else visible_prompt_func
          try:
              # Write the prompt separately so that we get nice
              # coloring through colorama on Windows
              echo(text.rstrip(" "), nl=False, err=err)
              # Echo a space to stdout to work around an issue where
              # readline causes backspace to clear the whole line.
              return f(" ")
          except (KeyboardInterrupt, EOFError):
              # getpass doesn't print a newline if the user aborts input with ^C.
              # Allegedly this behavior is inherited from getpass(3).
              # A doc bug has been filed at https://bugs.python.org/issue24711
              if hide_input:
                  echo(None, err=err)
              raise Abort() from None
  
      if value_proc is None:
          value_proc = convert_type(type, default)
  
      prompt = _build_prompt(
          text, prompt_suffix, show_default, default, show_choices, type
      )
  
      if confirmation_prompt:
          if confirmation_prompt is True:
              confirmation_prompt = _("Repeat for confirmation")
  
          confirmation_prompt = _build_prompt(
              confirmation_prompt, prompt_suffix
          )
  
      while True:
          while True:
              value = prompt_func(prompt)
              if value:
                  break
              elif default is not None:
                  value = default
                  break
          try:
              result = value_proc(value)
          except UsageError as e:
              if hide_input:
                  echo(
                      _("Error: The value you entered was invalid."),
                      err=err,
                  )
              else:
                  echo(
                      _("Error: {e.message}").format(e=e), err=err
                  )  # noqa: B306
              continue
          if not confirmation_prompt:
              return result
          while True:
              value2 = prompt_func(confirmation_prompt)
              is_empty = not value and not value2
              if value2 or is_empty:
                  break
          if value == value2:
              return result
          echo(
              _("Error: The two entered values do not match."), err=err
          )
  
imports: import inspect
  import io
  import itertools
  import sys
  import typing
  from gettext import gettext
  from ._compat import isatty
  from ._compat import strip_ansi
  from .exceptions import Abort
  from .exceptions import UsageError
  from .globals import resolve_color_default
  from .types import Choice
  from .types import convert_type
  from .types import ParamType
  from .utils import echo
  from .utils import LazyFile
label_desc: Use image node_id 4 for calling a global function with example usage: prompt(text, default, hide_input, confirmation_prompt, type, value_proc, prompt_suffix, show_default, err, show_choices) and returns: f, result, result