@uncarved/jade 0.3.1 → 0.4.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/dist/api.d.ts +1 -1
- package/dist/api.js +1 -1
- package/dist/host.d.ts +2 -0
- package/dist/host.js +39 -5
- package/dist/host.js.map +1 -1
- package/dist/remote.js +5 -0
- package/dist/remote.js.map +1 -1
- package/dist/session.d.ts +7 -0
- package/dist/session.js +482 -27
- package/dist/session.js.map +1 -1
- package/package.json +4 -4
- package/plugins/approval/index.ts +36 -14
- package/plugins/approval/policy.ts +15 -10
- package/plugins/approval/review.ts +9 -5
- package/plugins/checks/checks.ts +10 -7
- package/plugins/checks/index.ts +13 -13
- package/plugins/checks/plugin.json +1 -1
- package/plugins/checks/project.ts +37 -38
- package/plugins/commands/index.ts +27 -3
- package/plugins/compact/compact.ts +13 -5
- package/plugins/compact/index.ts +20 -3
- package/plugins/compact/style.ts +13 -14
- package/plugins/completions/index.ts +35 -0
- package/plugins/completions/plugin.json +7 -0
- package/plugins/copy/index.ts +46 -0
- package/plugins/copy/plugin.json +7 -0
- package/plugins/editor/index.ts +10 -4
- package/plugins/fs/diff.ts +7 -6
- package/plugins/fs/fs.ts +8 -4
- package/plugins/fs/grep.ts +42 -9
- package/plugins/fs/index.ts +2 -7
- package/plugins/fs/plugin.json +1 -1
- package/plugins/fs/renderers.ts +16 -15
- package/plugins/fs/style.ts +16 -15
- package/plugins/hooks/index.ts +3 -2
- package/plugins/keys/index.ts +5 -1
- package/plugins/mcp/index.ts +197 -78
- package/plugins/mcp/install.ts +5 -3
- package/plugins/mcp/mcp.ts +163 -11
- package/plugins/mcp/plugin.json +2 -1
- package/plugins/mcp/project.ts +47 -50
- package/plugins/memory/index.ts +4 -4
- package/plugins/memory/style.ts +13 -14
- package/plugins/mentions/candidates.ts +67 -0
- package/plugins/mentions/index.ts +12 -5
- package/plugins/mentions/plugin.json +1 -1
- package/plugins/mentions/style.ts +13 -14
- package/plugins/models/configure.ts +10 -9
- package/plugins/models/index.ts +27 -1
- package/plugins/modes/index.ts +13 -2
- package/plugins/print/index.ts +7 -4
- package/plugins/prompts/index.ts +0 -0
- package/plugins/renderers/index.ts +10 -5
- package/plugins/repeats/index.ts +8 -8
- package/plugins/schedule/index.ts +2 -0
- package/plugins/screenshot/browser.ts +10 -0
- package/plugins/sessions/index.ts +48 -2
- package/plugins/shell/index.ts +20 -25
- package/plugins/shell/plugin.json +1 -2
- package/plugins/shell/renderers.ts +9 -7
- package/plugins/shell/shell.ts +3 -1
- package/plugins/skills/index.ts +28 -19
- package/plugins/skills/project.ts +12 -7
- package/plugins/steer/index.ts +5 -4
- package/plugins/task/index.ts +80 -50
- package/plugins/task/plugin.json +6 -2
- package/plugins/task/style.ts +13 -14
- package/plugins/task/subagent.ts +67 -184
- package/plugins/todo/index.ts +39 -9
- package/plugins/tools/index.ts +9 -2
- package/plugins/tui/frontend.ts +139 -89
- package/plugins/tui/index.ts +2 -3
- package/plugins/tui/mentions.ts +11 -80
- package/plugins/tui/plugin.json +1 -1
- package/plugins/tui/screen.ts +55 -5
- package/plugins/tui/transcript.ts +17 -7
- package/plugins/tui/tui.ts +337 -101
- package/plugins/tui/vendor.ts +1 -1
- package/plugins/undo/checkpoint.ts +5 -3
- package/plugins/undo/index.ts +43 -14
- package/plugins/undo/style.ts +13 -14
- package/plugins/web/index.ts +7 -18
- package/plugins/web/plugin.json +1 -1
- package/plugins-dist/approval/index.js +363 -418
- package/plugins-dist/approval/policy.js +391 -508
- package/plugins-dist/approval/review.js +132 -158
- package/plugins-dist/approval/schema.js +50 -55
- package/plugins-dist/ask/index.js +115 -129
- package/plugins-dist/budget/index.js +27 -31
- package/plugins-dist/checks/checks.js +293 -329
- package/plugins-dist/checks/index.js +119 -139
- package/plugins-dist/checks/plugin.json +2 -1
- package/plugins-dist/checks/project.js +57 -65
- package/plugins-dist/commands/index.js +47 -29
- package/plugins-dist/compact/compact.js +233 -249
- package/plugins-dist/compact/index.js +98 -95
- package/plugins-dist/compact/style.js +9 -14
- package/plugins-dist/completions/index.js +30 -0
- package/plugins-dist/completions/plugin.json +9 -0
- package/plugins-dist/continue/index.js +40 -52
- package/plugins-dist/copy/index.js +40 -0
- package/plugins-dist/copy/plugin.json +9 -0
- package/plugins-dist/cost/index.js +98 -115
- package/plugins-dist/custom-commands/index.js +55 -72
- package/plugins-dist/editor/index.js +64 -72
- package/plugins-dist/fs/diff.js +111 -124
- package/plugins-dist/fs/fs.js +426 -469
- package/plugins-dist/fs/grep.js +262 -253
- package/plugins-dist/fs/index.js +20 -34
- package/plugins-dist/fs/plugin.json +1 -2
- package/plugins-dist/fs/renderers.js +100 -112
- package/plugins-dist/fs/style.js +11 -15
- package/plugins-dist/fs/sys.js +31 -43
- package/plugins-dist/hooks/index.js +107 -127
- package/plugins-dist/keys/index.js +27 -31
- package/plugins-dist/mcp/index.js +271 -199
- package/plugins-dist/mcp/install.js +123 -137
- package/plugins-dist/mcp/mcp.js +638 -577
- package/plugins-dist/mcp/plugin.json +3 -1
- package/plugins-dist/mcp/project.js +98 -115
- package/plugins-dist/memory/index.js +83 -88
- package/plugins-dist/memory/memory.js +111 -128
- package/plugins-dist/memory/style.js +9 -14
- package/plugins-dist/mentions/attach.js +91 -99
- package/plugins-dist/mentions/candidates.js +49 -0
- package/plugins-dist/mentions/index.js +71 -81
- package/plugins-dist/mentions/plugin.json +2 -1
- package/plugins-dist/mentions/style.js +9 -14
- package/plugins-dist/models/config.js +29 -43
- package/plugins-dist/models/configure.js +392 -473
- package/plugins-dist/models/context.js +14 -22
- package/plugins-dist/models/index.js +182 -189
- package/plugins-dist/models/provider.js +243 -307
- package/plugins-dist/models/saved.js +59 -71
- package/plugins-dist/modes/index.js +138 -165
- package/plugins-dist/plugins/index.js +34 -34
- package/plugins-dist/print/index.js +192 -175
- package/plugins-dist/prompts/index.js +81 -89
- package/plugins-dist/prompts/notes.js +31 -37
- package/plugins-dist/prompts/prompts.js +155 -193
- package/plugins-dist/prompts/results.js +40 -53
- package/plugins-dist/prompts/sys.js +39 -50
- package/plugins-dist/renderers/index.js +32 -32
- package/plugins-dist/repeats/index.js +131 -174
- package/plugins-dist/schedule/cron.js +49 -56
- package/plugins-dist/schedule/index.js +229 -247
- package/plugins-dist/schedule/store.js +93 -109
- package/plugins-dist/scratch/index.js +12 -18
- package/plugins-dist/screenshot/browser.js +136 -154
- package/plugins-dist/screenshot/index.js +37 -46
- package/plugins-dist/screenshot/sys.js +53 -65
- package/plugins-dist/screenshot/tool.js +98 -126
- package/plugins-dist/sessions/index.js +149 -117
- package/plugins-dist/shell/index.js +115 -135
- package/plugins-dist/shell/plugin.json +1 -2
- package/plugins-dist/shell/renderers.js +28 -33
- package/plugins-dist/shell/service.js +17 -23
- package/plugins-dist/shell/shell.js +307 -362
- package/plugins-dist/shell/sys.js +64 -79
- package/plugins-dist/skills/index.js +193 -211
- package/plugins-dist/skills/install.js +122 -149
- package/plugins-dist/skills/project.js +65 -73
- package/plugins-dist/skills/skills.js +135 -171
- package/plugins-dist/steer/index.js +108 -125
- package/plugins-dist/suggest/index.js +235 -259
- package/plugins-dist/task/index.js +130 -117
- package/plugins-dist/task/plugin.json +5 -2
- package/plugins-dist/task/style.js +9 -14
- package/plugins-dist/task/subagent.js +156 -279
- package/plugins-dist/todo/index.js +79 -63
- package/plugins-dist/tools/index.js +36 -42
- package/plugins-dist/tui/editor.js +145 -160
- package/plugins-dist/tui/frontend.js +639 -678
- package/plugins-dist/tui/history.js +34 -37
- package/plugins-dist/tui/index.js +16 -18
- package/plugins-dist/tui/markdown.js +203 -247
- package/plugins-dist/tui/mascot.js +266 -355
- package/plugins-dist/tui/mentions.js +67 -144
- package/plugins-dist/tui/plugin.json +1 -2
- package/plugins-dist/tui/render.js +35 -45
- package/plugins-dist/tui/screen.js +197 -180
- package/plugins-dist/tui/transcript.js +436 -468
- package/plugins-dist/tui/tui.js +1554 -1656
- package/plugins-dist/undo/checkpoint.js +95 -118
- package/plugins-dist/undo/index.js +185 -192
- package/plugins-dist/undo/snapshot.js +83 -99
- package/plugins-dist/undo/style.js +9 -14
- package/plugins-dist/update/index.js +26 -28
- package/plugins-dist/web/env.js +55 -68
- package/plugins-dist/web/index.js +80 -110
- package/plugins-dist/web/plugin.json +1 -2
- package/plugins-dist/web/renderers.js +4 -5
- package/plugins-dist/web/web.js +514 -593
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +9 -2
- package/src/api.ts +1 -1
- package/src/host.ts +39 -4
- package/src/remote.ts +6 -1
- package/src/session.ts +489 -34
|
@@ -1,42 +1,29 @@
|
|
|
1
|
-
// 标题左边的吉祥物:一个玉做的团子,按当前在做的事换表情、带一点动画;还有终端标签页标题上的 jade 标志。
|
|
2
|
-
// 不碰 Ink:动画由 App 统一重画推动(见 tui.ts 的 tick),这里每次按时间算出这一帧。
|
|
3
|
-
//
|
|
4
|
-
// 画布 15×6 个像素,每格字符上下两个像素(▀ 前景是上面、背景是下面),6 个像素高正好三行,和右边三行文字并排。
|
|
5
|
-
// 左边 9 列是身体,空一列,右边 5 列放表情以外的小东西(思考的三个点、工具的转圈、提问的感叹号、做完的 ✓……都用像素画)。画布宽度不随表情变,标题右边的文字不会跟着左右跳。
|
|
6
|
-
//
|
|
7
|
-
// 精度只有这么多,细节靠颜色:身体按光照着色(左上亮、边缘暗、一点高光),眼睛是深色的形状,
|
|
8
|
-
// 每个像素按 4×4 次采样算出眼睛盖住了多少、和身体的颜色混合,所以眼睛可以不按整格移动、眨眼也有中间的几帧。
|
|
9
|
-
// 身体外面是终端背景,颜色未知、没法混合,所以轮廓只按整格变(只有做完后蹦那一下会变)、混色只在身体里面做。
|
|
10
|
-
// 视线、睁眼的程度、颜色在状态之间缓动(Mascot),不会一下跳过去。
|
|
11
1
|
export const JADE = "#00a86b";
|
|
12
|
-
/** 做完后笑多久 */
|
|
13
2
|
export const HAPPY_MS = 4000;
|
|
14
3
|
export function moodOf(s, now) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
4
|
+
if (s.asking)
|
|
5
|
+
return "asking";
|
|
6
|
+
const b = s.busy;
|
|
7
|
+
if (b === undefined)
|
|
8
|
+
return s.doneAt !== undefined && now - s.doneAt < HAPPY_MS ? "happy" : "idle";
|
|
9
|
+
if (b === "Interrupting")
|
|
10
|
+
return "stopping";
|
|
11
|
+
if (b === "Thinking")
|
|
12
|
+
return "thinking";
|
|
13
|
+
if (b.startsWith("Writing"))
|
|
14
|
+
return "writing";
|
|
15
|
+
if (b.startsWith("Running "))
|
|
16
|
+
return "tool";
|
|
17
|
+
return "waiting";
|
|
29
18
|
}
|
|
30
19
|
const rgb = (hex) => [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));
|
|
31
20
|
const hex = (c) => `#${c.map((v) => Math.round(Math.max(0, Math.min(255, v))).toString(16).padStart(2, "0")).join("")}`;
|
|
32
21
|
const mix = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
33
|
-
/** 按 t(0–1)在一串颜色之间插值 */
|
|
34
22
|
const ramp = (stops, t) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
const x = Math.max(0, Math.min(1, t)) * (stops.length - 1);
|
|
24
|
+
const i = Math.min(stops.length - 2, Math.floor(x));
|
|
25
|
+
return mix(stops[i], stops[i + 1], x - i);
|
|
38
26
|
};
|
|
39
|
-
/** 从暗到亮的玉色;中断时换成琥珀色那一套 */
|
|
40
27
|
const JADE_RAMP = ["#004a33", "#00744c", JADE, "#2ccc8a", "#8eeec0"].map(rgb);
|
|
41
28
|
const AMBER_RAMP = ["#5a3a00", "#9a6500", "#e0a526", "#f4c75a", "#fde4a0"].map(rgb);
|
|
42
29
|
const SPECULAR = rgb("#effff6");
|
|
@@ -45,397 +32,321 @@ const PALE = rgb("#b6f2d4");
|
|
|
45
32
|
const DEEP = rgb("#00744c");
|
|
46
33
|
const BANG = [rgb("#f5c518"), rgb("#fff1a8")];
|
|
47
34
|
const SWEAT = rgb("#8fd3ff");
|
|
48
|
-
/** 蹦起来时地上的影子:身体外面没法和终端背景混合,用一个暗的玉色 */
|
|
49
35
|
const SHADOW = mix(DEEP, EYE, 0.55);
|
|
50
|
-
// ---------- 形状 ----------
|
|
51
36
|
const W = 15;
|
|
52
|
-
/** 右边小东西的第一列:和身体之间空一列,不贴着 */
|
|
53
37
|
const SIDE = 10;
|
|
54
38
|
const H = 6;
|
|
55
|
-
/** 身体的轮廓(9 列),轮廓外是终端背景 */
|
|
56
39
|
const MASK = ["..#####..", ".#######.", "#########", "#########", "#########", ".#######."];
|
|
57
40
|
const CX = 4.5;
|
|
58
41
|
const SHAPES = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
42
|
+
rest: { mask: MASK, top: 0, bottom: 6, dy: 0 },
|
|
43
|
+
crouch: { mask: [".........", ".#######.", "#########", "#########", "#########", ".#######."], top: 1, bottom: 6, dy: 1 },
|
|
44
|
+
air: { mask: ["..#####..", ".#######.", "#########", "#########", ".#######.", "........."], top: 0, bottom: 5, dy: -1 }
|
|
62
45
|
};
|
|
63
|
-
/** 做完后的一跳:蹲下蓄力 → 跳起 → 落地压扁一下 → 站好(t 是进入 happy 之后的毫秒) */
|
|
64
46
|
const HOP = { crouch: 90, air: 380, land: 470 };
|
|
65
47
|
function shapeAt(mood, t) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
48
|
+
if (mood !== "happy" || t >= HOP.land)
|
|
49
|
+
return SHAPES.rest;
|
|
50
|
+
return t < HOP.crouch || t >= HOP.air ? SHAPES.crouch : SHAPES.air;
|
|
69
51
|
}
|
|
70
|
-
/**
|
|
71
|
-
* 两只眼睛:中心的 x、下沿的 y(像素坐标,像素 (x, y) 覆盖 [x, x+1)×[y, y+1)),宽 1、高 2 个像素。
|
|
72
|
-
* 停住的位置都正好对齐像素,眼睛是清楚的两块;只有移动、眨眼的中间几帧才会混出过渡色
|
|
73
|
-
*/
|
|
74
52
|
const EYES_X = [2.5, 6.5];
|
|
75
53
|
const EYE_BOTTOM = 4;
|
|
76
54
|
const EYE_H = 2;
|
|
77
55
|
const smooth = (t) => {
|
|
78
|
-
|
|
79
|
-
|
|
56
|
+
const x = Math.max(0, Math.min(1, t));
|
|
57
|
+
return x * x * (3 - 2 * x);
|
|
80
58
|
};
|
|
81
59
|
const gauss = (dx, dy, s) => Math.exp(-(dx * dx + dy * dy) / (2 * s * s));
|
|
82
60
|
const REST = { gx: 0, gy: 0, open: 1, happy: 0, wink: 0, tint: 0, glow: 0 };
|
|
83
|
-
// ---------- 时间轴 ----------
|
|
84
61
|
const ease = (now, keys, period) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return keys[0][1];
|
|
62
|
+
const t = now % period;
|
|
63
|
+
for (let i = 0;i < keys.length; i++) {
|
|
64
|
+
const [t0, v0] = keys[i];
|
|
65
|
+
const [t1raw, v1] = keys[(i + 1) % keys.length];
|
|
66
|
+
const t1 = i + 1 < keys.length ? t1raw : t1raw + period;
|
|
67
|
+
if (t >= t0 && t < t1)
|
|
68
|
+
return v0 + (v1 - v0) * smooth((t - t0) / (t1 - t0));
|
|
69
|
+
}
|
|
70
|
+
return keys[0][1];
|
|
95
71
|
};
|
|
96
|
-
/** 关键帧之间停一会儿再动:每个值先停 hold 毫秒,再用 move 毫秒移到下一个 */
|
|
97
72
|
const steps = (values, hold, move) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
73
|
+
const keys = [];
|
|
74
|
+
values.forEach((v, i) => {
|
|
75
|
+
keys.push([i * (hold + move), v], [i * (hold + move) + hold, v]);
|
|
76
|
+
});
|
|
77
|
+
return [keys, values.length * (hold + move)];
|
|
103
78
|
};
|
|
104
|
-
/** 每隔多久眨一次眼,眨一下多久 */
|
|
105
79
|
const BLINK_EVERY = 4200;
|
|
106
80
|
const BLINK_MS = 220;
|
|
107
|
-
|
|
108
|
-
const GLANCE_EVERY = 11_000;
|
|
81
|
+
const GLANCE_EVERY = 11000;
|
|
109
82
|
const GLANCE = [7000, 8600];
|
|
110
|
-
/** 眨眼:返回睁眼程度的系数。每第三次连眨两下 */
|
|
111
83
|
function blink(now) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
84
|
+
const n = Math.floor(now / BLINK_EVERY);
|
|
85
|
+
const t = now % BLINK_EVERY;
|
|
86
|
+
const one = (t0) => t >= t0 && t < t0 + BLINK_MS ? 1 - Math.sin(Math.PI * (t - t0) / BLINK_MS) : 1;
|
|
87
|
+
return Math.min(one(0), n % 3 === 2 ? one(BLINK_MS + 90) : 1);
|
|
116
88
|
}
|
|
117
|
-
/** 做完后什么时候回过头眨眼(落地后先看着 ✓ 画出来) */
|
|
118
89
|
const WINK_AT = 1500;
|
|
119
|
-
/** 这个状态此刻想要的样子(Mascot 往这里缓动);t 是进入这个状态之后的毫秒,只有 happy 用 */
|
|
120
90
|
export function goal(mood, now, t = HAPPY_MS / 2) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
case "thinking": {
|
|
132
|
-
// 琢磨:眯起眼往左上方望,身体一点点亮起来(在攒想法);
|
|
133
|
-
// 想到了:睁开眼转向右上角,看着三个点一个个冒出来,攒的亮光随着点冒出来慢慢退掉
|
|
134
|
-
const gx = ease(now, [[0, -1], [THINK.ponder - 350, -1], [THINK.ponder, 1], [THINK.period - 350, 1]], THINK.period);
|
|
135
|
-
const open = ease(now, [[0, 0.5], [THINK.ponder - 350, 0.5], [THINK.ponder, 1], [THINK.period - 350, 1]], THINK.period);
|
|
136
|
-
const glow = ease(now, [[0, 0], [THINK.ponder, 0.75], [THINK.dot(2), 0]], THINK.period);
|
|
137
|
-
return { ...REST, gx, gy: -1, open: open * blink(now + 1700), glow };
|
|
138
|
-
}
|
|
139
|
-
case "writing": {
|
|
140
|
-
// 读着刚写的字:一行里从左往右扫,到头回来
|
|
141
|
-
const [keys, period] = steps([-1, 0, 1], 260, 140);
|
|
142
|
-
return { ...REST, gx: ease(now, keys, period), gy: 1, open: 0.5 + 0.5 * blink(now + 600) };
|
|
143
|
-
}
|
|
144
|
-
case "tool":
|
|
145
|
-
return { ...REST, gx: 1, open: blink(now + 900) };
|
|
146
|
-
case "asking":
|
|
147
|
-
return { ...REST, open: 1.5 * blink(now + 2500) };
|
|
148
|
-
case "stopping":
|
|
149
|
-
return { ...REST, open: 0, tint: 1 };
|
|
150
|
-
case "happy": {
|
|
151
|
-
// 只有眼睛,不加嘴和脸红:别的表情都只靠眼睛,加了反而不像同一个。
|
|
152
|
-
// 蹦的时候 ^ ^;落地那一下身体一亮,睁眼看右边的 ✓ 画出来;然后回过头,左眼 ^ 冲你眨一下
|
|
153
|
-
const glow = t >= HOP.air ? Math.exp(-(t - HOP.air) / 260) : 0;
|
|
154
|
-
if (t < HOP.land)
|
|
155
|
-
return { ...REST, happy: 1, glow };
|
|
156
|
-
if (t < WINK_AT)
|
|
157
|
-
return { ...REST, gx: 1, glow };
|
|
158
|
-
return { ...REST, wink: 1 };
|
|
159
|
-
}
|
|
91
|
+
switch (mood) {
|
|
92
|
+
case "idle": {
|
|
93
|
+
const t = now % GLANCE_EVERY;
|
|
94
|
+
const look = t >= GLANCE[0] && t < GLANCE[1] ? -1 : 0;
|
|
95
|
+
return { ...REST, gx: look, open: blink(now) };
|
|
96
|
+
}
|
|
97
|
+
case "waiting": {
|
|
98
|
+
const [keys, period] = steps([0, -1, 0, 1], 600, 350);
|
|
99
|
+
return { ...REST, gx: ease(now, keys, period), open: blink(now) };
|
|
160
100
|
}
|
|
101
|
+
case "thinking": {
|
|
102
|
+
const gx = ease(now, [[0, -1], [THINK.ponder - 350, -1], [THINK.ponder, 1], [THINK.period - 350, 1]], THINK.period);
|
|
103
|
+
const open = ease(now, [[0, 0.5], [THINK.ponder - 350, 0.5], [THINK.ponder, 1], [THINK.period - 350, 1]], THINK.period);
|
|
104
|
+
const glow = ease(now, [[0, 0], [THINK.ponder, 0.75], [THINK.dot(2), 0]], THINK.period);
|
|
105
|
+
return { ...REST, gx, gy: -1, open: open * blink(now + 1700), glow };
|
|
106
|
+
}
|
|
107
|
+
case "writing": {
|
|
108
|
+
const [keys, period] = steps([-1, 0, 1], 260, 140);
|
|
109
|
+
return { ...REST, gx: ease(now, keys, period), gy: 1, open: 0.5 + 0.5 * blink(now + 600) };
|
|
110
|
+
}
|
|
111
|
+
case "tool":
|
|
112
|
+
return { ...REST, gx: 1, open: blink(now + 900) };
|
|
113
|
+
case "asking":
|
|
114
|
+
return { ...REST, open: 1.5 * blink(now + 2500) };
|
|
115
|
+
case "stopping":
|
|
116
|
+
return { ...REST, open: 0, tint: 1 };
|
|
117
|
+
case "happy": {
|
|
118
|
+
const glow = t >= HOP.air ? Math.exp(-(t - HOP.air) / 260) : 0;
|
|
119
|
+
if (t < HOP.land)
|
|
120
|
+
return { ...REST, happy: 1, glow };
|
|
121
|
+
if (t < WINK_AT)
|
|
122
|
+
return { ...REST, gx: 1, glow };
|
|
123
|
+
return { ...REST, wink: 1 };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
161
126
|
}
|
|
162
|
-
/** 画一帧:返回 6 行、每行 15 个颜色("#rrggbb"),undefined 是透明(终端背景);t 同 goal */
|
|
163
127
|
export function paint(p, mood, now, t = HAPPY_MS / 2) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
for (let
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const px = x + (sx + 0.5) / 4;
|
|
189
|
-
const py = y + (sy + 0.5) / 4;
|
|
190
|
-
cover += eyeAt(p, px, py - shape.dy) / 16;
|
|
191
|
-
}
|
|
192
|
-
c = mix(c, mix(EYE, ramp_(0.05), p.tint * 0.4), Math.min(1, cover));
|
|
193
|
-
grid[y][x] = c;
|
|
128
|
+
const shape = shapeAt(mood, t);
|
|
129
|
+
const cy = (shape.top + shape.bottom) / 2;
|
|
130
|
+
const half = (shape.bottom - shape.top) / 2;
|
|
131
|
+
const ramp_ = (t) => mix(ramp(JADE_RAMP, t), ramp(AMBER_RAMP, t), p.tint);
|
|
132
|
+
const grid = Array.from({ length: H }, () => Array(W).fill(undefined));
|
|
133
|
+
const sweep = mood === "tool" ? now % 1400 / 1400 * 16 - 4 : undefined;
|
|
134
|
+
for (let y = 0;y < H; y++)
|
|
135
|
+
for (let x = 0;x < 9; x++) {
|
|
136
|
+
if (shape.mask[y]?.[x] !== "#")
|
|
137
|
+
continue;
|
|
138
|
+
const nx = (x + 0.5 - CX) / 4.5;
|
|
139
|
+
const ny = (y + 0.5 - cy) / half;
|
|
140
|
+
const r = Math.max(Math.abs(nx), Math.abs(ny) * 0.9, Math.hypot(nx, ny) * 0.82);
|
|
141
|
+
let light = 0.62 - 0.3 * ny - 0.14 * nx - 0.32 * smooth((r - 0.55) / 0.45) + 0.18 * p.glow;
|
|
142
|
+
if (sweep !== undefined)
|
|
143
|
+
light += 0.22 * Math.exp(-(((x - y * 0.5 - sweep) / 0.8) ** 2));
|
|
144
|
+
let c = ramp_(light);
|
|
145
|
+
c = mix(c, SPECULAR, 0.9 * gauss(x - 2, y - shape.top - 1, 0.45));
|
|
146
|
+
let cover = 0;
|
|
147
|
+
for (let sy = 0;sy < 4; sy++)
|
|
148
|
+
for (let sx = 0;sx < 4; sx++) {
|
|
149
|
+
const px = x + (sx + 0.5) / 4;
|
|
150
|
+
const py = y + (sy + 0.5) / 4;
|
|
151
|
+
cover += eyeAt(p, px, py - shape.dy) / 16;
|
|
194
152
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
for (
|
|
200
|
-
|
|
201
|
-
|
|
153
|
+
c = mix(c, mix(EYE, ramp_(0.05), p.tint * 0.4), Math.min(1, cover));
|
|
154
|
+
grid[y][x] = c;
|
|
155
|
+
}
|
|
156
|
+
if (shape === SHAPES.air)
|
|
157
|
+
for (let x = 3;x < 6; x++)
|
|
158
|
+
grid[5][x] = SHADOW;
|
|
159
|
+
for (const [x, y, c] of extras(mood, now, t))
|
|
160
|
+
grid[y][x] = c;
|
|
161
|
+
return grid.map((row) => row.map((c) => c ? hex(c) : undefined));
|
|
202
162
|
}
|
|
203
|
-
/** 眼睛在 (px, py) 处的覆盖(0 或 1):普通的眼睛和 ^ 形的笑眼按 happy 混合(左眼还算上 wink) */
|
|
204
163
|
function eyeAt(p, px, py) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (Math.abs(px - ex) < 0.5) {
|
|
218
|
-
// 闭眼是上眼皮往下:下沿不动,高度变小,最少留 1 像素的一条线
|
|
219
|
-
const lower = bottom - Math.min(1, happy / 0.6);
|
|
220
|
-
const upper = Math.min(bottom - Math.max(1, EYE_H * p.open), lower - 1);
|
|
221
|
-
if (py >= upper && py < lower)
|
|
222
|
-
best = 1;
|
|
223
|
-
}
|
|
224
|
-
if (smile && Math.abs(Math.abs(px - ex) - 1) < 0.5 && py >= bottom - 1 && py < bottom)
|
|
225
|
-
best = 1;
|
|
164
|
+
let best = 0;
|
|
165
|
+
for (const [i, bx] of EYES_X.entries()) {
|
|
166
|
+
const happy = i === 0 ? Math.max(p.happy, p.wink) : p.happy;
|
|
167
|
+
const smile = happy > 0.6;
|
|
168
|
+
const out = p.happy > 0.6 ? i === 0 ? -1 : 1 : 0;
|
|
169
|
+
const ex = smile ? Math.round(bx + p.gx - 0.5) + 0.5 + out : bx + p.gx;
|
|
170
|
+
const bottom = smile ? Math.round(EYE_BOTTOM + p.gy) : EYE_BOTTOM + p.gy;
|
|
171
|
+
if (Math.abs(px - ex) < 0.5) {
|
|
172
|
+
const lower = bottom - Math.min(1, happy / 0.6);
|
|
173
|
+
const upper = Math.min(bottom - Math.max(1, EYE_H * p.open), lower - 1);
|
|
174
|
+
if (py >= upper && py < lower)
|
|
175
|
+
best = 1;
|
|
226
176
|
}
|
|
227
|
-
|
|
177
|
+
if (smile && Math.abs(Math.abs(px - ex) - 1) < 0.5 && py >= bottom - 1 && py < bottom)
|
|
178
|
+
best = 1;
|
|
179
|
+
}
|
|
180
|
+
return best;
|
|
228
181
|
}
|
|
229
|
-
/** 右边的小东西:[列, 行, 颜色],列是 SIDE 起的 0–4 */
|
|
230
182
|
function extras(mood, now, t) {
|
|
231
|
-
|
|
183
|
+
return side(mood, now, t).map(([x, y, c]) => [SIDE + x, y, c]);
|
|
232
184
|
}
|
|
233
|
-
/** ✓ 的五个像素,按笔画的顺序:短的一笔往右下,长的一笔往右上 */
|
|
234
185
|
const CHECK = [
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
186
|
+
[0, 3],
|
|
187
|
+
[1, 4],
|
|
188
|
+
[2, 3],
|
|
189
|
+
[3, 2],
|
|
190
|
+
[4, 1]
|
|
240
191
|
];
|
|
241
|
-
/** ✓ 落地后一笔画出来,每个像素隔多久;画完过一会儿一道光沿着笔画走一遍;最后按笔画的顺序暗下去消失 */
|
|
242
192
|
const CHECK_STEP = 55;
|
|
243
193
|
const CHECK_SHINE = 1900;
|
|
244
194
|
const CHECK_FADE = HAPPY_MS - 600;
|
|
245
195
|
function check(t) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
c = mix(c, DEEP, out);
|
|
261
|
-
return [[x, y, c]];
|
|
262
|
-
});
|
|
196
|
+
const white = rgb("#ffffff");
|
|
197
|
+
return CHECK.flatMap(([x, y], i) => {
|
|
198
|
+
const age = t - (HOP.land + i * CHECK_STEP);
|
|
199
|
+
if (age < 0)
|
|
200
|
+
return [];
|
|
201
|
+
let c = mix(PALE, white, Math.exp(-age / 120));
|
|
202
|
+
c = mix(c, white, 0.85 * Math.exp(-(((t - CHECK_SHINE) / 60 - i) ** 2)));
|
|
203
|
+
const out = (t - CHECK_FADE - i * 70) / 280;
|
|
204
|
+
if (out >= 1)
|
|
205
|
+
return [];
|
|
206
|
+
if (out > 0)
|
|
207
|
+
c = mix(c, DEEP, out);
|
|
208
|
+
return [[x, y, c]];
|
|
209
|
+
});
|
|
263
210
|
}
|
|
264
211
|
const fade = (t) => ramp([DEEP, rgb(JADE), PALE], t);
|
|
265
|
-
/**
|
|
266
|
-
* 思考的节奏(一圈的毫秒数):先琢磨 ponder,然后三个点隔 gap 一个个冒出来;
|
|
267
|
-
* 三个都在了停一会儿,从 dim 起一起暗下去、拿掉,再接着琢磨
|
|
268
|
-
*/
|
|
269
212
|
const THINK = {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
/** 暗下去用多久:之后拿掉(外面是终端背景,没法渐隐) */
|
|
277
|
-
fade: 400,
|
|
213
|
+
period: 4800,
|
|
214
|
+
ponder: 1700,
|
|
215
|
+
gap: 550,
|
|
216
|
+
dot: (i) => THINK.ponder + 250 + i * THINK.gap,
|
|
217
|
+
dim: 4200,
|
|
218
|
+
fade: 400
|
|
278
219
|
};
|
|
279
|
-
/** 三个点:在右上方从左往右排成一排,和往右上看的眼睛同一高度附近,像省略号 */
|
|
280
220
|
const DOTS = [
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
221
|
+
[0, 1],
|
|
222
|
+
[2, 1],
|
|
223
|
+
[4, 1]
|
|
284
224
|
];
|
|
285
225
|
function dots(now) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
});
|
|
226
|
+
const t = now % THINK.period;
|
|
227
|
+
const out = (t - THINK.dim) / THINK.fade;
|
|
228
|
+
if (out >= 1)
|
|
229
|
+
return [];
|
|
230
|
+
return DOTS.flatMap(([x, y], i) => {
|
|
231
|
+
const age = t - THINK.dot(i);
|
|
232
|
+
if (age < 0)
|
|
233
|
+
return [];
|
|
234
|
+
let c = mix(fade(0.85), rgb("#ffffff"), Math.exp(-age / 140));
|
|
235
|
+
if (out > 0)
|
|
236
|
+
c = mix(c, DEEP, out);
|
|
237
|
+
return [[x, y, c]];
|
|
238
|
+
});
|
|
300
239
|
}
|
|
301
240
|
function side(mood, now, t) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
// 感叹号在两种黄之间呼吸
|
|
333
|
-
const c = mix(BANG[0], BANG[1], 0.5 + 0.5 * Math.sin(now / 160));
|
|
334
|
-
return [0, 1, 2, 4].map((y) => [1, y, c]);
|
|
335
|
-
}
|
|
336
|
-
case "stopping": {
|
|
337
|
-
// 汗珠从头的右上角贴着身体一滴滴往下滑:亮的一头在下面,上面拖一格淡的;滑到底停一拍再冒下一滴
|
|
338
|
-
const row = Math.floor((now % 1000) / 200);
|
|
339
|
-
if (row > 3)
|
|
340
|
-
return [];
|
|
341
|
-
const head = [-1, row, mix(SWEAT, rgb("#ffffff"), 0.4)];
|
|
342
|
-
return row > 0 ? [[-1, row - 1, SWEAT], head] : [head];
|
|
343
|
-
}
|
|
344
|
-
default:
|
|
345
|
-
return [];
|
|
241
|
+
switch (mood) {
|
|
242
|
+
case "happy":
|
|
243
|
+
return check(t);
|
|
244
|
+
case "thinking":
|
|
245
|
+
return dots(now);
|
|
246
|
+
case "writing": {
|
|
247
|
+
const t = now % 1200 / 1200;
|
|
248
|
+
return [0, 1, 2].flatMap((x) => {
|
|
249
|
+
const age = t - x * 0.18;
|
|
250
|
+
return age >= 0 && age < 0.75 ? [[x, 5, fade(1 - Math.max(0, age - 0.25) * 2)]] : [];
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
case "tool": {
|
|
254
|
+
const ring = [
|
|
255
|
+
[1, 1],
|
|
256
|
+
[2, 2],
|
|
257
|
+
[2, 3],
|
|
258
|
+
[1, 4],
|
|
259
|
+
[0, 3],
|
|
260
|
+
[0, 2]
|
|
261
|
+
];
|
|
262
|
+
const head = Math.floor(now / 90) % ring.length;
|
|
263
|
+
return [0, 1, 2, 3].map((k) => {
|
|
264
|
+
const [x, y] = ring[(head - k + ring.length) % ring.length];
|
|
265
|
+
return [x, y, fade(1 - k / 3.2)];
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
case "asking": {
|
|
269
|
+
const c = mix(BANG[0], BANG[1], 0.5 + 0.5 * Math.sin(now / 160));
|
|
270
|
+
return [0, 1, 2, 4].map((y) => [1, y, c]);
|
|
346
271
|
}
|
|
272
|
+
case "stopping": {
|
|
273
|
+
const row = Math.floor(now % 1000 / 200);
|
|
274
|
+
if (row > 3)
|
|
275
|
+
return [];
|
|
276
|
+
const head = [-1, row, mix(SWEAT, rgb("#ffffff"), 0.4)];
|
|
277
|
+
return row > 0 ? [[-1, row - 1, SWEAT], head] : [head];
|
|
278
|
+
}
|
|
279
|
+
default:
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
347
282
|
}
|
|
348
|
-
|
|
349
|
-
* 有状态的动画:每次 frame 把 Pose 往当前状态想要的样子缓动一点,所以换状态时眼睛是滑过去的。
|
|
350
|
-
* 眨眼这种很快的动作直接用目标值,不缓动
|
|
351
|
-
*/
|
|
283
|
+
|
|
352
284
|
export class Mascot {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
this.#since = now;
|
|
362
|
-
}
|
|
363
|
-
const t = now - this.#since;
|
|
364
|
-
const want = goal(mood, now, t);
|
|
365
|
-
const dt = this.#last === undefined ? 1e9 : Math.max(0, now - this.#last);
|
|
366
|
-
this.#last = now;
|
|
367
|
-
const k = 1 - Math.exp(-dt / 110);
|
|
368
|
-
const p = this.pose;
|
|
369
|
-
for (const key of ["gx", "gy", "happy", "wink", "tint"])
|
|
370
|
-
p[key] += (want[key] - p[key]) * k;
|
|
371
|
-
p.open = want.open < p.open ? want.open : p.open + (want.open - p.open) * (1 - Math.exp(-dt / 50));
|
|
372
|
-
p.glow = want.glow;
|
|
373
|
-
return paint(p, mood, now, t);
|
|
374
|
-
}
|
|
375
|
-
/** 还在往目标缓动(空闲时也要接着重画几帧) */
|
|
376
|
-
moving(mood, now) {
|
|
377
|
-
const want = goal(mood, now, mood === this.#mood ? now - this.#since : 0);
|
|
378
|
-
const p = this.pose;
|
|
379
|
-
return ["gx", "gy", "happy", "wink", "tint", "open"].some((k) => Math.abs(want[k] - p[k]) > 0.02);
|
|
285
|
+
pose = { ...REST };
|
|
286
|
+
#last;
|
|
287
|
+
#mood;
|
|
288
|
+
#since = 0;
|
|
289
|
+
frame(mood, now) {
|
|
290
|
+
if (mood !== this.#mood) {
|
|
291
|
+
this.#mood = mood;
|
|
292
|
+
this.#since = now;
|
|
380
293
|
}
|
|
294
|
+
const t = now - this.#since;
|
|
295
|
+
const want = goal(mood, now, t);
|
|
296
|
+
const dt = this.#last === undefined ? 1e9 : Math.max(0, now - this.#last);
|
|
297
|
+
this.#last = now;
|
|
298
|
+
const k = 1 - Math.exp(-dt / 110);
|
|
299
|
+
const p = this.pose;
|
|
300
|
+
for (const key of ["gx", "gy", "happy", "wink", "tint"])
|
|
301
|
+
p[key] += (want[key] - p[key]) * k;
|
|
302
|
+
p.open = want.open < p.open ? want.open : p.open + (want.open - p.open) * (1 - Math.exp(-dt / 50));
|
|
303
|
+
p.glow = want.glow;
|
|
304
|
+
return paint(p, mood, now, t);
|
|
305
|
+
}
|
|
306
|
+
moving(mood, now) {
|
|
307
|
+
const want = goal(mood, now, mood === this.#mood ? now - this.#since : 0);
|
|
308
|
+
const p = this.pose;
|
|
309
|
+
return ["gx", "gy", "happy", "wink", "tint", "open"].some((k) => Math.abs(want[k] - p[k]) > 0.02);
|
|
310
|
+
}
|
|
381
311
|
}
|
|
382
|
-
/** 把像素合成半格字符,每一行是若干段同色的字符 */
|
|
383
312
|
export function cells(grid) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
if (last && last.fg === cell.fg && last.bg === cell.bg)
|
|
399
|
-
last.text += cell.text;
|
|
400
|
-
else
|
|
401
|
-
line.push(cell);
|
|
402
|
-
}
|
|
403
|
-
out.push(line);
|
|
313
|
+
const out = [];
|
|
314
|
+
for (let y = 0;y < grid.length; y += 2) {
|
|
315
|
+
const top = grid[y];
|
|
316
|
+
const bottom = grid[y + 1] ?? [];
|
|
317
|
+
const line = [];
|
|
318
|
+
for (let x = 0;x < top.length; x++) {
|
|
319
|
+
const t = top[x];
|
|
320
|
+
const b = bottom[x];
|
|
321
|
+
const cell = !t && !b ? { text: " " } : t === b ? { text: "█", fg: t } : !t ? { text: "▄", fg: b } : !b ? { text: "▀", fg: t } : { text: "▀", fg: t, bg: b };
|
|
322
|
+
const last = line.at(-1);
|
|
323
|
+
if (last && last.fg === cell.fg && last.bg === cell.bg)
|
|
324
|
+
last.text += cell.text;
|
|
325
|
+
else
|
|
326
|
+
line.push(cell);
|
|
404
327
|
}
|
|
405
|
-
|
|
328
|
+
out.push(line);
|
|
329
|
+
}
|
|
330
|
+
return out;
|
|
406
331
|
}
|
|
407
|
-
/** 动画帧之间隔多久 */
|
|
408
332
|
export const FRAME_MS = 50;
|
|
409
|
-
/**
|
|
410
|
-
* 不在运行时,下一次需要重画还要多久(毫秒):缓动没结束、正在眨眼或瞟眼时按帧画,
|
|
411
|
-
* 否则等到下一次眨眼、瞟眼或笑完。运行中由 App 定时重画,用不到这个
|
|
412
|
-
*/
|
|
413
333
|
export function nextChange(mood, now, doneAt, moving = false) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
return Math.max(16, Math.min(BLINK_EVERY - tb, toGlance));
|
|
334
|
+
if (moving)
|
|
335
|
+
return FRAME_MS;
|
|
336
|
+
if (mood === "asking" || mood === "happy") {
|
|
337
|
+
const end = mood === "happy" && doneAt !== undefined ? doneAt + HAPPY_MS - now : 1 / 0;
|
|
338
|
+
return Math.max(16, Math.min(FRAME_MS, end));
|
|
339
|
+
}
|
|
340
|
+
const tb = now % BLINK_EVERY;
|
|
341
|
+
if (tb < 2 * BLINK_MS + 90)
|
|
342
|
+
return FRAME_MS;
|
|
343
|
+
const tg = now % GLANCE_EVERY;
|
|
344
|
+
const toGlance = tg < GLANCE[0] ? GLANCE[0] - tg : tg < GLANCE[1] ? GLANCE[1] - tg : GLANCE_EVERY - tg + GLANCE[0];
|
|
345
|
+
return Math.max(16, Math.min(BLINK_EVERY - tb, toGlance));
|
|
427
346
|
}
|
|
428
|
-
// ---------- 终端标题 ----------
|
|
429
|
-
/** jade 的标志:一块玉 */
|
|
430
347
|
export const LOGO = "◆";
|
|
431
348
|
const SPIN = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
432
|
-
/**
|
|
433
|
-
* 终端标签页标题:空闲时是标志,运行中换成转圈,等用户时加感叹号,在别的标签页里也能看出 jade 在做什么。
|
|
434
|
-
* dir 是当前目录的名字
|
|
435
|
-
*/
|
|
436
349
|
export function title(mood, dir, now) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
: SPIN[Math.floor(now / 250) % SPIN.length];
|
|
440
|
-
return `${mark} jade · ${dir}`;
|
|
350
|
+
const mark = mood === "asking" ? `${LOGO}!` : mood === "idle" || mood === "happy" ? LOGO : SPIN[Math.floor(now / 250) % SPIN.length];
|
|
351
|
+
return `${mark} jade · ${dir}`;
|
|
441
352
|
}
|