In [ ]:
import os
import time

os.sys.path.append(os.path.dirname(os.path.abspath('./')))

HaloNotebook


In [ ]:
from halo import HaloNotebook as Halo

Test example codes

This frontend (for example, a static rendering on GitHub or NBViewer) doesn't currently support widgets. If you wonder results, run notebook manually.

persist_spin.py


In [ ]:
success_message = 'Loading success'
failed_message = 'Loading failed'
unicorn_message = 'Loading unicorn'

spinner = Halo(text=success_message, spinner='dots')

try:
    spinner.start()
    time.sleep(1)
    spinner.succeed()
    spinner.start(failed_message)
    time.sleep(1)
    spinner.fail()
    spinner.start(unicorn_message)
    time.sleep(1)
    spinner.stop_and_persist(symbol='🦄'.encode('utf-8'), text=unicorn_message)
except (KeyboardInterrupt, SystemExit):
    spinner.stop()

long_text.py


In [ ]:
spinner = Halo(text='This is a text that it is too long. In fact, it exceeds the eighty column standard '
                    'terminal width, which forces the text frame renderer to add an ellipse at the end of the '
                    'text. This should definitely make it more than 180!', spinner='dots', animation='marquee')

try:
    spinner.start()
    time.sleep(5)
    spinner.succeed('End!')
except (KeyboardInterrupt, SystemExit):
    spinner.stop()

loader_spin.py


In [ ]:
spinner = Halo(text='Downloading dataset.zip', spinner='dots')

try:
    spinner.start()
    for i in range(100):
        spinner.text = '{}% Downloaded dataset.zip'.format(i)
        time.sleep(0.05)
    spinner.succeed('Downloaded dataset.zip')
except (KeyboardInterrupt, SystemExit):
    spinner.stop()

doge_spin.py


In [ ]:
spinner = Halo(text='Such Spins', spinner='dots')

try:
    spinner.start()
    time.sleep(1)
    spinner.text = 'Much Colors'
    spinner.color = 'magenta'
    time.sleep(1)
    spinner.text = 'Very emojis'
    spinner.spinner = 'hearts'
    time.sleep(1)
    spinner.stop_and_persist(symbol='🦄 '.encode('utf-8'), text='Wow!')
except (KeyboardInterrupt, SystemExit):
    spinner.stop()

custom_spins.py


In [ ]:
spinner = Halo(
    text='Custom Spins',
    spinner={
        'interval': 100,
        'frames': ['-', '+', '*', '+', '-']
    }
)

try:
    spinner.start()
    time.sleep(2)
    spinner.succeed('It works!')
except (KeyboardInterrupt, SystemExit):
    spinner.stop()

context_manager.py


In [ ]:
with Halo(text='Loading', spinner='dots'):
    # Run time consuming work here
    time.sleep(2)

with Halo(text='Loading 2', spinner='dots') as spinner:
    # Run time consuming work here
    time.sleep(2)
    spinner.succeed('Done!')