TUI: waiting shimmer helper + tests

This commit is contained in:
Vignesh Natarajan
2026-01-18 13:14:58 -08:00
committed by Peter Steinberger
parent 2e99369113
commit fac66d4dda
3 changed files with 97 additions and 34 deletions

View File

@@ -22,6 +22,7 @@ import { editorTheme, theme } from "./theme/theme.js";
import { createCommandHandlers } from "./tui-command-handlers.js";
import { createEventHandlers } from "./tui-event-handlers.js";
import { formatTokens } from "./tui-formatters.js";
import { buildWaitingStatusMessage } from "./tui-waiting.js";
import { createOverlayHandlers } from "./tui-overlays.js";
import { createSessionActions } from "./tui-session-actions.js";
import type {
@@ -286,49 +287,23 @@ export async function runTui(opts: TuiOptions) {
statusContainer.addChild(statusLoader);
};
const waitingPhrases = [
"flibbertigibbeting",
"kerfuffling",
"dillydallying",
"twiddling thumbs",
"noodling",
"bamboozling",
"moseying",
"hobnobbing",
"pondering",
"conjuring",
"vibing",
"clawding",
];
let waitingTick = 0;
let waitingTimer: NodeJS.Timeout | null = null;
const shimmerWaitingText = (text: string, tick: number) => {
const width = 6;
const hi = (ch: string) => theme.bold(theme.accentSoft(ch));
const pos = tick % (text.length + width);
const start = Math.max(0, pos - width);
const end = Math.min(text.length - 1, pos);
let out = "";
for (let i = 0; i < text.length; i++) {
const ch = text[i];
out += i >= start && i <= end ? hi(ch) : theme.dim(ch);
}
return out;
};
const updateBusyStatusMessage = () => {
if (!statusLoader || !statusStartedAt) return;
const elapsed = formatElapsed(statusStartedAt);
if (activityStatus === "waiting") {
waitingTick++;
const phrase = waitingPhrases[Math.floor(waitingTick / 10) % waitingPhrases.length];
const cute = shimmerWaitingText(`${phrase}`, waitingTick);
statusLoader.setMessage(`${cute}${elapsed} | ${connectionStatus}`);
statusLoader.setMessage(
buildWaitingStatusMessage({
theme,
tick: waitingTick,
elapsed,
connectionStatus,
}),
);
return;
}