终端颜色变得简单!
easycolor的Python项目详细描述
python简单颜色
python2/3的颜色输出很简单!
说明
在unix终端中简化python颜色输出 支持ANSI序列的。
安装
pip install easycolor
源代码
在github检查:(https://github.com/GeorgeTG/easycolor)
许可证
George T.Gougoudis 2016版权所有。BSD 3条款许可证;见许可证文件。
基本用法
若要换行文本,必须导入换行函数。
fromeasycolor.styleimportwrapas_w
然后,文本将像
# wrap text, appends a style-resetprint(_w('yellow on red',fg='yellow',bg='red'))print('normal text')
要编译样式,请使用make_style函数:
fromeasycolor.styleimportmake_style,RESET
示例:
# define some stylesblack_on_white=make_style(fg='black',bg='white')# we have to reset the background herered_bold=make_style(fg='red',bg='reset',opt='bold')# An options reset is only possible with a total reset# we can however negate an option to remove it('!option').green_bold_underline=make_style(fg='green',opt=('!bold','underline'))print(black_on_white+'Black on white'+red_bold+'Red bold'+green_bold_underline+'Green not bold underline'+RESET)
注意:对于高级格式,请使用easycolor.parser模块。
高级用法
首先获取实例
fromeasycolor.parserimportColorParserparser=ColorParser()
然后用于打印
cprint=parser.cprint# Add rainbow colors!cprint("""<f:red>r<f:yellow>ai<f:green>nb<f:blue>o<f:magenta>w""""""</f>o</f>bn</f>ia</f>r</f>""")# complex foreground - backgroundcprint("""<f:red,b:yellow>red on yellow</b>just red<b:black>red on black!""""""<f:green>green on black</f>again red on black</f,b>normal""")
分析彩色记录器的格式字符串,供以后使用
INFO=parser.parse("[<f:cyan>INFO</f>] <o:bold>{}")print(INFO.format('Some info..'))