Skip to content

Commit 52a331c

Browse files
committed
Merge branch 'main' into argparse-monkeypatch
2 parents 7a5abfd + 06b4915 commit 52a331c

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

cmd2/cmd2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -727,11 +727,11 @@ def _should_continue_multiline(self) -> bool:
727727
def update_pt_style(self) -> None:
728728
"""Update the cached prompt_toolkit style."""
729729
theme = ru.get_theme()
730-
rich_menu_style = theme.styles.get(Cmd2Style.COMPLETION_MENU, "")
731-
rich_completion_style = theme.styles.get(Cmd2Style.COMPLETION_MENU_COMPLETION, "")
732-
rich_current_style = theme.styles.get(Cmd2Style.COMPLETION_MENU_CURRENT, "")
733-
rich_meta_style = theme.styles.get(Cmd2Style.COMPLETION_MENU_META, "")
734-
rich_meta_current_style = theme.styles.get(Cmd2Style.COMPLETION_MENU_META_CURRENT, "")
730+
rich_menu_style = theme.styles.get(Cmd2Style.COMPLETION_MENU, Style.null())
731+
rich_completion_style = theme.styles.get(Cmd2Style.COMPLETION_MENU_COMPLETION, Style.null())
732+
rich_current_style = theme.styles.get(Cmd2Style.COMPLETION_MENU_CURRENT, Style.null())
733+
rich_meta_style = theme.styles.get(Cmd2Style.COMPLETION_MENU_META, Style.null())
734+
rich_meta_current_style = theme.styles.get(Cmd2Style.COMPLETION_MENU_META_CURRENT, Style.null())
735735

736736
menu_style = rich_to_pt_style(rich_menu_style)
737737
completion_style = rich_to_pt_style(rich_completion_style)

cmd2/pt_utils.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Callable,
77
Iterable,
88
)
9+
from functools import lru_cache
910
from typing import (
1011
TYPE_CHECKING,
1112
Any,
@@ -75,6 +76,7 @@ def pt_filter_style(text: str | ANSI) -> str | ANSI:
7576
return text if isinstance(text, ANSI) else ANSI(text)
7677

7778

79+
@lru_cache(maxsize=256)
7880
def rich_to_pt_color(color: "Color | None") -> str:
7981
"""Convert a rich Color object to a prompt_toolkit color string."""
8082
if not color or color.is_default:
@@ -90,6 +92,7 @@ def rich_to_pt_color(color: "Color | None") -> str:
9092
return f"#{c.red:02x}{c.green:02x}{c.blue:02x}"
9193

9294

95+
@lru_cache(maxsize=1024)
9396
def rich_to_pt_style(rich_style: StyleType) -> str:
9497
"""Convert a rich Style object to a prompt_toolkit style string."""
9598
if not rich_style:
@@ -115,10 +118,8 @@ def rich_to_pt_style(rich_style: StyleType) -> str:
115118
if rich_style.blink is not None:
116119
parts.append("blink" if rich_style.blink else "noblink")
117120
if rich_style.reverse is not None:
118-
# prompt-toolkit uses 'reverse'
119121
parts.append("reverse" if rich_style.reverse else "noreverse")
120122
if rich_style.conceal is not None:
121-
# prompt-toolkit uses 'hidden' for Rich's 'conceal'
122123
parts.append("hidden" if rich_style.conceal else "nohidden")
123124
return " ".join(parts)
124125

@@ -296,11 +297,11 @@ def set_colors(self) -> None:
296297
"""Update colors from the current rich theme."""
297298
# Retrieve styles dynamically from the current theme
298299
theme = ru.get_theme()
299-
self.command_color = rich_to_pt_style(theme.styles.get(Cmd2Style.LEXER_COMMAND, ""))
300-
self.alias_color = rich_to_pt_style(theme.styles.get(Cmd2Style.LEXER_ALIAS, ""))
301-
self.macro_color = rich_to_pt_style(theme.styles.get(Cmd2Style.LEXER_MACRO, ""))
302-
self.flag_color = rich_to_pt_style(theme.styles.get(Cmd2Style.LEXER_FLAG, ""))
303-
self.argument_color = rich_to_pt_style(theme.styles.get(Cmd2Style.LEXER_ARGUMENT, ""))
300+
self.command_color = rich_to_pt_style(theme.styles.get(Cmd2Style.LEXER_COMMAND, Style.null()))
301+
self.alias_color = rich_to_pt_style(theme.styles.get(Cmd2Style.LEXER_ALIAS, Style.null()))
302+
self.macro_color = rich_to_pt_style(theme.styles.get(Cmd2Style.LEXER_MACRO, Style.null()))
303+
self.flag_color = rich_to_pt_style(theme.styles.get(Cmd2Style.LEXER_FLAG, Style.null()))
304+
self.argument_color = rich_to_pt_style(theme.styles.get(Cmd2Style.LEXER_ARGUMENT, Style.null()))
304305

305306
def lex_document(self, document: Document) -> Callable[[int], Any]:
306307
"""Lex the document."""

0 commit comments

Comments
 (0)