@lokiyou/pi-nano-footer 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +63 -4
- package/package.json +2 -2
package/index.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pi-nano-footer — 超轻量 powerline 风格 footer
|
|
2
|
+
* pi-nano-footer — 超轻量 powerline 风格 footer + 输入框脉冲发光
|
|
3
3
|
*
|
|
4
4
|
* 精确复刻 pi-powerline-footer default 预设的样式 +
|
|
5
5
|
* 用户自定义霓虹色配色方案。
|
|
6
6
|
*
|
|
7
|
+
* 当模型工作时(processing):
|
|
8
|
+
* - 输入框边框呈呼吸脉冲发光效果(霓虹色循环)
|
|
9
|
+
* - "Working..." 保持原样
|
|
10
|
+
* - Footer 不变
|
|
11
|
+
*
|
|
7
12
|
* 安装:放到 ~/.pi/agent/extensions/ 后重启 pi 即可自动加载。
|
|
8
13
|
* 临时测试:pi -e ~/.pi/agent/extensions/pi-nano-footer.ts
|
|
9
14
|
*/
|
|
10
15
|
|
|
11
16
|
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
12
17
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
18
|
+
import { Editor } from "@earendil-works/pi-tui";
|
|
13
19
|
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
14
20
|
|
|
15
21
|
// ── Nerd Font 图标(与 pi-powerline-footer 完全一致) ──
|
|
@@ -43,12 +49,55 @@ const C = {
|
|
|
43
49
|
border: "#dfe6e9",
|
|
44
50
|
};
|
|
45
51
|
|
|
52
|
+
// ── 脉冲发光色轮(5色循环,更柔和的呼吸感) ──
|
|
53
|
+
const GLOW_PALETTE = [
|
|
54
|
+
"#ff3cac", // 热粉
|
|
55
|
+
"#ff9f1c", // 橙
|
|
56
|
+
"#00ff87", // 荧光绿
|
|
57
|
+
"#00d4ff", // 青蓝
|
|
58
|
+
"#a855f7", // 紫
|
|
59
|
+
];
|
|
60
|
+
|
|
46
61
|
// ── Rainbow 色表(high / xhigh 思考等级用) ──
|
|
47
62
|
const RAINBOW = [
|
|
48
63
|
"#b281d6", "#d787af", "#febc38", "#e4c00f",
|
|
49
64
|
"#89d281", "#00afaf", "#178fb9", "#b281d6",
|
|
50
65
|
];
|
|
51
66
|
|
|
67
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
68
|
+
// 输入框脉冲发光(Editor.borderColor monkey-patch)
|
|
69
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
70
|
+
|
|
71
|
+
let working = false;
|
|
72
|
+
|
|
73
|
+
/** 时间相位:每 120ms 进一帧 */
|
|
74
|
+
function getPhase(): number {
|
|
75
|
+
return Math.floor(performance.now() / 120);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 保存原始 render */
|
|
79
|
+
const origRender = Editor.prototype.render;
|
|
80
|
+
|
|
81
|
+
Editor.prototype.render = function (width: number): string[] {
|
|
82
|
+
if (working) {
|
|
83
|
+
const saved = this.borderColor; // 保存原始边框颜色函数
|
|
84
|
+
const phase = getPhase() % GLOW_PALETTE.length;
|
|
85
|
+
const hex = GLOW_PALETTE[phase];
|
|
86
|
+
// 临时用脉冲色渲染边框
|
|
87
|
+
this.borderColor = (str: string) => ansi(hex, str);
|
|
88
|
+
try {
|
|
89
|
+
return origRender.call(this, width);
|
|
90
|
+
} finally {
|
|
91
|
+
this.borderColor = saved; // 恢复原始颜色
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return origRender.call(this, width);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
98
|
+
// Extension
|
|
99
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
100
|
+
|
|
52
101
|
export default function (pi: ExtensionAPI) {
|
|
53
102
|
let thinkingLevel = "off";
|
|
54
103
|
let requestRender: (() => void) | undefined;
|
|
@@ -85,7 +134,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
85
134
|
// 4. 上下文用量 —— #6c5ce7 紫 / #fdcb6e 黄 / #ff3366 红
|
|
86
135
|
parts.push(renderContextN(ctx));
|
|
87
136
|
|
|
88
|
-
// 5.
|
|
137
|
+
// 5. Token 用量 —— #00ff87 荧光绿
|
|
89
138
|
const { input, cost } = calcTotals(ctx);
|
|
90
139
|
parts.push(ansi(C.tokens, `${icons.cache} ${icons.input} ${fmt(input)}`));
|
|
91
140
|
|
|
@@ -98,16 +147,26 @@ export default function (pi: ExtensionAPI) {
|
|
|
98
147
|
});
|
|
99
148
|
});
|
|
100
149
|
|
|
101
|
-
// ──
|
|
150
|
+
// ── 事件订阅 ──
|
|
102
151
|
|
|
103
152
|
pi.on("thinking_level_select", (event) => {
|
|
104
153
|
thinkingLevel = event.level;
|
|
105
154
|
refresh();
|
|
106
155
|
});
|
|
107
156
|
pi.on("model_select", () => refresh());
|
|
157
|
+
|
|
158
|
+
// 工作状态切换 → 控制脉冲发光
|
|
159
|
+
pi.on("agent_start", () => {
|
|
160
|
+
working = true;
|
|
161
|
+
refresh();
|
|
162
|
+
});
|
|
163
|
+
pi.on("agent_end", () => {
|
|
164
|
+
working = false;
|
|
165
|
+
refresh();
|
|
166
|
+
});
|
|
167
|
+
|
|
108
168
|
pi.on("turn_start", () => refresh());
|
|
109
169
|
pi.on("turn_end", () => refresh());
|
|
110
|
-
pi.on("agent_end", () => refresh());
|
|
111
170
|
|
|
112
171
|
pi.on("session_shutdown", (_event, ctx) => {
|
|
113
172
|
ctx.ui.setFooter(undefined);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lokiyou/pi-nano-footer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "超轻量 powerline 风格 footer for Pi Coding Agent —
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "超轻量 powerline 风格 footer for Pi Coding Agent — 输入框脉冲发光,霓虹配色,实时显示模型、目录、上下文、token 和费用",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"pi-package",
|