Skip to content

Refactored bottom toolbar and rprompt functionality.#1700

Open
kmvanbrunt wants to merge 6 commits into
mainfrom
refactor_bottom_toolbar
Open

Refactored bottom toolbar and rprompt functionality.#1700
kmvanbrunt wants to merge 6 commits into
mainfrom
refactor_bottom_toolbar

Conversation

@kmvanbrunt

@kmvanbrunt kmvanbrunt commented Jun 27, 2026

Copy link
Copy Markdown
Member
  • Removed default implementation of get_bottom_toolbar() from Cmd class and moved it to the getting_started example.
  • Renamed bottom_toolbar flag to enable_bottom_toolbar.
  • Added enable_rprompt flag.

Also closes #1699

work the same way as get_rprompt().

Removed default implementation of get_bottom_toolbar() from Cmd class
and moved it to the getting_started example.
@kmvanbrunt kmvanbrunt requested a review from tleonhardt as a code owner June 27, 2026 15:28
@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.60%. Comparing base (b17b1bd) to head (4706ed0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1700      +/-   ##
==========================================
+ Coverage   99.58%   99.60%   +0.01%     
==========================================
  Files          23       23              
  Lines        5773     5758      -15     
==========================================
- Hits         5749     5735      -14     
+ Misses         24       23       -1     
Flag Coverage Δ
unittests 99.60% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@tleonhardt tleonhardt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the two very minor issues I called out, I don't have problems with the code changes per se.

However, I have a big problem with the new default behavior from a UX perspective. Before this change, when a bottom toolbar wasn't requested, there was no visual display of a bottom bar. Now, it displays an empty gray bar which is ugly, distracting, and pointless.

Please fix it so the default behavior is like it was previously.

Comment thread examples/getting_started.py
Comment thread docs/features/prompt.md
@kmvanbrunt kmvanbrunt changed the title Simplified bottom toolbar usage. Refactored bottom toolbar and rprompt functionality. Jun 27, 2026
- **disabled_commands**: commands that have been disabled from use. This is to support commands that are only available during specific states of the application. This dictionary's keys are the command names and its values are DisabledCommand objects.
- **echo**: if `True`, each command the user issues will be repeated to the screen before it is executed. This is particularly useful when running scripts. This behavior does not occur when running a command at the prompt. (Default: `False`)
- **editor**: text editor program to use with _edit_ command (e.g. `vim`)
- **enable_bottom_toolbar**: if `True`, enables a bottom toolbar while at the main prompt. (Default: `False`)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added enable_bottom_toolbar and enable_rprompt (as well as refresh_interval below) are documented here as instance attributes, meaning they are instance members of the cmd2.Cmd instance that developers can override at runtime. However, in cmd2.py, they are strictly initializer arguments passed directly to PromptSession and are not stored on the Cmd instance. Attempting to override them at runtime will have no effect.

I think we should create a new section documenting __init__ parameters which are not also instance attributes and move them there.

This also applies to complete_in_thread.

Alternatively, we could restore them to instance attributes stored in Cmd.

Comment thread cmd2/cmd2.py

# Create the main PromptSession
self.bottom_toolbar = bottom_toolbar
self.complete_in_thread = complete_in_thread

@tleonhardt tleonhardt Jun 28, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since complete_in_thread, refresh_interval, and bottom_toolbar were previously public instance attributes on Cmd (and documented as such), removing them from the object instance will break downstream code that attempts to access or modify them. This should be explicitly noted in the breaking changes section of CHANGELOG.md, e.g.:

- Breaking Changes
    - ...
    - Removed `bottom_toolbar`, `complete_in_thread`, and `refresh_interval` as instance attributes of `Cmd`. They are now strictly `__init__` parameters.

Alternatively, we could restore them to being instance attributes.

Comment thread tests/test_cmd2.py
# Test overridden
expected_text = "bottom toolbar text"
base_app.get_bottom_toolbar = lambda: expected_text
assert base_app.get_bottom_toolbar() == expected_text

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overriding base_app.get_bottom_toolbar with a lambda and then asserting it returns the lambda's value only tests Python's ability to assign a function. Since the method no longer contains default logic, testing that the default implementation returns None is sufficient.

Comment thread tests/test_cmd2.py

expected_text = "rprompt text"
base_app.get_rprompt = lambda: expected_text
assert base_app.get_rprompt() == expected_text

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to test_get_bottom_toolbar, overriding get_rprompt with a lambda and asserting its return value tests Python's assignment capabilities rather than actual cmd2 functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make use of refresh_interval parameter for prompt-toolkit sessions

2 participants