Commit 20dae38
committed
Fix raw ANSI codes displaying for CompletionError in prompt_toolkit
When raising a CompletionError with apply_style=True during tab completion
in prompt_toolkit mode, the error message was printed directly to stdout using
ANSI codes. prompt_toolkit's patch_stdout would capture this but fail to
interpret the ANSI codes, resulting in raw escape sequences being displayed.
This commit fixes the issue by:
1. Modifying cmd2.complete to capture the styled error message into
self.completion_header instead of printing directly to stdout.
2. Updating Cmd2Completer.get_completions (in pt_utils.py) to print
completion_header using print_formatted_text wrapped in ANSI,
which correctly renders the styled text above the prompt.
3. Updating tests/conftest.py complete_tester to print completion_header
so existing tests (like test_completion_error) continue to pass by
capturing the error output.1 parent f1803b3 commit 20dae38
3 files changed
Lines changed: 17 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1624 | 1624 | | |
1625 | 1625 | | |
1626 | 1626 | | |
| 1627 | + | |
1627 | 1628 | | |
1628 | 1629 | | |
1629 | 1630 | | |
| |||
2468 | 2469 | | |
2469 | 2470 | | |
2470 | 2471 | | |
2471 | | - | |
2472 | | - | |
2473 | | - | |
2474 | | - | |
2475 | | - | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
2476 | 2478 | | |
2477 | 2479 | | |
2478 | 2480 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
79 | 84 | | |
80 | 85 | | |
81 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
154 | 159 | | |
155 | 160 | | |
156 | 161 | | |
| |||
0 commit comments