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

Bar gets cut off after 80 characters #63

Closed
typecasto opened this issue Dec 10, 2020 · 28 comments
Closed

Bar gets cut off after 80 characters #63

typecasto opened this issue Dec 10, 2020 · 28 comments

Comments

@typecasto
Copy link

image

It cuts off stuff like the ETA and percentage when the numbers are large enough,

This is the vscode terminal if that makes any difference, but it also happens on fluent terminal.
Is there a way to make it adapt to my terminal width?

code example:

from alive_progress import alive_bar
import time

with alive_bar(15000, title="Sending messages...") as bar:
    for x in range(15000):
        time.sleep(10/15000)
        bar()
@rsalmei
Copy link
Owner

rsalmei commented Dec 12, 2020

Hey, this seems like the default value of Python's util, when it can't retrieve the number of cols.
Please enter python or ipython and do:

import shutil
shutil.get_terminal_size()

What is the result?

@typecasto
Copy link
Author

image

@rsalmei
Copy link
Owner

rsalmei commented Dec 14, 2020

I can't simulate that, even inside vscode's terminal:
image

@rsalmei
Copy link
Owner

rsalmei commented Dec 14, 2020

The same thing with your exact code. I'll try to test it on my windows machine, but I don't think it will make any difference.
image

@rsalmei
Copy link
Owner

rsalmei commented Dec 14, 2020

Could you please paste the code directly on terminal, like I did above?
Also, please paste this and let me see the result:

print(''.join(str(x % 10) * 10 for x in range(20)))

@typecasto
Copy link
Author

https://gfycat.com/AgreeableThoroughAsiaticlesserfreshwaterclam
I didn't add any print statements in there, no clue why it did that.

I removed the time.sleep() call, and after it got to the end it looked like this:
image

(sorry for being slow to respond, I'm turning on email notifications for github so I should respond faster now)

@rsalmei
Copy link
Owner

rsalmei commented Dec 19, 2020

No problem!

Well, that print did print ok, so there isn't anything blocking that.
Since I've tested inside vscode myself, that is also not the problem.
So, I'm kinda out of clues. Would it be vscode + windows? I haven't had the chance to test in a windows machine yet.
To debug more, I'd need to modify the internal code...

Do you have the WSL? Windows Subsystem for Linux?
It's really recommended, and surely will work there (besides improving your work joy).
Would you be willing to test that?

@typecasto
Copy link
Author

I've tried to get vscode working on wsl, but whatever I do, running code always launches the non-wsl vscode. Haven't had time to mess with it much, being this close to christmas. I'll give it a shot again once I get home.

@nghiemvdv
Copy link

this also happened to me while using cmd and powershell in windows terminal to run python script:

from alive_progress import alive_bar
from tqdm import tqdm # another progress bar package
import time


length = [5000, 6000, 4000, 0]
for l in length:
    with alive_bar(l, title="Sending messages...") as bar:
        for i in range(length[0]):
            time.sleep(0.0001)
            bar()

pbar = tqdm(total=length[0])
for i in range(length[0]):
    time.sleep(0.0001)
    pbar.update()

image
is this a windows-specific problem?

@typecasto
Copy link
Author

It does seem to be. I'll try to recreate it on a minimal vm, and either find a way to send it to you or lay out the steps tonight when I get back to the hotel.

@rsalmei
Copy link
Owner

rsalmei commented Jan 5, 2021

It's very strange, I really can't understand why.
I detect the terminal size via shutil.get_terminal_size(), and I know it returns 80 if it can't find it...
That's all I can think atm.

Thanks @thecakeisalie25, it would be awesome!
Maybe create a docker image which does reproduce the problem, and post it in a free repo on hub.docker.com...
Humm no, I think now only private repos are free... Maybe its Dockerfile and I can try to build it here.

@typecasto
Copy link
Author

I don't know any docker, I was just gonna make a vmware/virtualbox appliance and send it over via firefox send or magic-wormhole, and you could experiment with it that way.

@rsalmei
Copy link
Owner

rsalmei commented Jan 5, 2021

Ok, I can try here, no problem.
Let me know if you can simulate it!

@typecasto
Copy link
Author

Issue is replicated in a minimal windows vm running python 3.9.1, it happens in cmd, powershell, and the vscode terminal. I'm uploading the OVA now, if you're using virtualbox you'll have to change the os to a 64 bit one.

@typecasto
Copy link
Author

typecasto commented Jan 7, 2021

https://mega.nz/file/1rwXyCLJ#RueKLGr7A80Q8eM5xXc-Hw0CJ2gCrPpsySnYANqaseU @rsalmei here's the link to the ova, import it and check the bar_test file on the desktop.

@rsalmei
Copy link
Owner

rsalmei commented Jan 7, 2021

That's great, thank you @thecakeisalie25 !
Wow, 17GB, that's gonna take a while. But I'll see to it asap.

if you're using virtualbox you'll have to change the os to a 64 bit one.

What do you mean?
I'm not using any, I'll install virtualbox which is free.

@typecasto
Copy link
Author

Looking through the code, it seems like you wanted to use shutil.get_terminal_size(), but haven't implemented it yet (as per this comment) Loading the core/utils.py file and calling terminal_columns() returns 80:
image

@typecasto
Copy link
Author

and if you still want to test on that virtual machine, you have to edit the machine settings, and in that window there's a setting for virtual OS that you need to change to windows 10 64 bit, it defaults to other/unknown which is 32 bit.

@rsalmei
Copy link
Owner

rsalmei commented Jan 7, 2021

Oops, you're right, thank you!
It's been so much time I didn't tinker with alive-progress 1.6 I had forgotten that... Python 2 does not have shutil.get_terminal_size()!!! I've included it just on alive-progress 2.0, the new next major.

That explains it. That code for Python 2 uses internals of the console terminal, and really does not work on windows, only unix variants like linux and macOS...

As soon as I drop Py2 support it will work as intended..... Thank you @thecakeisalie25, you nailed it.
If you know of any way of getting terminal size on Py2 let me know!

@rsalmei
Copy link
Owner

rsalmei commented Jan 7, 2021

Hey, I just realized I can use that code as a fallback, I'm gonna fix it.
If it's a Python 3 environment, I'll call the correct method, if not then that fallback is the next best thing... 👍

@rsalmei
Copy link
Owner

rsalmei commented Jan 8, 2021

Hey @thecakeisalie25, great news!!
I just fixed it in #70!!
Please update and let me know if it is ok...

@rsalmei rsalmei closed this as completed Jan 8, 2021
@typecasto
Copy link
Author

confirmed fixed, nice work!

@rsalmei
Copy link
Owner

rsalmei commented Jan 8, 2021

Great!! Thank you man!
Enjoy, and stay tuned for 2.0! 🎉

@typecasto
Copy link
Author

are multiple simultaneous progress bars a planned feature for 2.0? That (and color) are the main features I've been wanting for a while now. I love this library btw, recently used it in my first ever actual major python project, which I'm really proud of.

@rsalmei
Copy link
Owner

rsalmei commented Jan 8, 2021

Thanks man! And congrats for your first major project! 🎉

Not yet, 2.0 is dedicated mostly to the spinner Compiler (zero overhead animations!), Python 3 and emoji support (grapheme clusters).
You can see more details here: #51

About multiple simultaneous bars, it is an old request, I'd love to implement that but I'm not so sure how...
I didn't figure out yet how to render multiple bars at the same time, with possibly very different update speeds, while still making the print hook work... There's more info here: #20 (comment)

@MichaelCurrie
Copy link

MichaelCurrie commented Aug 24, 2023

My workaround for this issue is to remind users of my script to keep their terminal window wide.

# To fix the problem of cut-off progress bar messages..
if os.get_terminal_size().columns < 100:
    raise AssertionError(
        "Your alive progress bars are going to potentially get cut off "
        "because your terminal window has fewer than 100 character columns. "
        "Please shrink the size of your view or expand the width and try again."
    )

@rsalmei
Copy link
Owner

rsalmei commented Aug 24, 2023

Hi @MichaelCurrie,
Yeah, or you could simply shrink the bar from the default 40 chars to as low as 3 chars to not break your script. Just use length=X.
The issue here was for an actual problem, where the bar was being truncated regardless of the terminal size.

@MichaelCurrie
Copy link

MichaelCurrie commented Aug 24, 2023

Unfortunately I've just seen that my workaround doesn't fix my problem. No matter how wide the terminal it gets cut off at exactly 80 characters:

image

But if I override max_cols option to be something other than the default value of 80, it's fixed:

alive_progress.alive_bar(total_items, max_cols=os.get_terminal_size().columns)

image

I'm not sure if this is really a bug, more of a caveat emptor to set the max_cols.

@rsalmei that's another good option as you say, to just shrink the bar itself using length=X.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants