TUI: pick waiting phrase once per waiting session
This commit is contained in:
committed by
Peter Steinberger
parent
fac66d4dda
commit
e85d2dff97
@@ -1,4 +1,8 @@
|
||||
import type { ClawdbotTheme } from "./theme/theme.js";
|
||||
type MinimalTheme = {
|
||||
dim: (s: string) => string;
|
||||
bold: (s: string) => string;
|
||||
accentSoft: (s: string) => string;
|
||||
};
|
||||
|
||||
export const defaultWaitingPhrases = [
|
||||
"flibbertigibbeting",
|
||||
@@ -18,7 +22,7 @@ export function pickWaitingPhrase(tick: number, phrases = defaultWaitingPhrases)
|
||||
return phrases[idx] ?? phrases[0] ?? "waiting";
|
||||
}
|
||||
|
||||
export function shimmerText(theme: ClawdbotTheme, text: string, tick: number) {
|
||||
export function shimmerText(theme: MinimalTheme, text: string, tick: number) {
|
||||
const width = 6;
|
||||
const hi = (ch: string) => theme.bold(theme.accentSoft(ch));
|
||||
|
||||
@@ -35,7 +39,7 @@ export function shimmerText(theme: ClawdbotTheme, text: string, tick: number) {
|
||||
}
|
||||
|
||||
export function buildWaitingStatusMessage(params: {
|
||||
theme: ClawdbotTheme;
|
||||
theme: MinimalTheme;
|
||||
tick: number;
|
||||
elapsed: string;
|
||||
connectionStatus: string;
|
||||
|
||||
@@ -22,7 +22,10 @@ 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 {
|
||||
buildWaitingStatusMessage,
|
||||
defaultWaitingPhrases,
|
||||
} from "./tui-waiting.js";
|
||||
import { createOverlayHandlers } from "./tui-overlays.js";
|
||||
import { createSessionActions } from "./tui-session-actions.js";
|
||||
import type {
|
||||
@@ -289,6 +292,7 @@ export async function runTui(opts: TuiOptions) {
|
||||
|
||||
let waitingTick = 0;
|
||||
let waitingTimer: NodeJS.Timeout | null = null;
|
||||
let waitingPhrase: string | null = null;
|
||||
|
||||
const updateBusyStatusMessage = () => {
|
||||
if (!statusLoader || !statusStartedAt) return;
|
||||
@@ -302,6 +306,7 @@ export async function runTui(opts: TuiOptions) {
|
||||
tick: waitingTick,
|
||||
elapsed,
|
||||
connectionStatus,
|
||||
phrases: waitingPhrase ? [waitingPhrase] : undefined,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
@@ -326,6 +331,16 @@ export async function runTui(opts: TuiOptions) {
|
||||
|
||||
const startWaitingTimer = () => {
|
||||
if (waitingTimer) return;
|
||||
|
||||
// Pick a phrase once per waiting session.
|
||||
if (!waitingPhrase) {
|
||||
const idx = Math.floor(Math.random() * defaultWaitingPhrases.length);
|
||||
waitingPhrase =
|
||||
defaultWaitingPhrases[idx] ?? defaultWaitingPhrases[0] ?? "waiting";
|
||||
}
|
||||
|
||||
waitingTick = 0;
|
||||
|
||||
waitingTimer = setInterval(() => {
|
||||
if (activityStatus !== "waiting") return;
|
||||
updateBusyStatusMessage();
|
||||
@@ -336,6 +351,7 @@ export async function runTui(opts: TuiOptions) {
|
||||
if (!waitingTimer) return;
|
||||
clearInterval(waitingTimer);
|
||||
waitingTimer = null;
|
||||
waitingPhrase = null;
|
||||
};
|
||||
|
||||
const renderStatus = () => {
|
||||
|
||||
Reference in New Issue
Block a user