Keep the right prompt out of the committed prompt frame - #1749
Merged
Conversation
prompt-toolkit ends every Application.run() with a final render, and that frame is what stays on the terminal. Its bottom toolbar container is filtered with ~is_done so it is excluded, but the right prompt is a plain Float with no such filter, so a copy of it was left beside every accepted command line in the scrollback. Wrap that float in a ConditionalContainer with the same ~is_done filter the toolbar already gets. The float is located by its "class:rprompt" style rather than by its private type, and a layout that does not contain it is left alone, since the right prompt is cosmetic and must not stop the application starting.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1749 +/- ##
=======================================
Coverage 99.64% 99.64%
=======================================
Files 23 23
Lines 5960 5973 +13
=======================================
+ Hits 5939 5952 +13
Misses 21 21
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
_read_raw_input() calls patch_stdout(), which asks the ambient app session for an Output. Without one bound, prompt-toolkit builds a real one on demand, and on Windows CI that is a Win32Output with no console behind it, so the test failed there on every Python version with NoConsoleScreenBufferError. Wrap the session in create_app_session() with the same pipe input and dummy output, matching how the other prompt-driving tests do it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With
enable_rprompt=True, the right prompt was redrawn beside every accepted command line in the scrollback, not just on the live prompt line:Cause
prompt-toolkit ends every
Application.run()with a final render, and that frame is what stays on the terminal.PromptSessionfilters its bottom toolbar container with~is_doneso the toolbar is excluded from it, but the right prompt is a plainFloatwith no such filter (shortcuts/prompt.py:157-162), so it is drawn into the committed frame once per command.Fix
Wrap that float in a
ConditionalContainerwith the same~is_donefilter the toolbar already gets.The float is located by its
"class:rprompt"style rather than by its private_RPrompttype, matching how cmd2 already identifies the toolbar container by"class:bottom-toolbar". A layout that does not contain it is left alone — the right prompt is cosmetic, and an upstream layout change must not stop the application from starting.main_session.rpromptis untouched, somain_session.rprompt == get_rpromptstill holds and the existingtest_enable_rpromptpasses unchanged.Verification
Driving
examples/getting_started.pythrough a real pty:maintests/test_cmd2.py::test_rprompt_is_not_drawn_into_the_committed_lineasserts the right prompt is not rendered whileis_done. Making the fix a no-op fails it withthe right prompt was drawn into the committed final frame.make checkclean (ruff, prettier, typos,ty,mypy --strict)make test: 1857 passed, 2 skippedmake docs-testcleanProvenance
Found while investigating the bottom toolbar flicker on #1748. That branch fixed this incidentally as a side effect of a much larger architecture change which does not fix the flicker and should not be merged; this extracts the one confirmed win as a standalone change against
main.