import os
"""
All attributes off 默认值
Bold (or Bright) 粗体 or 高亮
Underline 下划线
Blink 闪烁
Reverse 反显
Black text
Red text
Green text
Yellow text
Blue text
Purple text
Cyan text
White text
Black background
Red background
Green background
Yellow background
Blue background
Purple background
Cyan background
White background
"""
def colored(text, color=None, on_color=None, attrs=None):
fmt_str = '\x1B[;%dm%s\x1B[0m'
if color is not None:
text = fmt_str % (color, text)
if on_color is not None:
text = fmt_str % (on_color, text)
if attrs is not None:
for attr in attrs:
text = fmt_str % (color, text)
return text
def printError(msg):
print colored(msg, color=31)
def printWarning(msg):
print colored(msg, color=33)
def printInfo(msg):
print colored(msg, color=37)
if __name__ == '__main__':
printError("this is an error message!")
printWarning("this is a warning message!")
printInfo("this ia a info message!")
"""
All attributes off 默认值
Bold (or Bright) 粗体 or 高亮
Underline 下划线
Blink 闪烁
Reverse 反显
Black text
Red text
Green text
Yellow text
Blue text
Purple text
Cyan text
White text
Black background
Red background
Green background
Yellow background
Blue background
Purple background
Cyan background
White background
"""
def colored(text, color=None, on_color=None, attrs=None):
fmt_str = '\x1B[;%dm%s\x1B[0m'
if color is not None:
text = fmt_str % (color, text)
if on_color is not None:
text = fmt_str % (on_color, text)
if attrs is not None:
for attr in attrs:
text = fmt_str % (color, text)
return text
def printError(msg):
print colored(msg, color=31)
def printWarning(msg):
print colored(msg, color=33)
def printInfo(msg):
print colored(msg, color=37)
if __name__ == '__main__':
printError("this is an error message!")
printWarning("this is a warning message!")
printInfo("this ia a info message!")