Skip to content

Instantly share code, notes, and snippets.

@trungquy
Created April 20, 2016 04:00
Show Gist options
  • Save trungquy/c1f05db05fd2c6e077b2823f07d6c113 to your computer and use it in GitHub Desktop.
Save trungquy/c1f05db05fd2c6e077b2823f07d6c113 to your computer and use it in GitHub Desktop.
[Python] Color Printing Utility
class color(object):
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
showing = False
@classmethod
def print_bold(self, str):
print self.BOLD + str + self.END
@classmethod
def print_process(self, curr_idx, total, step=5, bold=True):
cnt_precent = (int)((1.0 * (curr_idx) / total) * 100)
if cnt_precent % step == 0:
if not self.showing:
self.showing = True
msg = "Done: " + str(cnt_precent) + '%'
if bold:
self.print_bold(msg)
else:
print msg
else:
self.showing = False
@classmethod
def print_elapsed_time(self, start_time, name='task', bold=False):
msg = "{} took {} (s)".format(name, time.time() - start_time)
if bold:
self.print_bold(msg)
else:
print msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment