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

pacman style progress bar #34

Closed
FredBrockstedt opened this issue May 1, 2020 · 16 comments
Closed

pacman style progress bar #34

FredBrockstedt opened this issue May 1, 2020 · 16 comments

Comments

@FredBrockstedt
Copy link

I fail to make a pacman style progress bar with:
pacman = standard_bar_factory(borders="[]", tip=None, chars="Cc-", blank=" o")

It works sort of, but the dots move "away" from the "pacman".
Example:

[----------C  o  o  o  o  o  o  o  o  o  o]
[-----------C  o  o  o  o  o  o  o  o  o  ]
[------------C  o  o  o  o  o  o  o  o  o]

ideally the dots would stay in place, like this:

[----------C  o  o  o  o  o  o  o  o  o  o]
[----------c  o  o  o  o  o  o  o  o  o  o]
[-------------------------C  o  o  o  o]

The problem arises from how the padding (right part of the progress bar) is handled in bars.py.
My idea would be using some module tricks to scroll the padding. There is probably a better way.

@rsalmei
Copy link
Owner

rsalmei commented May 1, 2020

Hello @FredBrockstedt

The problem is because you are using two characters for a "blank", it should be a single char.
Experiment with a simple . or use the print_chars utility to find a more suitable char.

But it is a nice idea nevertheless! I liked it.
I'm going to include this support in the next version!
Yeah, it is a bit different than scrolling it, but instead of a blank argument, it would be something like a background, a text of any size that the bar would appear to roll over... It will be a nice effect!

It will maybe take a little while, because I'm in the middle of a big refactor in the whole alive_progress project, but I will surely include this new feature in it, I'll let you know.
Thanks!

@FredBrockstedt
Copy link
Author

Just as you reply... here is the solution, after thinking about it some time.
Replace: padding in bars.py line 19 with:
padding[::-1][:length - len(fill) - len(tip)][::-1]
Super easy right? The padding is created by repeating the padding letters and then cutting them off to the right length. This is pretty smart, but has the side effect of the letters appearing to be pushed to the right with progress.
By flipping, then truncating and flipping again, we subtract the letters on the left side, instead of the right. And no modulo BS.

@FredBrockstedt
Copy link
Author

And this can be done even simpler by:
padding[-length - len(fill) - len(tip):]
Let me get back to you on Sunday. If you like with a pull request.

@rsalmei
Copy link
Owner

rsalmei commented May 1, 2020 via email

@FredBrockstedt
Copy link
Author

That is very elegant. I don't think it will get better than this.
I'm closing this issue. Thank you for your support!
For the record: I use Arch Linux. Haha ;)

@rsalmei
Copy link
Owner

rsalmei commented May 1, 2020

You're welcome man!
Thank you for the idea! I'll let you know when it is available.

I didn't get Arch Linux joke 🤔
I use macOS 😉

@FredBrockstedt
Copy link
Author

FredBrockstedt commented May 1, 2020 via email

@rsalmei
Copy link
Owner

rsalmei commented May 2, 2020

Ohhh right, I see! lol
Nice!

@rsalmei rsalmei reopened this May 3, 2020
@rsalmei
Copy link
Owner

rsalmei commented May 3, 2020

Hey @FredBrockstedt , I'm releasing the "Pacman" support at this moment!

@rsalmei
Copy link
Owner

rsalmei commented May 3, 2020

Done. Care to test it again?

@FredBrockstedt
Copy link
Author

Outstanding work. There is a little bug. math.ceil returns a float and that can't be used to repeat a string. The first part is a little surprising, atleast to me. I send you a pull request with the little fix and the progress bar and a demo file, if you like to try for yourself.

@rsalmei
Copy link
Owner

rsalmei commented May 3, 2020

Thanks man.

That's odd, I did test it, thoroughly. It is working.
Which python version are you using?

@rsalmei
Copy link
Owner

rsalmei commented May 3, 2020

Python 3.7.6 (default, Mar 10 2020, 07:42:52)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import math

In [2]: math.ceil(3.1)
Out[2]: 4

In [3]: type(_)
Out[3]: int

@FredBrockstedt
Copy link
Author

My bad, I must have run it in python 2 without realizing. I checked the documentation and python 3 will return an integer as expected. In python 2 ceil returns a float, because an int might overflow. Funny thing, with the cast to int, it runs perfectly in 2.7, maybe that is the reason I didn't notice?

@rsalmei
Copy link
Owner

rsalmei commented May 3, 2020

Yeah, I do support python 2, it should really work. I'll drop python 2 support only in the next major version, 2.0, which is in the works.
In that sense, it really is a bug, forgot about ceil in py2... Thanks.

@rsalmei
Copy link
Owner

rsalmei commented May 11, 2020

Fixed that small python2 bug in #38.

Your PR #37 will still be open for a while, and will be the basis for the contrib feature, ok?

And I've enjoyed our chat, Thank you! 👍

@rsalmei rsalmei closed this as completed May 11, 2020
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

2 participants