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 = [
|
export const defaultWaitingPhrases = [
|
||||||
"flibbertigibbeting",
|
"flibbertigibbeting",
|
||||||
@@ -18,7 +22,7 @@ export function pickWaitingPhrase(tick: number, phrases = defaultWaitingPhrases)
|
|||||||
return phrases[idx] ?? phrases[0] ?? "waiting";
|
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 width = 6;
|
||||||
const hi = (ch: string) => theme.bold(theme.accentSoft(ch));
|
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: {
|
export function buildWaitingStatusMessage(params: {
|
||||||
theme: ClawdbotTheme;
|
theme: MinimalTheme;
|
||||||
tick: number;
|
tick: number;
|
||||||
elapsed: string;
|
elapsed: string;
|
||||||
connectionStatus: string;
|
connectionStatus: string;
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ import { editorTheme, theme } from "./theme/theme.js";
|
|||||||
import { createCommandHandlers } from "./tui-command-handlers.js";
|
import { createCommandHandlers } from "./tui-command-handlers.js";
|
||||||
import { createEventHandlers } from "./tui-event-handlers.js";
|
import { createEventHandlers } from "./tui-event-handlers.js";
|
||||||
import { formatTokens } from "./tui-formatters.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 { createOverlayHandlers } from "./tui-overlays.js";
|
||||||
import { createSessionActions } from "./tui-session-actions.js";
|
import { createSessionActions } from "./tui-session-actions.js";
|
||||||
import type {
|
import type {
|
||||||
@@ -289,6 +292,7 @@ export async function runTui(opts: TuiOptions) {
|
|||||||
|
|
||||||
let waitingTick = 0;
|
let waitingTick = 0;
|
||||||
let waitingTimer: NodeJS.Timeout | null = null;
|
let waitingTimer: NodeJS.Timeout | null = null;
|
||||||
|
let waitingPhrase: string | null = null;
|
||||||
|
|
||||||
const updateBusyStatusMessage = () => {
|
const updateBusyStatusMessage = () => {
|
||||||
if (!statusLoader || !statusStartedAt) return;
|
if (!statusLoader || !statusStartedAt) return;
|
||||||
@@ -302,6 +306,7 @@ export async function runTui(opts: TuiOptions) {
|
|||||||
tick: waitingTick,
|
tick: waitingTick,
|
||||||
elapsed,
|
elapsed,
|
||||||
connectionStatus,
|
connectionStatus,
|
||||||
|
phrases: waitingPhrase ? [waitingPhrase] : undefined,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@@ -326,6 +331,16 @@ export async function runTui(opts: TuiOptions) {
|
|||||||
|
|
||||||
const startWaitingTimer = () => {
|
const startWaitingTimer = () => {
|
||||||
if (waitingTimer) return;
|
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(() => {
|
waitingTimer = setInterval(() => {
|
||||||
if (activityStatus !== "waiting") return;
|
if (activityStatus !== "waiting") return;
|
||||||
updateBusyStatusMessage();
|
updateBusyStatusMessage();
|
||||||
@@ -336,6 +351,7 @@ export async function runTui(opts: TuiOptions) {
|
|||||||
if (!waitingTimer) return;
|
if (!waitingTimer) return;
|
||||||
clearInterval(waitingTimer);
|
clearInterval(waitingTimer);
|
||||||
waitingTimer = null;
|
waitingTimer = null;
|
||||||
|
waitingPhrase = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderStatus = () => {
|
const renderStatus = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user