In [ ]:
import os
import time
os.sys.path.append(os.path.dirname(os.path.abspath('./')))
In [ ]:
from halo import HaloNotebook as Halo
This frontend (for example, a static rendering on GitHub or NBViewer) doesn't currently support widgets. If you wonder results, run notebook manually.
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()
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()
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()
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()
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()
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!')