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

Message Bounce [How-To] #35

Closed CRO-THEHACKER closed 4 years ago

CRO-THEHACKER commented 4 years ago

If you look for "message_bouncing" in https://asciinema.org/a/OR83rcm8J06w0OC9pkgnaJmYG This is what I am trying to do, how would I do this?

Thanks!

rsalmei commented 4 years ago

Hello @CRO-THEHACKER

It's very easy, just import the bouncing_spinner_factory and declare your messages, the one thats goes to the right and the one goes back to the left, and then start alive_bar with it! Like this:

from alive_progress import bouncing_spinner_factory

my_message = bouncing_spinner_factory('message1', 15, left_chars='message2', hiding=False)

with alive_bar(10, spinner=my_message) as bar:
    ...

That's it!

EDIT: fixed alive_bar call.

CRO-THEHACKER commented 4 years ago

I still don't understand. I'm getting this error.

Traceback (most recent call last):
  File "main.py", line 90, in <module>
    welcome_bootup()
  File "main.py", line 83, in welcome_bootup
    with alive_bar(10, bar=my_message) as bar:
  File "/usr/lib/python3.5/contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "/usr/local/lib/python3.5/dist-packages/alive_progress/progress.py", line 90, in alive_bar
    config = config_handler(**options)
  File "/usr/local/lib/python3.5/dist-packages/alive_progress/configuration.py", line 80, in create_context
    local_config.update(_parse(theme, options))
  File "/usr/local/lib/python3.5/dist-packages/alive_progress/configuration.py", line 104, in _parse
    return {k: validator(k, v) for k, v in options.items()}
  File "/usr/local/lib/python3.5/dist-packages/alive_progress/configuration.py", line 104, in <dictcomp>
    return {k: validator(k, v) for k, v in options.items()}
  File "/usr/local/lib/python3.5/dist-packages/alive_progress/configuration.py", line 96, in validator
    raise ValueError('invalid config value: {}={}'.format(key, repr(value)))
ValueError: invalid config value: bar=<function bouncing_spinner_factory.<locals>.inner_factory at 0x7f397e6d4e18>

and with this code:

def welcome_bootup():
    from alive_progress import bouncing_spinner_factory
    my_message = bouncing_spinner_factory('message1', 15, left_chars='message2', hiding=False)
    with alive_bar(10, bar=my_message) as bar:
        bar()
welcome_bootup()

all is in py3.5!

rsalmei commented 4 years ago

Oh I'm so sorry, I've made a mistake in the command I've sent you. It is not bar=, it is spinner=... Try with this:

def welcome_bootup():
    from alive_progress import alive_bar, bouncing_spinner_factory
    import time
    my_message = bouncing_spinner_factory('message1', 15, left_chars='message2', hiding=False)
    with alive_bar(10, spinner=my_message) as bar:
        bar()
        time.sleep(10)
welcome_bootup()
CRO-THEHACKER commented 4 years ago

Thank you, I have everything almost working but, I'm having some errors with processing some scripts I want to run but they take some time to start up so this is why I am using this.

Here is my code:

def welcome_bootup():
    my_message = bouncing_spinner_factory('Loading...', 20, left_chars='Please wait...', hiding=False)
    with alive_bar(2, spinner=my_message) as bar:
        bar(os.system('bash startserver.sh'))
        bar(os.system('bash wwwserverstat.sh'))
        bar()
        time.sleep(10)

and then I'm getting 2/3 or getting errors.

How should I fix this?

CRO-THEHACKER commented 4 years ago

I keep getting: ✗ (!) 3/2 [150%] in 7.1s (0.42/s)

CRO-THEHACKER commented 4 years ago

New code now:

    my_message = bouncing_spinner_factory('Loading...', 20, left_chars='Please wait...', hiding=False)
    with alive_bar(2, spinner=my_message) as bar:
        bar(os.system('bash startserver.sh'))
        time.sleep(5)
        bar(os.system('bash wwwserverstat.sh'))
        time.sleep(2)
        bar()
CRO-THEHACKER commented 4 years ago

Hmm, looks like I fixed it with this:

def welcome_bootup():
    my_message = bouncing_spinner_factory('Loading...', 20, left_chars='Please wait...', hiding=False)
    with alive_bar(3, spinner=my_message) as bar:
        bar(os.system('bash startserver.sh'))
        time.sleep(5)
        bar(os.system('bash wwwserverstat.sh'))
        time.sleep(2)
        bar()
rsalmei commented 4 years ago

Yes, that's what I was going to say, the first argument to alive_bar is the total, and you were sending 2 but calling bar three times. Nice!

Just a suggestion: be careful you are not handling any errors from those scripts.

CRO-THEHACKER commented 4 years ago

Thanks!

rsalmei commented 4 years ago

You're welcome! 👍