<gh_stars>1-10
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: huizhi.yang
# Time: 2022/5/21 10:19

"""
    颜色处理
"""


class color(object):
    # 显示格式: \033[显示方式;前景色;背景色m
    # 只写一个字段表示前景色,背景色默认
    RED = '\033[31m'      # 红色
    GREEN = '\033[32m'    # 绿色
    YELLOW = '\033[33m'   # 黄色
    BLUE = '\033[34m'     # 蓝色
    FUCHSIA = '\033[35m'  # 紫红色
    CYAN = '\033[36m'     # 青蓝色
    WHITE = '\033[37m'    # 白色
    RESET = '\033[0m'     # 终端默认颜色
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'
    HEADER = '\033[95m'
    OKBLUE = '\033[94M'
    OKGREEN = '\033[93m'
    WARNING = '\033[92m'
    FAIL = '\033[91m'
    FAIL2 = '\033[90m'

    def _color_transition(self, color, s):
        return '{}{}{}'.format(getattr(self, color), s, self.RESET)

    def red(self, s):
        return self._color_transition('RED', s)

    def okgreen(self, s):
        return self._color_transition('OKGREEN', s)

    def fail(self, s):
        return self._color_transition('FAIL', s)

    def green(self, s):
        return self._color_transition('GREEN', s)

    def yellow(self, s):
        return self._color_transition('YELLOW', s)

    def blue(self, s):
        return self._color_transition('BLUE', s)

    def fuchsia(self, s):
        return self._color_transition('FUCHSIA', s)

    def cyan(self, s):
        return self._color_transition('CYAN', s)

    def white(self, s):
        return self._color_transition('WHITE', s)

    # ----------使用示例如下:-------------


if __name__ == '__main__':
    color = color()
    print(color.red('I am red!'))
    print(color.okgreen('I am okgreen!'))
    print(color.fail('I am fail!'))
    print(color.green('I am green!'))
    print(color.yellow('I am yellow!'))
    print(color.blue('I am blue!'))
    print(color.fuchsia('I am fuchsia!'))
    print(color.cyan('I am cyan!'))
    print(color.white('I am white'))

    print(color.HEADER + '警告的颜色字体？')
    print(color.OKBLUE + '警告的颜色字体？？')
    print(color.WARNING + '警告的颜色字体？？？')
    print(color.FAIL2 + '警告的颜色字体？？？？？')
    print(color.BOLD + '警告的颜色字体？？')
    print(color.UNDERLINE + '警告的颜色字体？')

# !/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: huizhi.yang
# Time: 2022/5/21 10:19

"""
    颜色处理
"""


class color(object):
    # 显示格式: \033[显示方式;前景色;背景色m
    # 只写一个字段表示前景色,背景色默认
    RED = '\033[31m'      # 红色
    GREEN = '\033[32m'    # 绿色
    YELLOW = '\033[33m'   # 黄色
    BLUE = '\033[34m'     # 蓝色
    FUCHSIA = '\033[35m'  # 紫红色
    CYAN = '\033[36m'     # 青蓝色
    WHITE = '\033[37m'    # 白色
    RESET = '\033[0m'     # 终端默认颜色
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'
    HEADER = '\033[95m'
    OKBLUE = '\033[94M'
    OKGREEN = '\033[93m'
    WARNING = '\033[92m'
    FAIL = '\033[91m'
    FAIL2 = '\033[90m'

    def _color_transition(self, color, s):
        return '{}{}{}'.format(getattr(self, color), s, self.RESET)

    def red(self, s):
        return self._color_transition('RED', s)

    def okgreen(self, s):
        return self._color_transition('OKGREEN', s)

    def fail(self, s):
        return self._color_transition('FAIL', s)

    def green(self, s):
        return self._color_transition('GREEN', s)

    def yellow(self, s):
        return self._color_transition('YELLOW', s)

    def blue(self, s):
        return self._color_transition('BLUE', s)

    def fuchsia(self, s):
        return self._color_transition('FUCHSIA', s)

    def cyan(self, s):
        return self._color_transition('CYAN', s)

    def white(self, s):
        return self._color_transition('WHITE', s)

    # ----------使用示例如下:-------------


if __name__ == '__main__':
    color = color()
    print(color.red('I am red!'))
    print(color.okgreen('I am okgreen!'))
    print(color.fail('I am fail!'))
    print(color.green('I am green!'))
    print(color.yellow('I am yellow!'))
    print(color.blue('I am blue!'))
    print(color.fuchsia('I am fuchsia!'))
    print(color.cyan('I am cyan!'))
    print(color.white('I am white'))

    print(color.HEADER + '警告的颜色字体？')
    print(color.OKBLUE + '警告的颜色字体？？')
    print(color.WARNING + '警告的颜色字体？？？')
    print(color.FAIL2 + '警告的颜色字体？？？？？')
    print(color.BOLD + '警告的颜色字体？？')
    print(color.UNDERLINE + '警告的颜色字体？')
# !/usr/bin/env python # -*- coding: utf-8 -*- # Author: huizhi.yang # Time: 2022/5/21 10:19 颜色处理 # 显示格式: \033[显示方式;前景色;背景色m # 只写一个字段表示前景色,背景色默认 # 红色 # 绿色 # 黄色 # 蓝色 # 紫红色 # 青蓝色 # 白色 # 终端默认颜色 # ----------使用示例如下:-------------