@lokiyou/pi-nano-footer 0.9.0 → 0.11.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.
Files changed (2) hide show
  1. package/index.ts +31 -13
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -46,6 +46,9 @@ const C = {
46
46
  border: "#dfe6e9",
47
47
  };
48
48
 
49
+ // ── ANSI 24-bit true color 正则(用于从 borderColor 函数提取颜色) ──
50
+ const ANSI_RE = /\x1b\[38;2;(\d+);(\d+);(\d+)m/;
51
+
49
52
  // ── Rainbow 色表(high / xhigh 思考等级用) ──
50
53
  const RAINBOW = [
51
54
  "#b281d6", "#d787af", "#febc38", "#e4c00f",
@@ -59,8 +62,15 @@ const RAINBOW = [
59
62
  let working = false;
60
63
  let animInterval: ReturnType<typeof setInterval> | undefined;
61
64
 
62
- /** 工作状态呼吸色:暖橙 #ff9f1c,代表 processing/运行中 */
63
- const WORK_RGB: [number, number, number] = [0xff, 0x9f, 0x1c];
65
+ /**
66
+ * borderColor 函数采样字符,提取当前 RGB 色值
67
+ */
68
+ function extractRGB(fn: (str: string) => string): [number, number, number] | null {
69
+ const sample = fn("─");
70
+ const m = sample.match(ANSI_RE);
71
+ if (!m) return null;
72
+ return [parseInt(m[1]), parseInt(m[2]), parseInt(m[3])];
73
+ }
64
74
 
65
75
  /** 保存原始 render */
66
76
  const origRender = Editor.prototype.render;
@@ -68,17 +78,25 @@ const origRender = Editor.prototype.render;
68
78
  Editor.prototype.render = function (width: number): string[] {
69
79
  if (working) {
70
80
  const saved = this.borderColor;
71
- const [r, g, b] = WORK_RGB;
72
- // 更快呼吸 + 暖橙 processing 色
73
- // 周期 ~600ms(比之前快一倍),60fps 驱动
74
- const t = 0.5 + 0.5 * Math.sin(performance.now() / 300);
75
- const bright = 0.25 + 0.75 * t;
76
- const glow = t * t * 0.35;
77
- const nr = Math.round(Math.min(255, r * bright + (255 - r) * glow));
78
- const ng = Math.round(Math.min(255, g * bright + (255 - g) * glow));
79
- const nb = Math.round(Math.min(255, b * bright + (255 - b) * glow));
80
- this.borderColor = (str: string) =>
81
- `\x1b[38;2;${nr};${ng};${nb}m${str}\x1b[0m`;
81
+ const rgb = extractRGB(saved);
82
+ if (rgb) {
83
+ let [r, g, b] = rgb;
84
+ // 智能工作色:向暖橙 #ff9f1c 偏移 40%
85
+ // 这样冷色(紫/青)会变暖,暖色(橙/红)保持,过渡自然不突兀
86
+ const blend = 0.4;
87
+ r = Math.round(r + (0xff - r) * blend);
88
+ g = Math.round(g + (0x9f - g) * blend);
89
+ b = Math.round(b + (0x1c - b) * blend);
90
+ // 呼吸:周期 ~800ms,60fps
91
+ const t = 0.5 + 0.5 * Math.sin(performance.now() / 400);
92
+ const bright = 0.25 + 0.75 * t;
93
+ const glow = t * t * 0.35;
94
+ const nr = Math.round(Math.min(255, r * bright + (255 - r) * glow));
95
+ const ng = Math.round(Math.min(255, g * bright + (255 - g) * glow));
96
+ const nb = Math.round(Math.min(255, b * bright + (255 - b) * glow));
97
+ this.borderColor = (str: string) =>
98
+ `\x1b[38;2;${nr};${ng};${nb}m${str}\x1b[0m`;
99
+ }
82
100
  try {
83
101
  return origRender.call(this, width);
84
102
  } finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lokiyou/pi-nano-footer",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "超轻量 powerline 风格 footer for Pi Coding Agent — 输入框脉冲发光,霓虹配色,实时显示模型、目录、上下文、token 和费用",
5
5
  "type": "module",
6
6
  "keywords": [