Skip to content

Commit a3890a7

Browse files
authored
Remove always_show_hint settable (#1652)
* Remove always_show_hint settable This setting worked well for some cases when cmd2 was using readline. However, due to subtle differences in how prompt-toolkit and readline work, setting this True provided a bad user experience with prompt-toolkit. * Simplified a logic condition to prevent double checking Also: - Clarified a parameter description to document how to accept fish-shell style auto-suggestions
1 parent 12a7d5e commit a3890a7

12 files changed

Lines changed: 14 additions & 61 deletions

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ prompt is displayed.
9999
- Renamed `Cmd._command_parsers` to `Cmd.command_parsers`.
100100
- Removed `RichPrintKwargs` `TypedDict` in favor of using `Mapping[str, Any]`, allowing for
101101
greater flexibility in passing keyword arguments to `console.print()` calls.
102+
- Removed `always_show_hint` settable as it provided a poor user experience with
103+
`prompt-toolkit`
102104
- Enhancements
103105
- New `cmd2.Cmd` parameters
104106
- **auto_suggest**: (boolean) if `True`, provide fish shell style auto-suggestions. These

cmd2/argparse_completer.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,6 @@ def _handle_last_token(
491491

492492
# If we have results, then return them
493493
if completions:
494-
if not completions.hint:
495-
# Add a hint even though there are results in case Cmd.always_show_hint is True.
496-
completions = dataclasses.replace(
497-
completions,
498-
hint=_build_hint(self._parser, flag_arg_state.action),
499-
)
500-
501494
return completions
502495

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

520513
# If we have results, then return them
521514
if completions:
522-
if not completions.hint:
523-
# Add a hint even though there are results in case Cmd.always_show_hint is True.
524-
completions = dataclasses.replace(
525-
completions,
526-
hint=_build_hint(self._parser, pos_arg_state.action),
527-
)
528515
return completions
529516

530517
# Otherwise, print a hint if text isn't possibly the start of a flag

cmd2/cmd2.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ def __init__(
395395
instantiate and register all commands. If False, CommandSets
396396
must be manually installed with `register_command_set`.
397397
:param auto_suggest: If True, cmd2 will provide fish shell style auto-suggestions
398-
based on history. If False, these will not be provided.
398+
based on history. User can press right-arrow key to accept the
399+
provided suggestion.
399400
:param bottom_toolbar: if ``True``, then a bottom toolbar will be displayed.
400401
:param command_sets: Provide CommandSet instances to load during cmd2 initialization.
401402
This allows CommandSets with custom constructor parameters to be
@@ -464,7 +465,6 @@ def __init__(
464465
self.interactive_pipe = False
465466

466467
# Attributes which ARE dynamically settable via the set command at runtime
467-
self.always_show_hint = False
468468
self.debug = False
469469
self.echo = False
470470
self.editor = self.DEFAULT_EDITOR
@@ -1324,10 +1324,6 @@ def allow_style_type(value: str) -> ru.AllowStyle:
13241324
choices_provider=get_allow_style_choices,
13251325
)
13261326
)
1327-
1328-
self.add_settable(
1329-
Settable("always_show_hint", bool, "Display completion hint even when completion suggestions print", self)
1330-
)
13311327
self.add_settable(Settable("debug", bool, "Show full traceback on exception", self))
13321328
self.add_settable(Settable("echo", bool, "Echo command issued into output", self))
13331329
self.add_settable(Settable("editor", str, "Program used by 'edit'", self))

cmd2/pt_utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ def get_completions(self, document: Document, _complete_event: object) -> Iterab
9797
console.print(completions.table, end="", soft_wrap=False)
9898
print_formatted_text(pt_filter_style("\n" + capture.get()))
9999

100-
# Print hint if present and settings say we should
101-
if completions.hint and (self.cmd_app.always_show_hint or not completions):
102-
print_formatted_text(pt_filter_style(completions.hint))
103-
104100
if not completions:
101+
# # Print hint if present
102+
if completions.hint:
103+
print_formatted_text(pt_filter_style(completions.hint))
105104
return
106105

107106
# The length of the user's input minus any shortcut.

docs/features/builtin_commands.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ application:
8080
Name Value Description
8181
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
8282
allow_style Terminal Allow ANSI text style sequences in output (valid values: Always, Never, Terminal)
83-
always_show_hint False Display completion hint even when completion suggestions print
8483
debug False Show full traceback on exception
8584
echo False Echo command issued into output
8685
editor vim Program used by 'edit'

docs/features/initialization.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ The `cmd2.Cmd` class provides a large number of public instance attributes which
3333

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

36-
- **always_show_hint**: if `True`, display tab completion hint even when completion suggestions print (Default: `False`)
3736
- **bottom_toolbar**: if `True`, then a bottom toolbar will be displayed (Default: `False`)
3837
- **broken_pipe_warning**: if non-empty, this string will be displayed if a broken pipe error occurs
3938
- **continuation_prompt**: used for multiline commands on 2nd+ line of input

docs/features/settings.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ This setting can be one of three values:
3737
stripped.
3838
- `Always` - ANSI escape sequences are always passed through to the output
3939

40-
### always_show_hint
41-
42-
If `True`, display tab completion hint even when completion suggestions print. The default value of
43-
this setting is `False`.
44-
4540
### debug
4641

4742
The default value of this setting is `False`, which causes the `cmd2.Cmd.pexcept` method to only

tests/scripts/postcmds.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
set always_show_hint False
1+
set allow_style Terminal

tests/scripts/precmds.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
set always_show_hint True
1+
set allow_style Always

tests/test_cmd2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,11 @@ def test_run_script_nested_run_scripts(base_app, request) -> None:
488488
expected = f"""
489489
{initial_run}
490490
_relative_run_script precmds.txt
491-
set always_show_hint True
491+
set allow_style Always
492492
help
493493
shortcuts
494494
_relative_run_script postcmds.txt
495-
set always_show_hint False"""
495+
set allow_style Terminal"""
496496
out, _err = run_cmd(base_app, "history -s")
497497
assert out == normalize(expected)
498498

@@ -505,11 +505,11 @@ def test_runcmds_plus_hooks(base_app, request) -> None:
505505
base_app.runcmds_plus_hooks(["run_script " + prefilepath, "help", "shortcuts", "run_script " + postfilepath])
506506
expected = f"""
507507
run_script {prefilepath}
508-
set always_show_hint True
508+
set allow_style Always
509509
help
510510
shortcuts
511511
run_script {postfilepath}
512-
set always_show_hint False"""
512+
set allow_style Terminal"""
513513

514514
out, _err = run_cmd(base_app, "history -s")
515515
assert out == normalize(expected)

0 commit comments

Comments
 (0)