Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ prompt is displayed.
- Renamed `Cmd._command_parsers` to `Cmd.command_parsers`.
- Removed `RichPrintKwargs` `TypedDict` in favor of using `Mapping[str, Any]`, allowing for
greater flexibility in passing keyword arguments to `console.print()` calls.
- Removed `always_show_hint` settable as it provided a poor user experience with
`prompt-toolkit`
- Enhancements
- New `cmd2.Cmd` parameters
- **auto_suggest**: (boolean) if `True`, provide fish shell style auto-suggestions. These
Expand Down
13 changes: 0 additions & 13 deletions cmd2/argparse_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,6 @@ def _handle_last_token(

# If we have results, then return them
if completions:
if not completions.hint:
# Add a hint even though there are results in case Cmd.always_show_hint is True.
completions = dataclasses.replace(
completions,
hint=_build_hint(self._parser, flag_arg_state.action),
)

return completions

# Otherwise, print a hint if the flag isn't finished or text isn't possibly the start of a flag
Expand All @@ -519,12 +512,6 @@ def _handle_last_token(

# If we have results, then return them
if completions:
if not completions.hint:
# Add a hint even though there are results in case Cmd.always_show_hint is True.
completions = dataclasses.replace(
completions,
hint=_build_hint(self._parser, pos_arg_state.action),
)
return completions

# Otherwise, print a hint if text isn't possibly the start of a flag
Expand Down
8 changes: 2 additions & 6 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ def __init__(
instantiate and register all commands. If False, CommandSets
must be manually installed with `register_command_set`.
:param auto_suggest: If True, cmd2 will provide fish shell style auto-suggestions
based on history. If False, these will not be provided.
based on history. User can press right-arrow key to accept the
provided suggestion.
:param bottom_toolbar: if ``True``, then a bottom toolbar will be displayed.
:param command_sets: Provide CommandSet instances to load during cmd2 initialization.
This allows CommandSets with custom constructor parameters to be
Expand Down Expand Up @@ -464,7 +465,6 @@ def __init__(
self.interactive_pipe = False

# Attributes which ARE dynamically settable via the set command at runtime
self.always_show_hint = False
self.debug = False
self.echo = False
self.editor = self.DEFAULT_EDITOR
Expand Down Expand Up @@ -1324,10 +1324,6 @@ def allow_style_type(value: str) -> ru.AllowStyle:
choices_provider=get_allow_style_choices,
)
)

self.add_settable(
Settable("always_show_hint", bool, "Display completion hint even when completion suggestions print", self)
)
self.add_settable(Settable("debug", bool, "Show full traceback on exception", self))
self.add_settable(Settable("echo", bool, "Echo command issued into output", self))
self.add_settable(Settable("editor", str, "Program used by 'edit'", self))
Expand Down
7 changes: 3 additions & 4 deletions cmd2/pt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ def get_completions(self, document: Document, _complete_event: object) -> Iterab
console.print(completions.table, end="", soft_wrap=False)
print_formatted_text(pt_filter_style("\n" + capture.get()))

# Print hint if present and settings say we should
if completions.hint and (self.cmd_app.always_show_hint or not completions):
print_formatted_text(pt_filter_style(completions.hint))

if not completions:
# # Print hint if present
if completions.hint:
print_formatted_text(pt_filter_style(completions.hint))
return

# The length of the user's input minus any shortcut.
Expand Down
1 change: 0 additions & 1 deletion docs/features/builtin_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ application:
Name Value Description
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
allow_style Terminal Allow ANSI text style sequences in output (valid values: Always, Never, Terminal)
always_show_hint False Display completion hint even when completion suggestions print
debug False Show full traceback on exception
echo False Echo command issued into output
editor vim Program used by 'edit'
Expand Down
1 change: 0 additions & 1 deletion docs/features/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ The `cmd2.Cmd` class provides a large number of public instance attributes which

Here are instance attributes of `cmd2.Cmd` which developers might wish to override:

- **always_show_hint**: if `True`, display tab completion hint even when completion suggestions print (Default: `False`)
- **bottom_toolbar**: if `True`, then a bottom toolbar will be displayed (Default: `False`)
- **broken_pipe_warning**: if non-empty, this string will be displayed if a broken pipe error occurs
- **continuation_prompt**: used for multiline commands on 2nd+ line of input
Expand Down
5 changes: 0 additions & 5 deletions docs/features/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ This setting can be one of three values:
stripped.
- `Always` - ANSI escape sequences are always passed through to the output

### always_show_hint

If `True`, display tab completion hint even when completion suggestions print. The default value of
this setting is `False`.

### debug

The default value of this setting is `False`, which causes the `cmd2.Cmd.pexcept` method to only
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/postcmds.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set always_show_hint False
set allow_style Terminal
2 changes: 1 addition & 1 deletion tests/scripts/precmds.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set always_show_hint True
set allow_style Always
8 changes: 4 additions & 4 deletions tests/test_cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,11 @@ def test_run_script_nested_run_scripts(base_app, request) -> None:
expected = f"""
{initial_run}
_relative_run_script precmds.txt
set always_show_hint True
set allow_style Always
help
shortcuts
_relative_run_script postcmds.txt
set always_show_hint False"""
set allow_style Terminal"""
out, _err = run_cmd(base_app, "history -s")
assert out == normalize(expected)

Expand All @@ -505,11 +505,11 @@ def test_runcmds_plus_hooks(base_app, request) -> None:
base_app.runcmds_plus_hooks(["run_script " + prefilepath, "help", "shortcuts", "run_script " + postfilepath])
expected = f"""
run_script {prefilepath}
set always_show_hint True
set allow_style Always
help
shortcuts
run_script {postfilepath}
set always_show_hint False"""
set allow_style Terminal"""

out, _err = run_cmd(base_app, "history -s")
assert out == normalize(expected)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ def test_complete_set_value(cmd2_app) -> None:
expected = ["SUCCESS"]
completions = cmd2_app.complete(text, line, begidx, endidx)
assert completions.to_strings() == Completions.from_values(expected).to_strings()
assert completions.hint.strip() == "Hint:\n value a test settable param"
assert completions.hint.strip() == ""


def test_complete_set_value_invalid_settable(cmd2_app) -> None:
Expand Down
24 changes: 0 additions & 24 deletions tests/test_pt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def __init__(self) -> None:
self.complete = Mock(return_value=cmd2.Completions())

self.stdout = io.StringIO()
self.always_show_hint = False
self.statement_parser = Mock()
self.statement_parser.terminators = [";"]
self.statement_parser.shortcuts = []
Expand Down Expand Up @@ -335,29 +334,6 @@ def test_get_completions_no_matches(self, mock_cmd_app: MockCmd, monkeypatch) ->
args, _ = mock_print.call_args
assert cmd2_completions.hint in str(args[0])

def test_get_completions_always_show_hints(self, mock_cmd_app: MockCmd, monkeypatch) -> None:
"""Test that get_completions respects 'always_show_hint' and prints a hint even with no matches."""
mock_print = Mock()
monkeypatch.setattr(pt_utils, "print_formatted_text", mock_print)

completer = pt_utils.Cmd2Completer(cast(Any, mock_cmd_app))
document = Document("test", cursor_position=4)

# Enable hint printing when there are no matches.
mock_cmd_app.always_show_hint = True

# Set up matches
cmd2_completions = cmd2.Completions(hint="Completion Hint")
mock_cmd_app.complete.return_value = cmd2_completions

completions = list(completer.get_completions(document, None))
assert not completions

# Verify that only the completion hint printed
assert mock_print.call_count == 1
args, _ = mock_print.call_args
assert cmd2_completions.hint in str(args[0])

def test_get_completions_with_error(self, mock_cmd_app: MockCmd, monkeypatch) -> None:
"""Test get_completions with a completion error."""
mock_print = Mock()
Expand Down
Loading