Skip to content

Commit 400f744

Browse files
committed
Remove complete_style parameter from cmd2.Cmd.__init__
prompt-toolkit complete_style argument now gets set automatically based on the number of completion results based on the max_column_completion_items parameter and settable.
1 parent 1d59d5a commit 400f744

File tree

5 files changed

+7
-28
lines changed

5 files changed

+7
-28
lines changed

CHANGELOG.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ shell, and the option for a persistent bottom bar that can display realtime stat
3636
displaying realtime status information while the prompt is displayed, see the
3737
`cmd2.Cmd2.get_bottom_toolbar` method that can be overridden as well as the updated
3838
`getting_started.py` example
39-
- **complete_style**: (enum) style of prompt-toolkit tab completion to use, 3 valid options
40-
are:
41-
- 1. `CompleteStyle.COLUMN` (default) - displays hints with help next to them in one
42-
big column
43-
- 2. `CompleteStyle.MULTI_COLUMN` - displays hints across multiple columns, with help
44-
when selected
45-
- 3. `CompleteStyle.READLINE_LIKE` - displays like readline; WARNING:
46-
`complete_in_thread` doesn't work for background completion when this option is
47-
selected
4839
- **max_column_completion_items**: (int) the maximum number of completion results to display
4940
in a single column, used to provide the initial value for a settable with the same name
5041
- Added `cmd2.Cmd._in_prompt` flag that is set to `True` when the prompt is displayed and the

cmd2/cmd2.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ def __init__(
301301
auto_suggest: bool = True,
302302
bottom_toolbar: bool = False,
303303
command_sets: Iterable[CommandSet] | None = None,
304-
complete_style: CompleteStyle = CompleteStyle.COLUMN,
305304
include_ipy: bool = False,
306305
include_py: bool = False,
307306
intro: RenderableType = '',
@@ -343,10 +342,6 @@ def __init__(
343342
This allows CommandSets with custom constructor parameters to be
344343
loaded. This also allows the a set of CommandSets to be provided
345344
when `auto_load_commands` is set to False
346-
:param complete_style: style of prompt-toolkit tab completion to use, 3 valid options are:
347-
1. CompleteStyle.COLUMN (default) - displays hints with help next to them in one big column
348-
2. CompleteStyle.MULTI_COLUMN - displays hints across multiple columns, with help when selected
349-
3. CompleteStyle.READLINE_LIKE - displays like readline, complete_in_thread doesn't work
350345
:param include_ipy: should the "ipy" command be included for an embedded IPython shell
351346
:param include_py: should the "py" command be included for an embedded Python shell
352347
:param intro: introduction to display at startup
@@ -480,7 +475,7 @@ def _(event: Any) -> None: # pragma: no cover
480475
auto_suggest=self.auto_suggest,
481476
bottom_toolbar=self.get_bottom_toolbar if self.bottom_toolbar else None,
482477
complete_in_thread=True,
483-
complete_style=complete_style,
478+
complete_style=CompleteStyle.MULTI_COLUMN,
484479
complete_while_typing=False,
485480
completer=self.completer,
486481
history=self.history_adapter,
@@ -495,7 +490,7 @@ def _(event: Any) -> None: # pragma: no cover
495490
auto_suggest=self.auto_suggest,
496491
bottom_toolbar=self.get_bottom_toolbar if self.bottom_toolbar else None,
497492
complete_in_thread=True,
498-
complete_style=complete_style,
493+
complete_style=CompleteStyle.MULTI_COLUMN,
499494
complete_while_typing=False,
500495
completer=self.completer,
501496
history=self.history_adapter,
@@ -2539,11 +2534,10 @@ def complete(
25392534
self.matches_sorted = True
25402535

25412536
# Swap between COLUMN and MULTI_COLUMN style based on the number of matches if not using READLINE_LIKE
2542-
if self.session.complete_style != CompleteStyle.READLINE_LIKE:
2543-
if len(self.completion_matches) > self.max_column_completion_items:
2544-
self.session.complete_style = CompleteStyle.MULTI_COLUMN
2545-
else:
2546-
self.session.complete_style = CompleteStyle.COLUMN
2537+
if len(self.completion_matches) > self.max_column_completion_items:
2538+
self.session.complete_style = CompleteStyle.MULTI_COLUMN
2539+
else:
2540+
self.session.complete_style = CompleteStyle.COLUMN
25472541

25482542
try:
25492543
return self.completion_matches[state]

docs/features/initialization.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Here are instance attributes of `cmd2.Cmd` which developers might wish to overri
2626

2727
- **always_show_hint**: if `True`, display tab completion hint even when completion suggestions print (Default: `False`)
2828
- **bottom_toolbar**: if `True`, then a bottom toolbar will be displayed (Default: `False`)
29-
- **complete_style**: style to display tab-completion hints in (from `CompleteStyle` options in `prompt-toolkit`)
3029
- **broken_pipe_warning**: if non-empty, this string will be displayed if a broken pipe error occurs
3130
- **continuation_prompt**: used for multiline commands on 2nd+ line of input
3231
- **debug**: if `True`, show full stack trace on error (Default: `False`)

examples/basic_completion.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
import functools
1515

16-
from prompt_toolkit.shortcuts import CompleteStyle
17-
1816
import cmd2
1917

2018
# List of strings used with completion functions
@@ -33,7 +31,7 @@
3331

3432
class BasicCompletion(cmd2.Cmd):
3533
def __init__(self) -> None:
36-
super().__init__(auto_suggest=False, complete_style=CompleteStyle.MULTI_COLUMN, include_py=True)
34+
super().__init__(auto_suggest=False, include_py=True)
3735

3836
def do_flag_based(self, statement: cmd2.Statement) -> None:
3937
"""Tab completes arguments based on a preceding flag using flag_based_complete

examples/hello_cmd2.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env python
22
"""This is intended to be a completely bare-bones cmd2 application suitable for rapid testing and debugging."""
33

4-
from prompt_toolkit.shortcuts import CompleteStyle
5-
64
from cmd2 import (
75
cmd2,
86
)
@@ -12,7 +10,6 @@
1210

1311
# If run as the main application, simply start a bare-bones cmd2 application with only built-in functionality.
1412
app = cmd2.Cmd(
15-
complete_style=CompleteStyle.READLINE_LIKE, # Use readline style tab completion instead of prompt-toolkit style
1613
include_ipy=True, # Enable support for interactive Python shell via py command
1714
include_py=True, # Enable support for interactive IPython shell via ipy command
1815
persistent_history_file='cmd2_history.dat', # Persist history between runs

0 commit comments

Comments
 (0)