CLI终端输出彩色的文本, simple termcolor wrapper
Project description
SWTermColor
封装了 termcolor库,更方便使用了;
同时,也借鉴了 termcolor2库的一些思想;
支持 python2 + python3;
Install
pip install SWTermColor
Example Modules:
文本颜色,都是以 "c_" 开头的方法;
背景色,都是以 "b_" 开头的方法;
文字特性(加粗等),都是以 "a_" 开头的方法;
from swtermcolor import SWTermColor
from swtermcolor import ColorPrint
from swtermcolor import PrintColor
# 注意:
# SWTermColor == ColorPrint == PrintColor, 三者都是等价的类名,根据喜好选用
print(PrintColor("hello, PrintColor sw"))
print(ColorPrint("hello, ColorPrint sw"))
print(SWTermColor("hello, SWTermColor sw"))
print(SWTermColor("hello, sw red").c_red())
print(SWTermColor("hello, sw red").c_blue().c_red())
print(SWTermColor().text("hello, sw red replace").c_red())
print(SWTermColor("hello, sw red bg_grey").c_red().b_grey())
print(SWTermColor("hello, sw red bg_blue").c_red().b_blue())
print(SWTermColor("hello, sw red bg_blue").c_red().b_white().b_blue()) # 背景色,蓝色 覆盖了 白色
print(SWTermColor("hello, sw red bg_blue bold").c_red().b_blue().a_bold())
print(SWTermColor("hello, sw red bg_blue bold dark").c_red().b_blue().a_bold().a_dark())
print(SWTermColor("hello, sw red blue bold reverse(反转)").c_red().b_blue().a_bold().a_reverse())
text = "hello, sw red bg_blue bold 文本 与 样式 分离" # 文本
effect = SWTermColor().c_red().b_blue().a_bold() # 特效
print(effect) # 输出空行
print(effect(text)) # 正常使用方法
print(effect(text, "color临时改为grey", color="grey")) # 临时改变文本颜色
print(effect(text, "bg_color临时改为grey", bg_color="grey")) # 临时改变文本背景色
print(effect(text, "attrs临时改为reverse", attrs=["reverse"])) # 临时改变文本效果
print(effect.text("提示文案:")) # 增加 提示文案
print(effect(text, sep=" *#sep#* ")) # 输出:提示文案 + text,以sep做分隔符
effect.text(None) # 删除默认的提示文案
# 输出彩色的:1 + 2 = 3
print(effect(" 1") + effect(" + ", bg_color="cyan") + effect("2") + effect(" = ", bg_color="cyan") + effect("3 "))
截图(ScreenShot)
致谢
- "swtermcolor/termcolor.py"文件,来自于termcolor 1.1.0
- 设计思想借鉴了:termcolor2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
SWTermColor-1.0.tar.gz
(5.5 kB
view hashes)
Built Distribution
Close
Hashes for SWTermColor-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0b55eddfebc2f4c9e240a1de1dcd48ce842295ce695397fe4d221d812a68121 |
|
MD5 | f489afbc47e17cb64d90f32bf2ee4636 |
|
BLAKE2b-256 | 672ac60e42e93157c64c4d1db872facd4e13af512210826b1bfdb7fcbc8ea256 |