asciimatics
是一个 Python 库,用于在 命令行(终端)界面中创建富视觉效果的图形、动画和用户界面。它的设计目标是让开发者可以在不使用 GUI 框架的情况下,直接通过终端创建复杂的视觉交互程序。
地址: https://github.com/peterbrittain/asciimatics
✨ 功能亮点
终端动画:支持复杂的字符动画、图像转字符动画等。
用户界面(UI):内置表单、按钮、输入框等控件,构建类似 TUI(Text User Interface)的交互界面。
跨平台:兼容 Linux、macOS、Windows 终端(包括 Windows 的 cmd/powershell)。
多种终端支持:兼容 ANSI 终端、Windows 控制台等。
无依赖:纯 Python 编写,无需 curses、ncurses 等底层依赖。
📦 安装方式
pip install asciimatics
🛠️ 示例:显示一段文字动画
from asciimatics.effects import Cycle, Stars
from asciimatics.renderers import FigletText
from asciimatics.scene import Scene
from asciimatics.screen import Screen
def demo(screen):
effects = [
Cycle(
screen,
FigletText("ASCIIMATICS", font='big'),
int(screen.height / 2 - 8)),
Cycle(
screen,
FigletText("ROCKS!", font='big'),
int(screen.height / 2 + 3)),
Stars(screen, 200)
]
screen.play([Scene(effects, 500)])
Screen.wrapper(demo)
运行后,你将在终端看到大字体动画文字。

📋 典型用途
用于制作命令行工具的欢迎界面
构建文本模式的游戏(roguelike)
创建服务器端的监控仪表板
为 CLI 工具添加动态视觉效果
📚 文档与教程