Skip to content

Instantly share code, notes, and snippets.

@AaronGhent
Created August 23, 2012 00:00
Show Gist options
  • Save AaronGhent/3430730 to your computer and use it in GitHub Desktop.
Save AaronGhent/3430730 to your computer and use it in GitHub Desktop.
Spinner
#! /usr/bin/env python
# >><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><< #
# Spinner - command line spinning for times of patience
# Author: Aaron Ghent
# >><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><< #
import sys
class Spinner(object):
symbols = list('-\|/')
nsym = len(symbols)
n = 0
def __init__(self, message=''):
"The message is the description of what is being done."
self.message = message
def spin(self):
"Each call to spin() makes the ascii spin."
print '\r', self.message + self.symbols[self.n],
sys.stdout.flush()
self.n = (self.n + 1) % self.nsym
def stop(self, message=''):
"Erase the spin and display message (eg: Done.)"
print '\r', self.message + message
def set_message(self, message):
self.message = message
class DetailedSpinner(Spinner):
def set_message(self, message):
super(DetailedSpinner, self).set_message(message + ' ... ')
self.spin()
def stop(self, message='Done'):
super(DetailedSpinner, self).stop(message)
# >><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><< #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment