Skip to content

Commit fac66d4

Browse files
vignesh07steipete
authored andcommitted
TUI: waiting shimmer helper + tests
1 parent 2e99369 commit fac66d4

3 files changed

Lines changed: 97 additions & 34 deletions

File tree

‎src/tui/tui-waiting.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { buildWaitingStatusMessage, pickWaitingPhrase } from "./tui-waiting.js";
4+
5+
const theme = {
6+
dim: (s: string) => `<d>${s}</d>`,
7+
bold: (s: string) => `<b>${s}</b>`,
8+
accentSoft: (s: string) => `<a>${s}</a>`,
9+
} as any;
10+
11+
describe("tui-waiting", () => {
12+
it("pickWaitingPhrase rotates every 10 ticks", () => {
13+
const phrases = ["a", "b", "c"];
14+
expect(pickWaitingPhrase(0, phrases)).toBe("a");
15+
expect(pickWaitingPhrase(9, phrases)).toBe("a");
16+
expect(pickWaitingPhrase(10, phrases)).toBe("b");
17+
expect(pickWaitingPhrase(20, phrases)).toBe("c");
18+
expect(pickWaitingPhrase(30, phrases)).toBe("a");
19+
});
20+
21+
it("buildWaitingStatusMessage includes shimmer markup and metadata", () => {
22+
const msg = buildWaitingStatusMessage({
23+
theme,
24+
tick: 1,
25+
elapsed: "3s",
26+
connectionStatus: "connected",
27+
phrases: ["hello"],
28+
});
29+
30+
expect(msg).toContain("connected");
31+
expect(msg).toContain("3s");
32+
// text is wrapped per-char; check it appears in order
33+
expect(msg).toContain("h");
34+
expect(msg).toContain("e");
35+
expect(msg).toContain("l");
36+
expect(msg).toContain("o");
37+
// shimmer should contain both highlighted and dim parts
38+
expect(msg).toContain("<b><a>");
39+
expect(msg).toContain("<d>");
40+
});
41+
});

‎src/tui/tui-waiting.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { ClawdbotTheme } from "./theme/theme.js";
2+
3+
export const defaultWaitingPhrases = [
4+
"flibbertigibbeting",
5+
"kerfuffling",
6+
"dillydallying",
7+
"twiddling thumbs",
8+
"noodling",
9+
"bamboozling",
10+
"moseying",
11+
"hobnobbing",
12+
"pondering",
13+
"conjuring",
14+
];
15+
16+
export function pickWaitingPhrase(tick: number, phrases = defaultWaitingPhrases) {
17+
const idx = Math.floor(tick / 10) % phrases.length;
18+
return phrases[idx] ?? phrases[0] ?? "waiting";
19+
}
20+
21+
export function shimmerText(theme: ClawdbotTheme, text: string, tick: number) {
22+
const width = 6;
23+
const hi = (ch: string) => theme.bold(theme.accentSoft(ch));
24+
25+
const pos = tick % (text.length + width);
26+
const start = Math.max(0, pos - width);
27+
const end = Math.min(text.length - 1, pos);
28+
29+
let out = "";
30+
for (let i = 0; i < text.length; i++) {
31+
const ch = text[i];
32+
out += i >= start && i <= end ? hi(ch) : theme.dim(ch);
33+
}
34+
return out;
35+
}
36+
37+
export function buildWaitingStatusMessage(params: {
38+
theme: ClawdbotTheme;
39+
tick: number;
40+
elapsed: string;
41+
connectionStatus: string;
42+
phrases?: string[];
43+
}) {
44+
const phrase = pickWaitingPhrase(params.tick, params.phrases);
45+
const cute = shimmerText(params.theme, `${phrase}…`, params.tick);
46+
return `${cute} • ${params.elapsed} | ${params.connectionStatus}`;
47+
}

‎src/tui/tui.ts‎

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { editorTheme, theme } from "./theme/theme.js";
2222
import { createCommandHandlers } from "./tui-command-handlers.js";
2323
import { createEventHandlers } from "./tui-event-handlers.js";
2424
import { formatTokens } from "./tui-formatters.js";
25+
import { buildWaitingStatusMessage } from "./tui-waiting.js";
2526
import { createOverlayHandlers } from "./tui-overlays.js";
2627
import { createSessionActions } from "./tui-session-actions.js";
2728
import type {
@@ -286,49 +287,23 @@ export async function runTui(opts: TuiOptions) {
286287
statusContainer.addChild(statusLoader);
287288
};
288289

289-
const waitingPhrases = [
290-
"flibbertigibbeting",
291-
"kerfuffling",
292-
"dillydallying",
293-
"twiddling thumbs",
294-
"noodling",
295-
"bamboozling",
296-
"moseying",
297-
"hobnobbing",
298-
"pondering",
299-
"conjuring",
300-
"vibing",
301-
"clawding",
302-
];
303-
304290
let waitingTick = 0;
305291
let waitingTimer: NodeJS.Timeout | null = null;
306292

307-
const shimmerWaitingText = (text: string, tick: number) => {
308-
const width = 6;
309-
const hi = (ch: string) => theme.bold(theme.accentSoft(ch));
310-
311-
const pos = tick % (text.length + width);
312-
const start = Math.max(0, pos - width);
313-
const end = Math.min(text.length - 1, pos);
314-
315-
let out = "";
316-
for (let i = 0; i < text.length; i++) {
317-
const ch = text[i];
318-
out += i >= start && i <= end ? hi(ch) : theme.dim(ch);
319-
}
320-
return out;
321-
};
322-
323293
const updateBusyStatusMessage = () => {
324294
if (!statusLoader || !statusStartedAt) return;
325295
const elapsed = formatElapsed(statusStartedAt);
326296

327297
if (activityStatus === "waiting") {
328298
waitingTick++;
329-
const phrase = waitingPhrases[Math.floor(waitingTick / 10) % waitingPhrases.length];
330-
const cute = shimmerWaitingText(`${phrase}…`, waitingTick);
331-
statusLoader.setMessage(`${cute} • ${elapsed} | ${connectionStatus}`);
299+
statusLoader.setMessage(
300+
buildWaitingStatusMessage({
301+
theme,
302+
tick: waitingTick,
303+
elapsed,
304+
connectionStatus,
305+
}),
306+
);
332307
return;
333308
}
334309

0 commit comments

Comments
 (0)