wolph / python-progressbar

Progressbar 2 - A progress bar for Python 2 and Python 3 - "pip install progressbar2"
http://progressbar-2.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
859 stars 103 forks source link

version 4.4: interactive shell: arrow keys yield weird symbols #293

Closed eachimei closed 9 months ago

eachimei commented 9 months ago

Description

With version 4.4.1 on Windows, after importing progressbar: pressing any arrow key yield odd symbols on the console:

Code

>>> import progressbar
>>> ^[[A^[[C^[[D^[[C^[[D^[[C^[[D^[[B^[[D^[[C^[[A^[[C^[[B^[[D   # <-- this is what happens when pressing different arrow keys on the keyboard

Versions

eachimei commented 9 months ago

Suspecting this change:

https://github.com/wolph/python-progressbar/commit/a9c677021e963cb419d0eac764ada0ee2f6add79#diff-5bd70fb63160004c558a687f98cb5dfe4a8925be30f161048b96966cd9de054bR170

Before this, set_console_mode() was not invoked by just importing progressbar

wolph commented 9 months ago

You are very likely right... that mode enables 24 bit color support in your terminal but apparently it has side-effects in some cases.

For some reason the console mode isn't reverted back to it's original state once the script is done it seems so that's certainly a bug.

As a quick workaround, I can't reproduce the issue in PowerShell so that might help

eachimei commented 9 months ago

Thanks for the quick response! I am able to reproduce it on Powershell as well: image

wolph commented 9 months ago

Oh... that's odd. Generally on Linux/Unix systems this is caused by not having readline available, but while it's better with readline, it doesn't solve the issue for me it seems.

You can try like this:

pip install pyreadline3

And after that:

import pyreadline3
pyreadline3.Readline()
eachimei commented 9 months ago

Still buggy, this time pressing arrow keys makes parts of the terminal to disappear: image

if I press some more arrow keys, it will erase more chunks: image

wolph commented 9 months ago

I've pushed a fix to the develop branch, can you see if it works for you?

pip install "git+https://github.com/wolph/python-progressbar.git#egg=progressbar2"
eachimei commented 9 months ago

Looks good! The issue does not reproduce with this version (commit 20f1bbb41f751824a28bbe7ea88cedf718b7a12a)

wolph commented 9 months ago

The new release is online!

eachimei commented 9 months ago

Thanks @wolph ! I currently don't see a new release (4.4.2 ?) on pypi though: https://pypi.org/project/progressbar2/#history image

wolph commented 8 months ago

Odd... I've attempted to upload it again and it seems to have worked this time :) image

eachimei commented 8 months ago

Cheers, thank you! Confirmed no issue using 4.4.2 👍