echo.py print 输出颜色

Posted on Posted in python
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8

"""usage: import echo; print(echo.red('字符串'))"""
def usage():
    tips='''
    import echo
    print(echo.red(\'字符串\'))'''
    return tips

def colorTemplate(colornum,s):
    return '{}\033[0;{}m {}\033[0m'.format(prefix(),colornum,s)

def colorTemplate5(colornum,s):
    return '{}\033[5;{}m {}\033[0m'.format(prefix(),colornum,s)

def prefix():
    return '\033[0;34m==>\033[0m'

def red(s):
    return colorTemplate(31,s)

def green(s):
    return colorTemplate(32,s)

def yellow(s):
    return colorTemplate(33,s)

def blue(s):
    return colorTemplate(34,s)

def red5(s):
    return colorTemplate5(31,s)

def green5(s):
    return colorTemplate5(32,s)

def yellow5(s):
    return colorTemplate5(33,s)

def blue5(s):
    return colorTemplate5(34,s)

if __name__ == '__main__':
    print(blue(usage()))
    print(red5('等待改造 print ,每次输括号有点烦!'))
» 转载请注明来源:呢喃 » echo.py print 输出颜色

Leave a Reply

Your email address will not be published. Required fields are marked *

eight − 5 =