Skip to main content

Colorful Print 彩色文本格式化, 彩色文本输出, 控制打印字符颜色样式!

Project description

Colorful Print

彩色文本格式化, 彩色文本输出, 控制打印字符颜色样式!

main

安装

pip install -U cprint-jianjun

简介

让你的终端输出各式各样的彩色文本, 以一种非常简便的方式嵌入到程序中!

# default
print("{0}  {1}".format("Hello", "World!"))

# cformat
import cprint
print("@56056{0}@45031{1}".cformat("Hello ", " World!"))

# iformat
import cprint
cprint.custom_style = {1: 612, 2: 1224}
print("@1{0}@2{1}".iformat("Hello ", " World!"))

# [] format
print("@56056{0}@45031[ World!]".cformat("Hello "))

use

只需要在 {} 前加上@样式id, 然后把 format 改为 cformat 就可以按照样式id输出彩色文本

查看颜色样式ID

命令行输入 cpshow 查看所有的样式id

颜色样式ID为 @ 后面的数字, 现在一共有 70943 个不同的样式可以选择, 不同的终端效果不一样, 有些终端可能不支持, 请自行测试.

style

其他命令行

  • cpdemo : Hello World! 样例
  • cpdemoid : Hello World! 样例并显示样式ID

可以多次调用 cpdemoid 查看样式配色, 选择喜欢的ID.

iformat

可以通过赋值 cprint.custom_style 来自定义配置自己的id映射表, 这样可以提前配置几套不同的 id theme id主题, 然后可以根据喜好或者根据不同的终端配色切换主题配色

# iformat
import cprint

# theme 1
cprint.custom_style = {1: 612, 2: 1224}
print("@1{0}@2{1}".iformat("Hello ", " World!"))

# theme 2
cprint.custom_style = {1: 5547, 2: 66795}
print("@1{0}@2{1}".iformat("Hello ", " World!"))

也可以提前把配色序列写入 .py 文件中, 然后在程序启动的时候导入赋值就行.

固定常量

在字符串中使用 @NOW, @DATE, @TIME 可以获取到对应的时间字符串

print(" NOW: @NOW ".cformat())
print("DATE: @DATE ".cformat())
print("TIME: @TIME ".cformat())
 NOW: 2023-02-23 10:23:35
DATE: 2023-02-23
TIME: 10:23:35

实现方式

How to Print Colored Text in Python

how how

除了输出颜色字符外, 这种方式还可以控制光标移动、清屏、控制终端更改背景颜色等操作.

更新记录

最新版本: cprint-jianjun v1.3.0

  • 20221116: 1.更新新的常量 @NOW, @DATE, @TIME 的功能 2.更新文档
  • 20230223: 1.更新文档 2.增加 cpdemoid 命令行.
  • 20230303: 1.更新 iformat 函数.
  • 20230315: 1.更新 [] 功能.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cprint_jianjun-1.6.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

cprint_jianjun-1.6.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file cprint_jianjun-1.6.0.tar.gz.

File metadata

  • Download URL: cprint_jianjun-1.6.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for cprint_jianjun-1.6.0.tar.gz
Algorithm Hash digest
SHA256 0f8fd9a0800ec36f5cf9d3e83391caae95718fae92b8610b0219424ee6912f28
MD5 1ab6bd3a4fdb14d0346c3c7f1b5a8262
BLAKE2b-256 97c7a109dde22563314fa751ca3ed6163d0873179432a539f0b08dd871d47295

See more details on using hashes here.

File details

Details for the file cprint_jianjun-1.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cprint_jianjun-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1506bb23e5f4acd30c6bd8390bb4fd8aa06726c5a565aee56845a0db25439a6a
MD5 c5086af0e9d1addca82d90210ed3ab8d
BLAKE2b-256 f3681455fa44262b46f1699ffbb87e1ccdef5a6f38d3d4af184875f40dd6c020

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page