代码拉取完成,页面将自动刷新
同步操作将从 shede333/SWTermColor 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
支持在终端打印彩色文案,效果如最下面截图;
封装了 termcolor库,更方便使用了; 同时,也借鉴了 termcolor2库的一些思想;
支持 python2 + python3;
注意:不同的终端软件、不同Shell,的输出效果会有些许的不同。
pip install SWTermColor
文本颜色,都是以 "c_" 开头的方法;
背景色,都是以 "b_" 开头的方法;
文字特性(加粗等),都是以 "a_" 开头的方法;
from swtermcolor import SWTermColor
# 或者
from swtermcolor import ColorPrint
# 或者
from swtermcolor import PrintColor
# 注意:
# SWTermColor == ColorPrint == PrintColor, 三者都是等价的类名,根据喜好选用
SWTermColor().c_red().p("hello, SWTermColor") # p 即 print的缩写
PrintColor().c_red().p("hello, PrintColor")
ColorPrint().c_red().p("hello, ColorPrint")
# 常用的几种打印方法:
SWTermColor("hello, sw red").c_red().p() # 先设置文本,再设置效果
SWTermColor().c_red().p("hello, sw red") # 先设置效果,再设置文本
print(SWTermColor("hello, sw red").c_red()) # 使用print方法打印
# 默认以", "为分隔符,打印所有文本
SWTermColor().c_red().p("hello", "sw", "red")
# 以" * "为分隔符,打印所有文本
SWTermColor().c_red().p("hello", "sw", "red", sep=" * ")
print(SWTermColor("hello, sw red").c_blue().c_red())
print(SWTermColor("hello, sw red bg_grey").c_red().b_grey())
SWTermColor("hello, sw red bg_blue").c_red().b_blue().p()
# 背景色:蓝色 覆盖了 白色,同时会打印一行覆盖警告
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(prefix_text="提示文案前缀:").c_red().b_blue().a_bold() # 特效
print(effect) # 输出空行,因为没有文本信息
effect.p("看打印效果")
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"])) # 临时改变文本效果
# 输出彩色的:1 + 2 = 3
effect._prefix_text = None # 删除 提示文案
print(effect("彩色文本") + " + 普通文本") # 与普通str 相加
print("普通文本 + " + effect("彩色文本")) # 与普通str 相加
print(effect(" 1") + effect(" + ", bg_color="cyan") + effect("2") + effect(" = ", bg_color="cyan") + effect("3 "))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。