Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions cprint/cprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class cprint(object):
'WARNING': '\033[93m',
'ERR': '\033[91m',
'FATAL': '\033[31m',
'ENDC': '\033[0m'
'ENDC': '\033[0m',
'BOLD': '\033[1m'
}

def __init__(self, str):
Expand All @@ -37,36 +38,44 @@ def _get_repr(cls, arg):
return repr(arg)

@classmethod
def ok(cls, arg, *args, **kwargs):
def _check_is_bold(cls, bold):
return cprint.colors["BOLD"] if bold else ""

@classmethod
def ok(cls, arg, *args, bold=False, **kwargs):
"""
Prints in blue to stdout
bold=True: Prints in bold.
"""
print(cprint.colors['OK'] + cls._get_repr(arg) + cprint.colors['ENDC'],
print(cprint.colors['OK'] + cls._check_is_bold(bold) + cls._get_repr(arg) + cprint.colors['ENDC'],
file=sys.stdout, *args, **kwargs)

@classmethod
def info(cls, arg, *args, **kwargs):
def info(cls, arg, *args, bold=False, **kwargs):
"""
Prints in green to stdout
bold=True: Prints in bold.
"""
print(cprint.colors['INFO'] + cls._get_repr(arg) + cprint.colors['ENDC'],
print(cprint.colors['INFO'] + cls._check_is_bold(bold) + cls._get_repr(arg) + cprint.colors['ENDC'],
file=sys.stdout, *args, **kwargs)

@classmethod
def warn(cls, arg, *args, **kwargs):
def warn(cls, arg, *args, bold=False, **kwargs):
"""
Prints in yellow to strerr
Prints in yellow to stderr
bold=True: Prints in bold.
"""
print(cprint.colors['WARNING'] + cls._get_repr(arg) + cprint.colors['ENDC'],
print(cprint.colors['WARNING'] + cls._check_is_bold(bold) + cls._get_repr(arg) + cprint.colors['ENDC'],
file=sys.stderr, *args, **kwargs)

@classmethod
def err(cls, arg, interrupt=False, fatal_message="Fatal error: Program stopped.", *args, **kwargs):
def err(cls, arg, interrupt=False, fatal_message="Fatal error: Program stopped.", *args, bold=False, **kwargs):
"""
Prints in brown to stderr
interrupt=True: stops the program
bold=True: Prints in bold. Fatal message will not be bold.
"""
print(cprint.colors['ERR'] + cls._get_repr(arg) + cprint.colors['ENDC'],
print(cprint.colors['ERR'] + cls._check_is_bold(bold) + cls._get_repr(arg) + cprint.colors['ENDC'],
file=sys.stderr, *args, **kwargs)
if interrupt:
print(cprint.colors['ERR'] + fatal_message +
Expand All @@ -75,12 +84,13 @@ def err(cls, arg, interrupt=False, fatal_message="Fatal error: Program stopped."
exit(1)

@classmethod
def fatal(cls, arg, interrupt=False, fatal_message="Fatal error: Program stopped.", *args, **kwargs):
def fatal(cls, arg, interrupt=False, fatal_message="Fatal error: Program stopped.", *args, bold=False, **kwargs):
"""
Prints in red to stderr
interrupt=True: stops the program
bold=True: Makes text bold. Fatal message will not be printed in bold.
"""
print(cprint.colors['FATAL'] + cls._get_repr(arg) + cprint.colors['ENDC'],
print(cprint.colors['FATAL'] + cls._check_is_bold(bold) + cls._get_repr(arg) + cprint.colors['ENDC'],
file=sys.stderr, *args, **kwargs)
if interrupt:
print(cprint.colors['FATAL'] + fatal_message +
Expand Down