-
Notifications
You must be signed in to change notification settings - Fork 127
Migrate from using readline to prompt-toolkit #1553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Tons of tests failing and some even getting stuck.
…f the correct arguments to app.complete() This fixes all of the test_argparse_comleter.py tests. There are still failing tests in test_cmd2.py, test_history.py, and test_run_pyscript.py as well as a test in test_cmd2.py that gets stuck.
TODO: - prompt-toolkit history isn't properly initialized with history from a persistent history file, as shown by the remaining failing history test
… of mocking the built-in input function. There are still 3 failing and 1 skipped test in test_cmd2.py Additionally, some tests in test_run_pyscript.py are getting stuck.All tests in other files are passing.
…ork with prompt-toolkit
Also: - Fixed make clean so it cleans up code coverage file artifacts
Also added a bottom toolboar for displaying these type hints.
|
🤖 Hi @tleonhardt, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1553 +/- ##
==========================================
+ Coverage 98.94% 99.08% +0.13%
==========================================
Files 21 21
Lines 4942 4895 -47
==========================================
- Hits 4890 4850 -40
+ Misses 52 45 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
🤖 I'm sorry @tleonhardt, but I was unable to process your request. Please see the logs for more details. |
… PromptSession and ensuring consistent input/output usage
…rs for better compatibility
…ws runners for better compatibility" This reverts commit 59c5ffa.
Set complete_style=CompleteStyle.READLINE_LIKE and complete_in_thread=True to restore <TAB><TAB> behavior showing all options, mimicking readline.
…ttom toolbar Removed completion hints from the bottom toolbar and implemented printing them above the prompt with ANSI support. Added an optional 'include_bottom_toolbar' parameter to Cmd.__init__ which displays the application name (sys.argv[0]) in the bottom toolbar when enabled.
…ional parameter is True
Subcommands completion hint (often a list of subcommands) was being displayed above the prompt, which is redundant when prompt-toolkit displays the subcommands in the completion menu. This change suppresses the hint for _SubParsersAction, allowing the completion menu to be the primary guide for subcommands.
Suppressed the generation of a completion hint for the main command name completion. This ensures that the command list appears in the prompt-toolkit completion menu below the prompt without a redundant or distracting hint above the prompt.
Switched PromptSession to CompleteStyle.COLUMN and disabled completion while typing to ensure the menu appears on the first Tab press with descriptions. Updated ArgparseCompleter to return CompletionItems for subcommands and main commands, allowing their descriptions to appear in the prompt-toolkit menu instead of a redundant hint table above the prompt. Restored printing of hint tables for other argument types.
Fixed an issue where argparse subcommands and flags were not showing in the prompt-toolkit completion menu on an empty Tab press. Improved Cmd2Completer to accurately calculate the word being completed using cmd2 delimiters. Refactored ArgparseCompleter to reduce complexity and return CompletionItems for flags, providing descriptions in the completion menu. Updated test suite to reflect improved functionality.
Fixed an issue where argparse subcommands and flags were not showing in the prompt-toolkit completion menu on an empty Tab press. Improved Cmd2Completer to accurately calculate the word being completed using cmd2 delimiters. Refactored ArgparseCompleter to reduce complexity and return CompletionItems for subcommands and flags, providing descriptions in the completion menu. Updated test suite to reflect improved functionality and maintain compatibility.
Updated ArgparseCompleter integration to display required argument hints in the prompt-toolkit bottom toolbar. This ensures hints like 'Hint: name name of this alias' are visible below the prompt when no completion matches are available. Restored printing of hint tables above the prompt for other argument types.
Updated ArgparseCompleter integration to display required argument hints by printing them above the prompt and allowing prompt-toolkit to redraw the prompt. This ensures hints like 'Hint: name name of this alias' are visible when no completion matches are available. Removed previous bottom toolbar implementation for hints.
Added unit tests for completion hints, hint tables, custom delimiter logic, and CompletionItem metadata handling in pt_utils.py. Achieved 100% code coverage (excluding TYPE_CHECKING blocks) and modernized existing tests to use real Document objects.
Updated Cmd._bottom_toolbar to display the application name in green on the left and the current ISO timestamp in blue on the right when include_bottom_toolbar is enabled. Used padding to achieve right-alignment of the timestamp. Updated associated tests to match the new return format.
Modified getting_started.py to spawn a background thread that triggers a UI redraw twice a second. This ensures that dynamic content in the bottom toolbar, such as the timestamp, stays current while waiting for user input.
Updated Cmd._bottom_toolbar to format the current time with 0.01s precision (two decimal places for fractional seconds). Maintained the ISO-like format including the timezone offset.
Updated documentation throughout the docs/ directory to reflect the migration from GNU Readline to prompt-toolkit and the addition of the new bottom toolbar feature. Added an upgrade guide section for 4.x, updated the history and prompt feature pages, and adjusted mkdocs configuration to allow documentation of the _bottom_toolbar method.
…pletion Added a unit test to verify that visible commands, aliases, and macros are correctly returned as CompletionItem objects for tab completion. Specifically addressed the case where a command has no docstring.
|
@kmvanbrunt This is ready for your review when you get a chance. @anselor @kotfu @theagilehacker @joqual If any of you have feedback, I'd also greatly appreciate it. |
This PR migrates from using GNU Readline for user input, tab-completion, and history to using prompt-toolkit for the same purpose.
prompt-toolkitis a pure-Pythonreadlinereplacement that is fully cross-platform compatible and doesn't rely on the presence of underlying C dynamic libraries. It also opens the door to some advanced features in the future.All use of
readlineis removed and thecmd2.rl_utilsmodule has been deleted. There is a newcmd2.pt_utilsmodule in its place. Currently all linting is passing and the documentation builds. This is essentially final draft that needs more testing. There are likely a some things that need to be considered related to asynicio support, signal handlers, and blocking popen calls.All tests are passing on all platforms. I have done some manual testing on both macOS and Linux. But I don't have a Windows VM to do any manual testing on Windows however.
NOTE FOR REVIEWERS: The substantive code changes are in the 3 following files (all in the
cmd2directory):argparse_completer.py(modified)cmd2.py(modified)pt_utils.py(new)TODO:
alias create <TAB>- currently showing nothinggetting_started.pyexample to show how to use the optional bottom toolbar feature