极简终端 UI 框架,差量渲染 + 同步输出,无闪烁交互式 CLI 应用。
特性
- 差量渲染:三策略渲染系统,只更新变化部分
- 同步输出:使用 CSI 2026 原子化屏幕更新(无闪烁)
- 括号粘贴模式:>10 行粘贴时使用 marker 正确处理
- 组件化:简单的
Component接口(render()方法) - 主题支持:组件接受 theme 接口定制样式
- 内联图片:支持 Kitty 和 iTerm2 图形协议
内置组件
Text、TruncatedText、Input、Editor、Markdown、Loader、SelectList、SettingsList、Spacer、Image、Box、Container
快速开始
import { TUI, Text, Editor, ProcessTerminal, matchesKey } from "@earendil-works/pi-tui";
const terminal = new ProcessTerminal();
const tui = new TUI(terminal);
tui.addChild(new Text("Welcome!"));
const editor = new Editor(tui, editorTheme);
editor.onSubmit = (text) => {
tui.addChild(new Text(`You said: ${text}`));
};
tui.addChild(editor);
tui.setFocus(editor);
// raw mode 下 Ctrl+C 不发 SIGINT,需手动拦截
tui.addInputListener((data) => {
if (matchesKey(data, 'ctrl+c')) {
tui.stop();
process.exit(0);
}
});
tui.start();与 pi-coding-agent 的关系
pi-tui 是独立包,与 Agent 层解耦。pi-coding-agent 在内部使用 pi-tui 构建交互界面,extensions 也可直接调用 pi-tui API 添加自定义 UI 组件。