Skip to content

Instantly share code, notes, and snippets.

@gibatronic
Created October 1, 2015 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gibatronic/da54458fb99315688a3d to your computer and use it in GitHub Desktop.
Save gibatronic/da54458fb99315688a3d to your computer and use it in GitHub Desktop.
nice shell spinner
#!/usr/bin/env python
# coding: utf-8
import sys
import time
cursor = '\033[1D'
frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
amount = len(frames)
hide = '\033[?25l'
index = 0
show = '\033[?25h'
sys.stdout.write(hide)
while True:
try:
frame = frames[index % amount]
index += 1
sys.stdout.write('%s' % frame)
sys.stdout.flush()
time.sleep(0.1)
sys.stdout.write('%s' % cursor)
except KeyboardInterrupt:
sys.stdout.write(show)
sys.exit(0)
except SystemExit:
sys.stdout.write(show)
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment