rsalmei/alive-progress

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

Ravencentric opened this issue · 10 comments

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)

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")

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

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

In PowerShell the newline character is `n

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

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

Could it be because we are on different versions?
v6UdYt1

qLunar commented

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

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

@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

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