一个轻量级纯python库,用于将颜色和html文本样式应用于字符串

ezcolor的Python项目详细描述


https://api.codacy.com/project/badge/Grade/5384da344156447daa23f588fc8fbae6

python着色字符串库

用于将颜色和HTML文本样式应用于字符串的轻量级库 使用生成器模式进行配置的。EZCOLOR让你拥有美好的 带有额外HTML文本样式(如粗体/斜体/下划线)的彩色输出。 与bash/sh/zsh兼容。

功能

  • 一个简单易用的api
  • 轻量级,使用纯python编写
  • 在Python3.6+上测试(与python2.x不兼容)
  • 与Windows操作系统不兼容(命令提示符、powershell)

用法

$ pip install ezcolor
fromezcolorimportStylestyle=Style()cp=style.add.foreground('green').apply()cp('hello world')
https://github.com/0x0ptim0us/images/raw/master/ezcolor_simple_output.png

添加更多属性

cp=style.add.foreground('green').background('dark_gray').bold.italic.underline.apply()cp('hello world')
https://github.com/0x0ptim0us/images/raw/master/ezcolor_more_attribute.png

为漂亮的日志添加前缀

cp=style.add.foreground('green').prefix('done').bold.italic.apply()cp('Job is done!')cp_error=style.add.foreground('red').prefix('error').bold.italic.apply()cp_error('Error occurred!')
https://github.com/0x0ptim0us/images/raw/master/ezcolor_prefix_done.pnghttps://github.com/0x0ptim0us/images/raw/master/ezcolor_prefix_error.png

用作装饰器

@cp.decoratedefmy_name(name,lastname):returnf"my name is {name} {lastname}"print(my_name('Fardin','Allahverdinazhand'))
Supported colors and prefix (log level)
Colorprefix
blackdone
redinfo
greenwarning
yellowerror
blue
magenta
cyan
light_gray
dark_gray
light_red
light_green
light_yellow
light_blue
light_magenta
light_cyan
white

法尔丁·阿拉维尔迪纳扎德-@0x0ptim0us-0x0ptim0us@gmail.com 根据麻省理工学院的许可证发行。有关详细信息,请参见LICENSE.txt

https://github.com/0x0ptim0us/ezcolor

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

推荐PyPI第三方库


热门话题
java Spring引导,通过POST从InputStream上载文件期间RestTemplate异常   Java小程序在小程序查看器中运行,但不在浏览器中运行   swing如何追踪Java中看似随机的崩溃?   带线程池的多线程Java阶乘计算   java EWS:FindItem请求异常中不支持的限制   java Android studio ListView默认项   Java的字符串。split()删除尾随的空条目   java如何在j2EE应用程序中通过JMS和Websphere MQ发送和接收xml文件   facebook图形api Solrjava错误:class com。restfb。类型。Post声明多个名为type的JSON字段   java Oracle数据库:使用字符(X)或数字(X)代替日期   java如何在saxon中使用DirectoryCollection   oracle我可以脱机“查看”Java标准库吗   java的增量if循环函数在主函数的增量循环中   oracle数字类型的数据库java映射   java读取一个文本文件并写入多个文本文件以进行过滤/提取   java ImageJ无法获取CurrentImage