Skip to content

Commit a5f18ec

Browse files
committed
Fixed issue where colors were being stripped by pyreadline3.
1 parent f739eb6 commit a5f18ec

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

cmd2/argparse_completer.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
from .constants import (
2121
INFINITY,
2222
)
23-
from .rich_utils import Cmd2Console
23+
from .rich_utils import (
24+
Cmd2Console,
25+
Cmd2Style,
26+
)
2427

2528
if TYPE_CHECKING: # pragma: no cover
2629
from .cmd2 import (
@@ -562,7 +565,13 @@ def _format_completions(self, arg_state: _ArgumentState, completions: list[str]
562565

563566
# Build all headers for the hint table
564567
headers: list[Column] = []
565-
headers.append(Column(destination.upper(), justify="right" if all_nums else "left", no_wrap=True))
568+
headers.append(
569+
Column(
570+
destination.upper(),
571+
justify="right" if all_nums else "left",
572+
no_wrap=True,
573+
)
574+
)
566575
for desc_header in desc_headers:
567576
header = (
568577
desc_header
@@ -575,7 +584,12 @@ def _format_completions(self, arg_state: _ArgumentState, completions: list[str]
575584
headers.append(header)
576585

577586
# Build the hint table
578-
hint_table = Table(*headers, box=SIMPLE_HEAD, show_edge=False, border_style="rule.line")
587+
hint_table = Table(
588+
*headers,
589+
box=SIMPLE_HEAD,
590+
show_edge=False,
591+
border_style=Cmd2Style.RULE_LINE,
592+
)
579593
for item in completion_items:
580594
hint_table.add_row(item, *item.descriptive_data)
581595

cmd2/cmd2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,13 +2168,13 @@ def _display_matches_pyreadline(self, matches: list[str]) -> None: # pragma: no
21682168
hint_printed = False
21692169
if self.always_show_hint and self.completion_hint:
21702170
hint_printed = True
2171-
readline.rl.mode.console.write('\n' + self.completion_hint)
2171+
sys.stdout.write('\n' + self.completion_hint)
21722172

21732173
# Check if we already have formatted results to print
21742174
if self.formatted_completions:
21752175
if not hint_printed:
2176-
readline.rl.mode.console.write('\n')
2177-
readline.rl.mode.console.write('\n' + self.formatted_completions + '\n')
2176+
sys.stdout.write('\n')
2177+
sys.stdout.write('\n' + self.formatted_completions + '\n')
21782178

21792179
# Redraw the prompt and input lines
21802180
rl_force_redisplay()

0 commit comments

Comments
 (0)