@@ -528,8 +528,9 @@ def __init__(
528528 self ._initialize_history (persistent_history_file )
529529
530530 # Cache for prompt_toolkit completion menu styles
531- self ._cached_pt_style : PtStyle | None = None
532- self ._cached_pt_style_params : tuple [StyleType , StyleType , StyleType , StyleType , StyleType ] | None = None
531+ self .pt_style : PtStyle
532+ self .update_pt_style ()
533+ ru .register_theme_update_callback (self .update_pt_style )
533534
534535 # Create the main PromptSession
535536 self .bottom_toolbar = bottom_toolbar
@@ -724,27 +725,22 @@ def _should_continue_multiline(self) -> bool:
724725 # No macro found or already processed. The statement is complete.
725726 return False
726727
727- def _get_pt_style (self ) -> "PtStyle" :
728- """Return the cached prompt_toolkit style."""
728+ def update_pt_style (self ) -> None :
729+ """Update the cached prompt_toolkit style."""
729730 theme = ru .get_theme ()
730731 rich_menu_style = theme .styles .get (Cmd2Style .COMPLETION_MENU , "" )
731732 rich_completion_style = theme .styles .get (Cmd2Style .COMPLETION_MENU_COMPLETION , "" )
732733 rich_current_style = theme .styles .get (Cmd2Style .COMPLETION_MENU_CURRENT , "" )
733734 rich_meta_style = theme .styles .get (Cmd2Style .COMPLETION_MENU_META , "" )
734735 rich_meta_current_style = theme .styles .get (Cmd2Style .COMPLETION_MENU_META_CURRENT , "" )
735736
736- current_params = (rich_menu_style , rich_completion_style , rich_current_style , rich_meta_style , rich_meta_current_style )
737- if self ._cached_pt_style is not None and self ._cached_pt_style_params == current_params :
738- return self ._cached_pt_style
739-
740737 menu_style = rich_to_pt_style (rich_menu_style )
741738 completion_style = rich_to_pt_style (rich_completion_style )
742739 current_style = rich_to_pt_style (rich_current_style )
743740 meta_style = rich_to_pt_style (rich_meta_style )
744741 meta_current_style = rich_to_pt_style (rich_meta_current_style )
745742
746- self ._cached_pt_style_params = current_params
747- self ._cached_pt_style = PtStyle .from_dict (
743+ self .pt_style = PtStyle .from_dict (
748744 {
749745 "completion-menu" : menu_style ,
750746 "completion-menu.completion" : completion_style ,
@@ -755,7 +751,9 @@ def _get_pt_style(self) -> "PtStyle":
755751 }
756752 )
757753
758- return self ._cached_pt_style
754+ def _get_pt_style (self ) -> "PtStyle" :
755+ """Return the cached prompt_toolkit style."""
756+ return self .pt_style
759757
760758 def _create_main_session (self , auto_suggest : bool , completekey : str ) -> PromptSession [str ]:
761759 """Create and return the main PromptSession for the application.
0 commit comments