Skip to main content

SWTermColor

封装了 termcolor库,更方便使用了;

同时,也借鉴了 termcolor2库的一些思想;

支持 python2 + python3;

注意:不同的终端软件、不同Shell,的输出效果会有些许的不同。

Install


pip install SWTermColor

Example Modules:

文本颜色,都是以 "c_" 开头的方法;
背景色,都是以 "b_" 开头的方法;
文字特性(加粗等),都是以 "a_" 开头的方法;

from swtermcolor import SWTermColor
from swtermcolor import ColorPrint
from swtermcolor import PrintColor

# 注意:
# SWTermColor == ColorPrint == PrintColor, 三者都是等价的类名,根据喜好选用
SWTermColor("hello, SWTermColor").p()  # p 即 print的缩写
PrintColor("hello, PrintColor").p()
ColorPrint("hello, ColorPrint").p()


# 常用的几种打印方法:
print(SWTermColor("hello, sw red").c_red())
SWTermColor("hello, sw red").c_red().p()  # 先设置文本,再设置效果
SWTermColor().c_red().p("hello, sw red")  # 先设置效果,再设置文本
# 默认以", "为分隔符,打印所有文本
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 "))

截图(ScreenShot)

image1

致谢

待完成的功能

  1. 内置一些彩色打印模板,类似警告、错误等;

Metadata

Release files for SWTermColor 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for SWTermColor 1.1
File Size Uploaded Provenance Actions
SWTermColor-1.1.tar.gz 5.9 kB Without provenance Details for SWTermColor-1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for SWTermColor 1.1
File Interpreter ABI Platform Actions
SWTermColor-1.1-py3-none-any.whl Python 3 none any Details for SWTermColor-1.1-py3-none-any.whl

Total release size: 13.0 kB

Release files / SWTermColor-1.1.tar.gz

Download URL SWTermColor-1.1.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0d4d283d42f9aa57f1f96cc97803b15118ffb3ba9a728375f59d9527126450c1
BLAKE2b-256 checksum
How to use checksums
f6f1b23da7d4c8140bc0757245dd24f9f4312fb9575bdf068388e33e86b6e5e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

Release files / SWTermColor-1.1-py3-none-any.whl

Download URL SWTermColor-1.1-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
072e1bee33a8f7168b0dfa5ee514fa5b527eb630424bc734947d794d2cbc8aef
BLAKE2b-256 checksum
How to use checksums
31e4126c7da27f4fdbeca68af4471273a99edf677b7bc4d4b30dd3f61c9fbda9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

Security for SWTermColor 1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page