主题
pi 可以创建主题。请它为你的环境构建一个。
主题是定义 TUI 颜色的 JSON 文件。
Pi 从以下位置加载主题:
- 内置:
dark、light - 全局:
~/.pi/agent/themes/*.json - 项目:
.pi/themes/*.json(仅在项目被信任后) - 包:
themes/目录或package.json中的pi.themes条目 - 设置:包含文件或目录的
themes数组 - CLI:
--theme <path>(可重复)
使用 --no-themes 禁用发现。
通过 /settings 或在 settings.json 中选择主题:
{ "theme": "my-theme"}首次运行时,pi 会检测终端背景并默认使用 dark 或 light。
创建自定义主题
Section titled “创建自定义主题”- 创建主题文件:
mkdir -p ~/.pi/agent/themesvim ~/.pi/agent/themes/my-theme.json- 定义包含所有必需颜色的主题(参见颜色令牌):
{ "$schema": "https://raw.githubusercontent.com/earendil-works/pi/main/packages/coding-agent/src/modes/interactive/theme/theme-schema.json", "name": "my-theme", "vars": { "primary": "#00aaff", "secondary": 242 }, "colors": { "accent": "primary", "border": "primary", "borderAccent": "#00ffff", "borderMuted": "secondary", "success": "#00ff00", "error": "#ff0000", "warning": "#ffff00", "muted": "secondary", "dim": 240, "text": "", "thinkingText": "secondary", "selectedBg": "#2d2d30", "userMessageBg": "#2d2d30", "userMessageText": "", "customMessageBg": "#2d2d30", "customMessageText": "", "customMessageLabel": "primary", "toolPendingBg": "#1e1e2e", "toolSuccessBg": "#1e2e1e", "toolErrorBg": "#2e1e1e", "toolTitle": "primary", "toolOutput": "", "mdHeading": "#ffaa00", "mdLink": "primary", "mdLinkUrl": "secondary", "mdCode": "#00ffff", "mdCodeBlock": "", "mdCodeBlockBorder": "secondary", "mdQuote": "secondary", "mdQuoteBorder": "secondary", "mdHr": "secondary", "mdListBullet": "#00ffff", "toolDiffAdded": "#00ff00", "toolDiffRemoved": "#ff0000", "toolDiffContext": "secondary", "syntaxComment": "secondary", "syntaxKeyword": "primary", "syntaxFunction": "#00aaff", "syntaxVariable": "#ffaa00", "syntaxString": "#00ff00", "syntaxNumber": "#ff00ff", "syntaxType": "#00aaff", "syntaxOperator": "primary", "syntaxPunctuation": "secondary", "thinkingOff": "secondary", "thinkingMinimal": "primary", "thinkingLow": "#00aaff", "thinkingMedium": "#00ffff", "thinkingHigh": "#ff00ff", "thinkingXhigh": "#ff0000", "bashMode": "#ffaa00" }}- 通过
/settings选择主题。
热重载: 当你编辑当前活动的自定义主题文件时,pi 会自动重新加载,以便立即看到视觉反馈。
{ "$schema": "https://raw.githubusercontent.com/earendil-works/pi/main/packages/coding-agent/src/modes/interactive/theme/theme-schema.json", "name": "my-theme", "vars": { "blue": "#0066cc", "gray": 242 }, "colors": { "accent": "blue", "muted": "gray", "text": "", ... }}name为必填,必须唯一,且不能包含/。vars为可选。在此定义可复用的颜色,然后在colors中引用。colors必须定义全部 51 个必需令牌。
$schema 字段可启用编辑器自动补全和验证。
每个主题必须定义全部 51 个颜色令牌。没有可选颜色。
核心 UI(11 种颜色)
Section titled “核心 UI(11 种颜色)”| 令牌 | 用途 |
|---|---|
accent | 主强调色(logo、选中项、光标) |
border | 普通边框 |
borderAccent | 高亮边框 |
borderMuted | 柔和边框(编辑器) |
success | 成功状态 |
error | 错误状态 |
warning | 警告状态 |
muted | 次要文本 |
dim | 第三级文本 |
text | 默认文本(通常为 "") |
thinkingText | 思考块文本 |
背景与内容(11 种颜色)
Section titled “背景与内容(11 种颜色)”| 令牌 | 用途 |
|---|---|
selectedBg | 选中行背景 |
userMessageBg | 用户消息背景 |
userMessageText | 用户消息文本 |
customMessageBg | 扩展消息背景 |
customMessageText | 扩展消息文本 |
customMessageLabel | 扩展消息标签 |
toolPendingBg | 工具框(待处理) |
toolSuccessBg | 工具框(成功) |
toolErrorBg | 工具框(错误) |
toolTitle | 工具标题 |
toolOutput | 工具输出文本 |
Markdown(10 种颜色)
Section titled “Markdown(10 种颜色)”| 令牌 | 用途 |
|---|---|
mdHeading | 标题 |
mdLink | 链接文本 |
mdLinkUrl | 链接 URL |
mdCode | 行内代码 |
mdCodeBlock | 代码块内容 |
mdCodeBlockBorder | 代码块围栏 |
mdQuote | 引用块文本 |
mdQuoteBorder | 引用块边框 |
mdHr | 水平分隔线 |
mdListBullet | 列表项目符号 |
工具 Diff(3 种颜色)
Section titled “工具 Diff(3 种颜色)”| 令牌 | 用途 |
|---|---|
toolDiffAdded | 新增行 |
toolDiffRemoved | 删除行 |
toolDiffContext | 上下文行 |
语法高亮(9 种颜色)
Section titled “语法高亮(9 种颜色)”| 令牌 | 用途 |
|---|---|
syntaxComment | 注释 |
syntaxKeyword | 关键字 |
syntaxFunction | 函数名 |
syntaxVariable | 变量 |
syntaxString | 字符串 |
syntaxNumber | 数字 |
syntaxType | 类型 |
syntaxOperator | 运算符 |
syntaxPunctuation | 标点 |
思考级别边框(6 种颜色)
Section titled “思考级别边框(6 种颜色)”表示思考级别的编辑器边框颜色(视觉层次从弱到强):
| 令牌 | 用途 |
|---|---|
thinkingOff | 关闭思考 |
thinkingMinimal | 最小思考 |
thinkingLow | 低思考 |
thinkingMedium | 中等思考 |
thinkingHigh | 高思考 |
thinkingXhigh | 超高思考 |
Bash 模式(1 种颜色)
Section titled “Bash 模式(1 种颜色)”| 令牌 | 用途 |
|---|---|
bashMode | Bash 模式下的编辑器边框(! 前缀) |
HTML 导出(可选)
Section titled “HTML 导出(可选)”export 部分控制 /export HTML 输出的颜色。若省略,颜色将从 userMessageBg 派生。
{ "export": { "pageBg": "#18181e", "cardBg": "#1e1e24", "infoBg": "#3c3728" }}支持四种格式:
| 格式 | 示例 | 说明 |
|---|---|---|
| Hex | "#ff0000" | 6 位十六进制 RGB |
| 256 色 | 39 | xterm 256 色调色板索引(0-255) |
| 变量 | "primary" | 引用 vars 条目 |
| 默认 | "" | 终端默认颜色 |
256 色调色板
Section titled “256 色调色板”0-15:基本 ANSI 颜色(取决于终端)16-231:6×6×6 RGB 立方体(16 + 36×R + 6×G + B,其中 R、G、B 为 0-5)232-255:灰度渐变
Pi 使用 24 位 RGB 颜色。大多数现代终端支持此功能(iTerm2、Kitty、WezTerm、Windows Terminal、VS Code)。对于仅支持 256 色的旧终端,pi 会回退到最接近的近似值。
检查 truecolor 支持:
echo $COLORTERM # Should output "truecolor" or "24bit"深色终端: 使用明亮、饱和的颜色,对比度更高。
浅色终端: 使用较暗、柔和的颜色,对比度较低。
色彩和谐: 从基础调色板(Nord、Gruvbox、Tokyo Night)开始,在 vars 中定义,并一致地引用。
测试: 用不同的消息类型、工具状态、markdown 内容和长换行文本检查你的主题。
VS Code: 将 terminal.integrated.minimumContrastRatio 设为 1 以获得准确的颜色。
参见内置主题: