2525from rich .text import Text
2626
2727from .constants import INFINITY
28- from .rich_utils import Cmd2GeneralConsole
2928
3029if TYPE_CHECKING : # pragma: no cover
3130 from .cmd2 import Cmd
@@ -500,11 +499,11 @@ def _handle_last_token(
500499
501500 # If we have results, then return them
502501 if completions :
503- if not completions .completion_hint :
502+ if not completions .hint :
504503 # Add a hint even though there are results in case Cmd.always_show_hint is True.
505504 completions = dataclasses .replace (
506505 completions ,
507- completion_hint = _build_hint (self ._parser , flag_arg_state .action ),
506+ hint = _build_hint (self ._parser , flag_arg_state .action ),
508507 )
509508
510509 return completions
@@ -528,11 +527,11 @@ def _handle_last_token(
528527
529528 # If we have results, then return them
530529 if completions :
531- if not completions .completion_hint :
530+ if not completions .hint :
532531 # Add a hint even though there are results in case Cmd.always_show_hint is True.
533532 completions = dataclasses .replace (
534533 completions ,
535- completion_hint = _build_hint (self ._parser , pos_arg_state .action ),
534+ hint = _build_hint (self ._parser , pos_arg_state .action ),
536535 )
537536 return completions
538537
@@ -592,8 +591,8 @@ def _complete_flags(self, text: str, line: str, begidx: int, endidx: int, used_f
592591
593592 return Completions (items )
594593
595- def _format_completions (self , arg_state : _ArgumentState , completions : Completions ) -> Completions :
596- """Format CompletionItems into completion table ."""
594+ def _build_completion_table (self , arg_state : _ArgumentState , completions : Completions ) -> Completions :
595+ """Build a rich.Table for completion results if applicable ."""
597596 # Skip table generation for single results or if the list exceeds the
598597 # user-defined threshold for table display.
599598 if len (completions ) < 2 or len (completions ) > self ._cmd2_app .max_completion_table_items :
@@ -627,19 +626,14 @@ def _format_completions(self, arg_state: _ArgumentState, completions: Completion
627626 column if isinstance (column , Column ) else Column (column , overflow = "fold" ) for column in table_header
628627 )
629628
630- # Add the data rows
631- hint_table = Table (* rich_columns , box = SIMPLE_HEAD , show_edge = False , border_style = Cmd2Style .TABLE_BORDER )
629+ # Build the table
630+ table = Table (* rich_columns , box = SIMPLE_HEAD , show_edge = False , border_style = Cmd2Style .TABLE_BORDER )
632631 for item in completions :
633- hint_table .add_row (Text .from_ansi (item .display ), * item .table_row )
634-
635- # Generate the table string
636- console = Cmd2GeneralConsole (file = self ._cmd2_app .stdout )
637- with console .capture () as capture :
638- console .print (hint_table , end = "" , soft_wrap = False )
632+ table .add_row (Text .from_ansi (item .display ), * item .table_row )
639633
640634 return dataclasses .replace (
641635 completions ,
642- completion_table = capture . get () ,
636+ table = table ,
643637 )
644638
645639 def complete_subcommand_help (self , text : str , line : str , begidx : int , endidx : int , tokens : Sequence [str ]) -> Completions :
@@ -780,7 +774,7 @@ def _complete_arg(
780774 filtered = [choice for choice in all_choices if choice .text not in used_values ]
781775 completions = self ._cmd2_app .basic_complete (text , line , begidx , endidx , filtered )
782776
783- return self ._format_completions (arg_state , completions )
777+ return self ._build_completion_table (arg_state , completions )
784778
785779
786780# The default ArgparseCompleter class for a cmd2 app
0 commit comments