You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update cmd2.Cmd.select to use prompt-toolkit choice (#1600)
* Update cmd2.Cmd.select to use prompt-toolkit choice
Key Changes:
- prompt_toolkit.shortcuts.choice integration: The select method now utilizes the modern, interactive choice shortcut when both stdin and stdout are TTYs. This
provides a more user-friendly selection menu (usually supports arrow keys and searching).
- Backward Compatibility: Maintained the original numbered-list implementation as a fallback for non-TTY environments. This ensures that existing scripts,
pipes, and tests (which mock read_input) continue to function correctly.
- Robust Argument Handling: Standardized the conversion of various input formats (strings, lists of strings, lists of tuples) to the (value, label) format
required by choice.
- Error Handling: Wrapped the choice call in a loop and a try-except block to correctly handle KeyboardInterrupt (Ctrl-C) by printing ^C and re-raising, and to
handle cancellations by reprompting, maintaining consistency with original select behavior.
Co-authored-by: Kevin Van Brunt <kmvanbrunt@gmail.com>
0 commit comments