Read a line of input with optional completion and history. :param prompt: prompt to display to user :param history: optional Sequence of strings to use for up-arrow history. The passed in history will not be edited. It is the caller's responsibility to add th
(
self,
prompt: str = "",
*,
history: Sequence[str] | None = None,
preserve_quotes: bool = False,
choices: Iterable[Any] | None = None,
choices_provider: UnboundChoicesProvider[CmdOrSetT] | None = None,
completer: UnboundCompleter[CmdOrSetT] | None = None,
parser: Cmd2ArgumentParser | None = None,
)
| 3520 | return Cmd2Completer(self, custom_settings=settings) |
| 3521 | |
| 3522 | def read_input( |
| 3523 | self, |
| 3524 | prompt: str = "", |
| 3525 | *, |
| 3526 | history: Sequence[str] | None = None, |
| 3527 | preserve_quotes: bool = False, |
| 3528 | choices: Iterable[Any] | None = None, |
| 3529 | choices_provider: UnboundChoicesProvider[CmdOrSetT] | None = None, |
| 3530 | completer: UnboundCompleter[CmdOrSetT] | None = None, |
| 3531 | parser: Cmd2ArgumentParser | None = None, |
| 3532 | ) -> str: |
| 3533 | """Read a line of input with optional completion and history. |
| 3534 | |
| 3535 | :param prompt: prompt to display to user |
| 3536 | :param history: optional Sequence of strings to use for up-arrow history. The passed in history |
| 3537 | will not be edited. It is the caller's responsibility to add the returned input |
| 3538 | to history if desired. Defaults to None. |
| 3539 | :param preserve_quotes: if True, then quoted tokens will keep their quotes when processed by |
| 3540 | ArgparseCompleter. This is helpful in cases when you're completing |
| 3541 | flag-like tokens (e.g. -o, --option) and you don't want them to be |
| 3542 | treated as argparse flags when quoted. Set this to True if you plan |
| 3543 | on passing the string to argparse with the tokens still quoted. |
| 3544 | |
| 3545 | A maximum of one of these should be provided: |
| 3546 | :param choices: iterable of accepted values for single argument |
| 3547 | :param choices_provider: function that provides choices for single argument |
| 3548 | :param completer: completion function that provides choices for single argument |
| 3549 | :param parser: an argument parser which supports the completion of multiple arguments |
| 3550 | :return: the line read from stdin with all trailing new lines removed |
| 3551 | :raises EOFError: if the input stream is closed or the user signals EOF (e.g., Ctrl+D) |
| 3552 | :raises Exception: any other exceptions raised by prompt() |
| 3553 | """ |
| 3554 | completer_to_use = self._resolve_completer( |
| 3555 | preserve_quotes=preserve_quotes, |
| 3556 | choices=choices, |
| 3557 | choices_provider=choices_provider, |
| 3558 | completer=completer, |
| 3559 | parser=parser, |
| 3560 | ) |
| 3561 | |
| 3562 | temp_session: PromptSession[str] = PromptSession( |
| 3563 | auto_suggest=self.main_session.auto_suggest, |
| 3564 | complete_style=self.main_session.complete_style, |
| 3565 | complete_in_thread=self.main_session.complete_in_thread, |
| 3566 | complete_while_typing=self.main_session.complete_while_typing, |
| 3567 | completer=completer_to_use, |
| 3568 | history=InMemoryHistory(history) if history is not None else InMemoryHistory(), |
| 3569 | key_bindings=self.main_session.key_bindings, |
| 3570 | input=self.main_session.input, |
| 3571 | output=self.main_session.output, |
| 3572 | ) |
| 3573 | |
| 3574 | return self._read_raw_input(prompt, temp_session) |
| 3575 | |
| 3576 | def read_secret( |
| 3577 | self, |