Commit 149bcca
committed
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.1 parent 5ab816e commit 149bcca
2 files changed
+33
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
4368 | 4368 | | |
4369 | 4369 | | |
4370 | 4370 | | |
4371 | | - | |
| 4371 | + | |
4372 | 4372 | | |
4373 | 4373 | | |
4374 | 4374 | | |
| |||
4385 | 4385 | | |
4386 | 4386 | | |
4387 | 4387 | | |
4388 | | - | |
| 4388 | + | |
4389 | 4389 | | |
4390 | 4390 | | |
4391 | 4391 | | |
4392 | 4392 | | |
4393 | 4393 | | |
4394 | | - | |
4395 | | - | |
4396 | | - | |
| 4394 | + | |
| 4395 | + | |
| 4396 | + | |
| 4397 | + | |
| 4398 | + | |
| 4399 | + | |
| 4400 | + | |
| 4401 | + | |
| 4402 | + | |
| 4403 | + | |
| 4404 | + | |
| 4405 | + | |
| 4406 | + | |
| 4407 | + | |
| 4408 | + | |
| 4409 | + | |
| 4410 | + | |
4397 | 4411 | | |
4398 | 4412 | | |
4399 | 4413 | | |
| |||
4411 | 4425 | | |
4412 | 4426 | | |
4413 | 4427 | | |
4414 | | - | |
4415 | | - | |
| 4428 | + | |
| 4429 | + | |
4416 | 4430 | | |
4417 | | - | |
| 4431 | + | |
4418 | 4432 | | |
4419 | 4433 | | |
4420 | 4434 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
3 | 6 | | |
4 | 7 | | |
5 | 8 | | |
| |||
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
12 | 21 | | |
13 | 22 | | |
14 | 23 | | |
| |||
0 commit comments