📜  python ansi 颜色 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:24.364000             🧑  作者: Mango

代码示例1
pref = "\033["
reset = f"{pref}0m"

class colors:
    black = "30m"
    red = "31m"
    green = "32m"
    yellow = "33m"
    blue = "34m"
    magenta = "35m"
    cyan = "36m"
    white = "37m"

# Alternative to print, uses white color by default but accepts any color 
# from the Colors class. Name it as you like.
def puts(text, color=colors.white, is_bold=False):
    print(f'{pref}{1 if is_bold else 0};{color}' + text + reset)