Created
April 20, 2016 04:00
-
-
Save trungquy/c1f05db05fd2c6e077b2823f07d6c113 to your computer and use it in GitHub Desktop.
[Python] Color Printing Utility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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