/** * 启动界面中文翻译扩展 * * 将 pi 的初始启动界面中的介绍和引导文字翻译为中文, * 快捷键和命令提示保持原样。 */ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; import { keyHint, keyText, rawKeyHint, VERSION } from "@mariozechner/pi-coding-agent"; export default function (pi: ExtensionAPI) { pi.on("session_start", async (_event, ctx) => { if (!ctx.hasUI) return; ctx.ui.setHeader((_tui, theme) => { const expandedInstructions = [ keyHint("app.interrupt", "to interrupt"), keyHint("app.clear", "to clear"), rawKeyHint(`${keyText("app.clear")} twice`, "to exit"), keyHint("app.exit", "to exit (empty)"), keyHint("app.suspend", "to suspend"), keyHint("tui.editor.deleteToLineEnd" as any, "to delete to end"), keyHint("app.thinking.cycle", "to cycle thinking level"), rawKeyHint( `${keyText("app.model.cycleForward")}/${keyText("app.model.cycleBackward")}`, "to cycle models", ), keyHint("app.model.select", "to select model"), keyHint("app.tools.expand", "to expand tools"), keyHint("app.thinking.toggle", "to expand thinking"), keyHint("app.editor.external", "for external editor"), rawKeyHint("/", "for commands"), rawKeyHint("!", "to run bash"), rawKeyHint("!!", "to run bash (no context)"), keyHint("app.message.followUp", "to queue follow-up"), keyHint("app.message.dequeue", "to edit all queued messages"), keyHint("app.clipboard.pasteImage", "to paste image"), rawKeyHint("drop files", "to attach"), ].join("\n"); const compactInstructions = [ keyHint("app.interrupt", "interrupt"), rawKeyHint(`${keyText("app.clear")}/${keyText("app.exit")}`, "clear/exit"), rawKeyHint("/", "commands"), rawKeyHint("!", "bash"), keyHint("app.tools.expand", "more"), ].join(theme.fg("muted", " · ")); const compactOnboarding = theme.fg( "dim", `按 ${keyText("app.tools.expand")} 查看完整帮助和已加载资源。`, ); const onboarding = theme.fg( "dim", "Pi 可以解释自身功能并查阅文档。询问它如何使用或扩展 Pi。", ); let expanded = false; return { render(_width: number): string[] { const logo = theme.bold(theme.fg("accent", "pi")) + theme.fg("dim", ` v${VERSION}`); const lines: string[] = [logo]; if (expanded) { lines.push(expandedInstructions); lines.push(""); lines.push(onboarding); } else { lines.push(compactInstructions); lines.push(compactOnboarding); lines.push(""); lines.push(onboarding); } return lines; }, invalidate() {}, setExpanded(v: boolean) { expanded = v; }, }; }); }); }