终端颜色变得简单!

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..'))

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在表被注释到配置之前获取表的元数据?   java滚动条不会出现在JList上   java JOGL监视器GPU内存   java为什么要使用RecyclerView onDraw延迟   java定制Oppo Reno 2 Z CPH1951(手机型号)的固件(闪存文件)   java自定义线程池执行器   java如何解决发布版本中重复的jar条目[com/安卓/volley/R.class]?   java如何使用Bukkit API触发事件?   java在blazemeter jmeter RTE插件中使用ctrl+w输入   C#/Visual Studio的java JDT等价物   java为什么当maxread值很大而收到的消息数量很小时,卡夫卡消费者会无限期消费?   java游戏2。x:包含模板列表的绑定模型   带压缩的java日志旋转   运行时。exec用java运行程序读取它正在做什么