chroma-term-console
轻量级
Python ANSI终端色彩库,支持4/8/256色、24位真RGB色彩与文本样式,用于控制台文本美化。
安装
pip install chroma-term-console
快速开始
Chroma 类(推荐)
最直观的方式,直接 Chroma.颜色名('文本') 即可看到彩色输出:
from chroma_term_console import Chroma
# 前景色
print(Chroma.red('错误'))
print(Chroma.green('成功'))
print(Chroma.yellow('警告'))
print(Chroma.blue('信息'))
print(Chroma.magenta('紫红色'))
print(Chroma.cyan('青蓝色'))
# 高亮前景色
print(Chroma.bright_red('高亮红'))
print(Chroma.bright_green('高亮绿'))
# 背景色
print(Chroma.bg_red('红色背景'))
print(Chroma.bg_green('绿色背景'))
print(Chroma.bg_yellow('黄色背景'))
# 显示方式
print(Chroma.bold('粗体'))
print(Chroma.underline('下划线'))
print(Chroma.blink('闪烁'))
print(Chroma.reverse('反显'))
# 组合样式
print(Chroma.bold_red('高亮红色'))
print(Chroma.bold_green('高亮绿色'))
print(Chroma.underline_cyan('下划线青蓝'))
# 256 色
print(Chroma.c256('橙色', fg=208))
print(Chroma.c256('粉色', fg=213))
# 24 位真彩 RGB
print(Chroma.rgb('自定义粉', fg=(255, 121, 198)))
print(Chroma.rgb('暗底亮字', fg=(255, 255, 255), bg=(40, 42, 54)))
快捷函数
from chroma_term_console import fg, bg, style, bold, underline, italic
# 前景色 / 背景色
print(fg('red', '红色文字'))
print(bg('blue', '蓝色背景'))
# 文本样式
print(bold('粗体'))
print(underline('下划线'))
print(italic('斜体'))
# 多样式组合
print(style('重要通知', fg='yellow', bold=True, underline=True))
color 函数(原始 ANSI 码封装)
直接对应 \033[显示方式;前景色;背景色m***\033[0m 语法:
from chroma_term_console import color, color256, color_rgb
# 基本 4/8 色
print(color('红色文字', fg=31))
print(color('高亮绿色', fg=32, mode=1))
print(color('红字黄底', fg=31, bg=43))
print(color('高亮蓝字白底', fg=34, bg=47, mode=1))
# 256 色
print(color256('橙色', fg=208))
# 24 位真彩 RGB
print(color_rgb('粉色', fg=(255, 121, 198)))
链式调用(Chroma 语法糖)
Chroma.样式名('文本') 返回 ChromaText 对象,可直接链式叠加任意颜色与样式,无需嵌套:
from chroma_term_console import Chroma
# 样式 + 颜色
print(Chroma.bold('粗体').red()) # 粗体 + 红色
print(Chroma.underline('下划线').bg_blue()) # 下划线 + 蓝色背景
# 多重叠加
print(Chroma.bold('警告').red().blink()) # 粗体 + 红色 + 闪烁
print(Chroma.italic('提示').cyan().dim()) # 斜体 + 青色 + 暗色
# 链式 + 256 色 / RGB
print(Chroma.bold('橙色').c256(fg=208))
print(Chroma.underline('自定义').rgb(fg=(255, 128, 0)))
# 兼容 print / f-string / 字符串拼接
msg = Chroma.bold('错误').red()
print(f"结果: {msg}")
print("前缀 " + msg + " 后缀")
# 获取原始文本
print(Chroma.bold('hello').red().text) # 'hello'
ChromaText实现了__str__/__format__/__repr__,可直接用于print()、f-string 和字符串拼接,无需手动转换。
自动输出:当表达式结果未被赋值时,ChromaText 对象在语句结束后自动打印到终端,无需 print():
# 无需 print(),直接自动输出
Chroma.bold('粗体').red()
Chroma.italic('提示').cyan().dim()
# 赋值给变量则不自动输出,需手动 print()
msg = Chroma.bold('粗体').red()
print(msg)
链式调用(Styled 类)
from chroma_term_console import Styled
s = Styled()
print(s.fg('green').bold('成功'))
print(s.fg('#ff79c6').bg('#282a36').italic('Dracula 主题'))
print(s.fg(196).bold('256色红'))
print(s.fg((255, 128, 0)).underline('RGB 橙色'))
API 参考
Chroma 类方法
| 方法 | 效果 |
|---|---|
Chroma.black/red/green/yellow/blue/magenta/cyan/white |
基本 8 色前景 |
Chroma.bright_red/... |
高亮 8 色前景 |
Chroma.bg_red/... |
背景色 |
Chroma.bold/underline/blink/reverse/hidden |
显示方式(返回 ChromaText,可链式调用) |
Chroma.bold_red/... |
高亮 + 颜色组合 |
Chroma.underline_red/... |
下划线 + 颜色组合 |
Chroma.c256(text, fg=N, bg=N) |
256 色 |
Chroma.rgb(text, fg=(R,G,B), bg=(R,G,B)) |
24 位真彩 |
颜色码对照表
| 前景色 | 背景色 | 颜色 |
|---|---|---|
| 30 | 40 | 黑色 |
| 31 | 41 | 红色 |
| 32 | 42 | 绿色 |
| 33 | 43 | 黄色 |
| 34 | 44 | 蓝色 |
| 35 | 45 | 紫红色 |
| 36 | 46 | 青蓝色 |
| 37 | 47 | 白色 |
| 90-97 | 100-107 | 高亮色 |
显示方式码
| 码 | 效果 |
|---|---|
| 0 | 默认值 |
| 1 | 高亮/粗体 |
| 4 | 下划线 |
| 5 | 闪烁 |
| 7 | 反显 |
| 8 | 不可见 |
工具函数
from chroma_term_console import strip_ansi, supports_color, detect_color_level
# 移除 ANSI 转义序列
plain = strip_ansi('\033[31m红色\033[0m') # '红色'
# 检测终端色彩支持
level = detect_color_level() # ColorLevel.NONE / BASIC / EXTENDED / TRUECOLOR
has_color = supports_color() # True / False
终端兼容性
- 自动检测终端色彩能力(真彩 / 256色 / 基本色)
- 支持
NO_COLOR协议(设置NO_COLOR环境变量禁用颜色) - 支持
FORCE_COLOR环境变量强制启用 - Windows 10+ / Windows Terminal / ConEmu / ANSICON 自动启用 VT 处理
- VS Code / PyCharm 集成终端及运行控制台均支持颜色输出
- 非 TTY 环境(管道/重定向)自动禁用颜色
Metadata
Release files for chroma-term-console 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 13.6 MB
Release files / chroma_term_console-0.1.4-cp314-cp314-win_amd64.whl
| Download URL | chroma_term_console-0.1.4-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 232.9 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
8992af32489ab5d168711fe3941758ac87b55c5b211e6ea33449035082ac88e3
|
|
BLAKE2b-256 checksum How to use checksums |
208c45d2ebd9f4ce979231e495226a15a4b1ab57591d44fe6fec4c398dd2f658
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp314-cp314-manylinux_2_17_x86_64.whl
| Download URL | chroma_term_console-0.1.4-cp314-cp314-manylinux_2_17_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.14 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
4141671d62276227a1f1d7a9fa4a4ae309ebcac87052cb9917d47e465e3103c6
|
|
BLAKE2b-256 checksum How to use checksums |
617f5c658088b7a9b839284c7161f491748cfb568d9dc9143e7886c5bd7ea25d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp313-cp313-win_amd64.whl
| Download URL | chroma_term_console-0.1.4-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 226.1 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
c8ed90ba9ab4ac9704450bb0c596f12d9ffcd574f712a79a3ff8a6c19e85767c
|
|
BLAKE2b-256 checksum How to use checksums |
882af200d0f55591b32a4e70ca49d0d26ea76365d9e69612fe56825d3e218ef6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp313-cp313-manylinux_2_17_x86_64.whl
| Download URL | chroma_term_console-0.1.4-cp313-cp313-manylinux_2_17_x86_64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
62b596aa5b6c2ff32de1a23ccffd497aa05d2943fa0c86810c93eed8ff1e22f8
|
|
BLAKE2b-256 checksum How to use checksums |
3e379675ff4ea7e7e1898e8c595467433a54fc257398e337af562783a21b6d83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp312-cp312-win_amd64.whl
| Download URL | chroma_term_console-0.1.4-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 229.2 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
66bac9f9ce337a5f5d7d78cb9e55965030b8902f07c8d67909849adb6cc93ae4
|
|
BLAKE2b-256 checksum How to use checksums |
7f547e10b52b6b1d67adb1bf5abcf37fe5a76d2deef6156b800afb307cec1dde
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp312-cp312-manylinux_2_17_x86_64.whl
| Download URL | chroma_term_console-0.1.4-cp312-cp312-manylinux_2_17_x86_64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
184666a8dece64d0b9b14a2f0e032983962ba00d285157d1b0d0c99dddd1756f
|
|
BLAKE2b-256 checksum How to use checksums |
9c8db84bd74c9c338fadcc7300f70a64d2a7ddc208e1cfb05c9b3d2a6e62eb74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp311-cp311-win_amd64.whl
| Download URL | chroma_term_console-0.1.4-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 239.2 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
ffb031373e1943524f24e550b75328d62ae706b865e2d99aca238cf162c2d72d
|
|
BLAKE2b-256 checksum How to use checksums |
5423d183331bd4989746f508168097264b3ce57c40627180b075878ca20d453b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp311-cp311-manylinux_2_17_x86_64.whl
| Download URL | chroma_term_console-0.1.4-cp311-cp311-manylinux_2_17_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
48fdcc2a091f852a5a1643cafa9afb1cf70d28d5da2ac1ca35639441e2242e67
|
|
BLAKE2b-256 checksum How to use checksums |
af7c5291ab924c74e755bb52c0f3cfa6dacb595ff035cda6ae4d2acca056351a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp310-cp310-win_amd64.whl
| Download URL | chroma_term_console-0.1.4-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 238.3 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
354eceb64f3cf52464e60edee9a07fd09d71742118769fa3d5b34a32ac694021
|
|
BLAKE2b-256 checksum How to use checksums |
e28194184e16b3a4da6a9e29863996f3927228cc4ea1040b8c79e2dbb57c4631
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp310-cp310-manylinux_2_17_x86_64.whl
| Download URL | chroma_term_console-0.1.4-cp310-cp310-manylinux_2_17_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
24ccfcd05a76035220b127dca19204ee5f91e6b78863cfa5a03d12dc8aadf303
|
|
BLAKE2b-256 checksum How to use checksums |
46bb174725ad330dd30f86fd37a7e2a6518dc0abebe95eeda6a3bf37e74fe476
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp39-cp39-win_amd64.whl
| Download URL | chroma_term_console-0.1.4-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 239.0 kB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
8a17f66e3d2ffb071ce7e96cbc83ed16d9f7c3209a132e9770b21b5bd30b0f51
|
|
BLAKE2b-256 checksum How to use checksums |
423433fc521a22aeadef57589eb7f8fcaa08908b703c9af99ec4f3761bc2fd65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp39-cp39-manylinux_2_17_x86_64.whl
| Download URL | chroma_term_console-0.1.4-cp39-cp39-manylinux_2_17_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
040e04fac47083d69cab22af8595bf9387419345e13ac5cff3737878664fc2bd
|
|
BLAKE2b-256 checksum How to use checksums |
c946f69274a8506637023df9515b30e2ada3e877bf1fc44e3364c8ca3e6d43ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp38-cp38-win_amd64.whl
| Download URL | chroma_term_console-0.1.4-cp38-cp38-win_amd64.whl |
|---|---|
| Size | 245.1 kB |
| Tags | CPython 3.8 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6ceedb04e7beed1525e7f603ffdecaf45c9ed98ee8b93d4f9f184f93b80cd58e
|
|
BLAKE2b-256 checksum How to use checksums |
44fe3f658d80d44bfdde8b7c0918166226634015dfdae8ba399b362f553242e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / chroma_term_console-0.1.4-cp38-cp38-manylinux_2_17_x86_64.whl
| Download URL | chroma_term_console-0.1.4-cp38-cp38-manylinux_2_17_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
c5e672b95d963daf312fd2458ee9034669d4e614f69abcd95e434423d1ccb235
|
|
BLAKE2b-256 checksum How to use checksums |
f4720a5f1e600740d3e19cefa74d46e5f5d4ab7cdb57df41318d756a93863aee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logSecurity for chroma-term-console 0.1.4
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.
Full provenance
All 14 files in this release have been uploaded with provenance metadata.
Attestation for chroma_term_console-0.1.4-cp314-cp314-win_amd64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logA 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.