rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.53k stars 206 forks source link

Clear multiple lines when printing all at once (fix #208) #209

Closed dlesbre closed 1 year ago

dlesbre commented 1 year ago

This is a small (untidy) fix I came up with for #208.

rsalmei commented 1 year ago

Thanks for the PR @dlesbre, but unfortunately I'm still with several changes in my local code preparing the 3.0 version whenever I have a bit of time, and thus won't be able to test or merge it for a while. But hang on please.

dlesbre commented 1 year ago

So my original fix didn't work since it would clear lines on "\n" but not on auto-line wrapping. This new commit should work better.

Here is an example code that fails with the original fix but works fine with the new one:

from alive_progress import alive_bar
from time import sleep

total = 2

# This was the original problem; fixed in both
with alive_bar(total, dual_line=True) as bar:
    bar.text = "Some fairly long line that stretches on and on and on..."
    for x in range(total):
        print("Any multiline\ntext")
        bar()
        sleep(2)

# This is the new problem, only fixed with latest PR version
with alive_bar(total, dual_line=True) as bar:
    bar.text = "Some fairly long line that stretches on and on and on..."
    for x in range(total):
        print(
            "Any single line text just slightly wider then your terminal will fail sadly ......................................................................."
        )
        bar()
        sleep(2)
rsalmei commented 1 year ago

Yeah, this is trickier than it looks. That's why I want to thoroughly test it, with various modes and options, to guarantee it doesn't break anything. Actually, my new unreleased code has 100% test code coverage, so it will be much easier after 3.0! But I'm lately very busy, and don't know when I'll be able to...

rsalmei commented 1 year ago

Merging it, thanks @dlesbre 👍