Skip to main content

A beautiful rich text rendering toolkit for CLI applications

Project description

GLM RichText

🎨 一个美观优雅的命令行文本渲染工具包,灵感来自 kimi-cli

GLM RichText 是一个专为 CLI 应用设计的富文本渲染工具包,提供美观优雅的终端文本输出。

✨ 特性

  • 📝 美观的 Markdown 渲染 - 完整的 Markdown 支持,带语法高亮
  • 🎨 自定义语法主题 - 精心设计的代码高亮配色方案
  • 📐 优雅的布局组件 - 项目符号列表、标签区域、网格布局等
  • 🔍 差异渲染 - 带内联高亮的精美 diff 显示
  • 🖥️ Console 集成 - 开箱即用的控制台助手函数
  • 🎯 简洁的 API - 简单直观的接口设计

📦 安装

一键安装(推荐)

curl -sSL https://raw.githubusercontent.com/user/glm-cli/main/install.sh | bash

其他安装方式

使用 pipx(推荐用于 CLI 工具)

pipx install glm-cli

使用 pip

pip install --user glm-cli

从源码安装

git clone <repo-url>
cd glm-cli
pip install -e .

开发模式安装

# 克隆项目
git clone <repo-url>
cd glm-cli

# 创建虚拟环境
python3 -m venv .venv
source .venv/bin/activate

# 安装依赖
pip install -e .

🚀 快速开始

CLI 命令使用

安装后,可以直接使用 glm-cli 命令:

# 运行演示
glm-cli                    # 快速演示
glm-cli demo               # 同上
glm-cli demo --full        # 完整演示(所有组件)

# 渲染文件
glm-cli markdown README.md # 渲染 Markdown 文件
glm-cli code script.py     # 渲染代码文件(自动检测语言)
glm-cli code main.rs --lang rust  # 指定语言

# 管道使用
cat README.md | glm-render  # 从 stdin 渲染 Markdown

# 查看版本
glm-cli version

Python 库使用

from glm_cli.richtext import console, markdown, code, panel

# 渲染 Markdown
text = """
# Hello, World!

这是 **粗体** 和 *斜体* 文本。

## 代码示例

```python
def greet(name: str) -> str:
    return f"Hello, {name}!"

""" console.print(markdown(text))

渲染代码

console.print(code("print('Hello')", "python"))

渲染面板

console.print(panel("重要内容", title="提示"))


## 📚 文档

详细文档请查看:

- [快速入门指南](docs/getting_started.md) - 新手友好的入门教程
- [API 文档](docs/api.md) - 完整的 API 参考

## 🎭 示例

### 运行演示

```bash
# 完整功能演示
python -m glm_cli.richtext.demo

# 基础示例
python examples/basic_usage.py

代码高亮

from glm_cli.richtext import console, code

python_code = '''
from typing import List

class Processor:
    def process(self, items: List[str]) -> List[str]:
        return [item.upper() for item in items]
'''

console.print(code(python_code, "python"))

表格

from glm_cli.richtext import console, table

headers = ["服务", "状态", "版本"]
rows = [
    ["API", "运行中", "1.0"],
    ["数据库", "运行中", "2.1"],
    ["缓存", "运行中", "3.5"],
]
console.print(table(headers, rows))

状态消息

from glm_cli.richtext import console, status_message

console.print(status_message("操作成功!", "success"))
console.print(status_message("请注意...", "warning"))
console.print(status_message("出错了!", "error"))

🎨 预览

运行演示程序可以看到各种组件的效果:

╔═══════════════════════════════════════════════════════╗
║        🎨 GLM RichText - Beautiful CLI Text          ║
║   A toolkit for elegant terminal text rendering      ║
╚═══════════════════════════════════════════════════════╝

📁 项目结构

glm-cli/
├── glm_cli/
│   └── richtext/          # 核心工具包
│       ├── __init__.py    # 主入口
│       ├── console.py     # Console 配置
│       ├── themes.py      # 颜色主题
│       ├── formats.py     # 格式化组件
│       ├── markdown.py    # Markdown 渲染器
│       ├── custom.py      # 自定义布局
│       └── demo.py        # 演示程序
├── examples/              # 示例代码
├── tests/                 # 测试文件
├── docs/                  # 文档
└── pyproject.toml         # 项目配置

🧪 测试

# 运行测试
pytest tests/

# 带覆盖率
pytest tests/ --cov=glm_cli/richtext

🔧 故障排除

命令未找到

如果安装后 glm-cli 命令未找到,可能需要将用户 bin 目录添加到 PATH:

# 查看用户 bin 目录
python3 -m site --user-base

# 添加到 PATH(将输出路径的 /bin 子目录添加)
# 例如:export PATH="$HOME/.local/bin:$PATH"

# 添加到 shell 配置文件(~/.bashrc 或 ~/.zshrc)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Python 版本要求

需要 Python 3.10 或更高版本。检查版本:

python3 --version

升级到最新版本

# 使用 pipx
pipx upgrade glm-cli

# 使用 pip
pip install --upgrade glm-cli

🤝 贡献

欢迎提交 Pull Request 或创建 Issue!

📄 许可证

MIT License - 详见 LICENSE 文件

🙏 致谢

本项目灵感来自 kimi-cli 的 rich text 渲染实现。


Made with ❤️ for beautiful CLI applications

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

glm_code-0.1.0.tar.gz (43.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glm_code-0.1.0-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file glm_code-0.1.0.tar.gz.

File metadata

  • Download URL: glm_code-0.1.0.tar.gz
  • Upload date:
  • Size: 43.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for glm_code-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2270a30f1e305c946c48fd45ec533efcf45586d22e596f3172eb8f4c18848f08
MD5 2e5912e15bf55e47c1bf7ebef3504d2d
BLAKE2b-256 00e46d6e9a4b6ce0421509c5e66aec99b4e8fe3bcaa47e62464f8fc6dda7a309

See more details on using hashes here.

File details

Details for the file glm_code-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: glm_code-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for glm_code-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71ba5c92adfb096b7c11ab9a02297aa07cea7ad3871e51bee11bb67083a4deee
MD5 7a7edad07be33cbe6084631d8ca7c670
BLAKE2b-256 f42fbd2f932b8441a3c6f37cb71d40261e69f255d895f6b00d1c36395f20cfa7

See more details on using hashes here.

Supported by

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