Skip to content
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

Odd behavior where the progress bar deletes a printed line in terminal #254

Open
Ravencentric opened this issue Oct 5, 2023 · 10 comments
Open
Labels
only on windows Happens on Windows OS only

Comments

@Ravencentric
Copy link

Ravencentric commented Oct 5, 2023

from pathlib import Path
from time import sleep

from alive_progress import alive_it, config_handler
config_handler.set_global(length=50, theme="classic", dual_line=True)

files = list(Path.cwd().glob("*"))
bar = alive_it(files, title="TEST")

print("this text will get deleted")

for file in bar:
    file_type = "Folder" if file.is_dir() else "File"
    bar.text(f"{file_type}: {file.name}")
    sleep(1)

6zM869N

If I remove bar.text(f"{file_type}: {file.name}"), then it works as expected:

9RFZMOG

If I remove file_type = "Folder" if file.is_dir() else "File", again it works:

DGZC6wz

From what I can gather, evaluating anything in file_type from the above example causes this. Getting rid of either this or bar.text fixes it at the cost of well not being able to do what I want. Same happens if I use any arbitrary function like:

from pathlib import Path
from time import sleep

from alive_progress import alive_it, config_handler

config_handler.set_global(length=50, theme="classic", dual_line=True)


def check(file: Path) -> int:
    if file.is_dir():
        return 1
    else:
        return 0


files = list(Path.cwd().glob("*"))
bar = alive_it(files, title="TEST")

print("this text will get deleted")


for file in bar:
    file_type = "Folder" if check(file) == 1 else "File"
    bar.text = f"{file_type}: {file.name}"
    sleep(1)
@rsalmei
Copy link
Owner

rsalmei commented Oct 5, 2023

Yes, that is odd indeed.
I cannot reproduce it. Everything seems to work for me (macOS).
I see you are using Windows, right? I bet it is ignoring some ANSI Escape Code somehow.
But unfortunately, I cannot test it on a win machine.

Please, what happens if you force a \n in there?

print("this text will get deleted\n")

@Ravencentric
Copy link
Author

Ravencentric commented Oct 5, 2023

Same thing, it ends up "eating" away the newline. I was able to reproduce this on a different windows machine so it's likely a Windows issue. Don't have any unix machine on me to test.
4kHysVy

If I remove the print statement entirely, then it'll delete the prompt
5UOqJuo

@jspilinek
Copy link

jspilinek commented Oct 5, 2023

Have you tried cmd prompt? \n works for me.

In PowerShell the newline character is `n

@Ravencentric
Copy link
Author

Ravencentric commented Oct 5, 2023

I get the same result. I'm on Windows 11 Pro 22H2 if that matters.
1QLcu2f
pdVyt5A

@jspilinek
Copy link

jspilinek commented Oct 5, 2023

I used the below code from the first post and it works for me. I'm on Windows 11 Enterprise 22H2

from pathlib import Path
from time import sleep

from alive_progress import alive_it, config_handler
config_handler.set_global(length=50, theme="classic", dual_line=True)

files = list(Path.cwd().glob("*"))
bar = alive_it(files, title="TEST")

print("this text will get deleted")

for file in bar:
    file_type = "Folder" if file.is_dir() else "File"
    bar.text(f"{file_type}: {file.name}")
    sleep(1)

2023-10-05_15-47-50

@Ravencentric
Copy link
Author

Could it be because we are on different versions?
v6UdYt1

@qLunar
Copy link

qLunar commented Oct 6, 2023

Reproducible on my machine, changing dual_line to False also fixes it other than removing the lines raven mentioned.

@rsalmei
Copy link
Owner

rsalmei commented Oct 6, 2023

Thanks @jspilinek for the help!
I think it is up to you Windows devs to figure this out... I'll be a spectator here.

@jspilinek
Copy link

@Ravencentric I see you have (test-py3.11) in your cmd and powershell prompt. Maybe this is causing your issue?

Here's my Python version and alive-progress version

>python --version
Python 3.11.5
>pip list
Package         Version
--------------- ------------
about-time      4.2.1
alive-progress  3.1.4
grapheme        0.6.0
numpy           1.26.0
pandas          2.1.1
pip             23.2.1
python-dateutil 2.8.2
pytz            2023.3.post1
setuptools      65.5.0
six             1.16.0
tzdata          2023.3

@Ravencentric
Copy link
Author

Ravencentric commented Oct 6, 2023

That's just the python venv im using to isolate any other package from interfering

> python --version
Python 3.11.5
> pip list
Package        Version
-------------- -------
about-time     4.2.1
alive-progress 3.1.4
grapheme       0.6.0
pip            23.2.1
setuptools     68.1.2
wheel          0.41.2

Here, running it with global python instead:
sVcsiMk

@rsalmei rsalmei added the only on windows Happens on Windows OS only label Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
only on windows Happens on Windows OS only
Projects
None yet
Development

No branches or pull requests

4 participants