Skip to content

gh-135883: Fix sqlite3 CLI keeps part of previous commands when scrolling history#135884

Merged
erlend-aasland merged 17 commits intopython:mainfrom
tanloong:fix-keeping-part-of-previous-commands
Mar 3, 2026
Merged

gh-135883: Fix sqlite3 CLI keeps part of previous commands when scrolling history#135884
erlend-aasland merged 17 commits intopython:mainfrom
tanloong:fix-keeping-part-of-previous-commands

Conversation

@tanloong
Copy link
Contributor

@tanloong tanloong commented Jun 24, 2025

Non-printing characters in the prompt need to be surrounded with \001 and \002 so readline knows those characters don't occupy screen space on redisplay.

Reference: https://lists.gnu.org/archive/html/bug-readline/2017-04/msg00018.html

@StanFromIreland
Copy link
Member

@ambv Maybe it would be better to implement this in _colorize.py instead, it could be an option for themes with_prompt_ignore=True?

@tanloong
Copy link
Contributor Author

tanloong commented Aug 9, 2025

Hi @erlend-aasland, could you take a look at this when you have some time? Thank you very much!

@tanloong
Copy link
Contributor Author

Hi, the issue this PR addresses is still present in main branch. Would it be possible to get a review from core developers? Thank you very much!

tanloong and others added 5 commits March 4, 2026 00:01
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@tanloong
Copy link
Contributor Author

tanloong commented Mar 3, 2026

Thank you for the review! I've committed the change.

It confused me why test_cli.Completion should use a plain "sqlite> " while test_cli.InteractiveSession should use "\001\002sqlite> \001\002" to make tests pass. After some digging: The Completion class uses run_pty() which creates real terminal environment, where SqliteInteractiveConsole invokes GNU Readline during running input(prompt). Readline goes through the call chain (readline(), readline_internal(), readline_internal_setup()) and finally calls _rl_strip_prompt() stripping the \001 and \002 from the output.

I added a comment in Completion about this in case any future developers are confused as well.

Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Choose a reason for hiding this comment

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

Thank you so much for the fix! (Sorry 'bout the late review!)

@erlend-aasland erlend-aasland added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Mar 3, 2026
@erlend-aasland erlend-aasland merged commit 745947c into python:main Mar 3, 2026
55 checks passed
@miss-islington-app

This comment was marked as outdated.

@miss-islington-app

This comment was marked as outdated.

@miss-islington-app
Copy link

Sorry, @tanloong and @erlend-aasland, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 745947cda0377bb44d791b7d8e58b327a9d84844 3.13

@erlend-aasland
Copy link
Contributor

@tanloong, do you want to take a stab at the backports?

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

Labels

needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants