Files
llmx/codex-cli/src/components/vendor/ink-spinner.tsx
Ilan Bigio 59a180ddec Initial commit
Signed-off-by: Ilan Bigio <ilan@openai.com>
2025-04-16 12:56:08 -04:00

37 lines
890 B
TypeScript

import { Text } from "ink";
import React, { useState } from "react";
import { useInterval } from "use-interval";
const spinnerTypes: Record<string, string[]> = {
dots: ["⢎ ", "⠎⠁", "⠊⠑", "⠈⠱", " ⡱", "⢀⡰", "⢄⡠", "⢆⡀"],
ball: [
"( ● )",
"( ● )",
"( ● )",
"( ● )",
"( ●)",
"( ● )",
"( ● )",
"( ● )",
"( ● )",
"(● )",
],
};
export default function Spinner({
type = "dots",
}: {
type?: string;
}): JSX.Element {
const frames = spinnerTypes[type || "dots"] || [];
const interval = 80;
const [frame, setFrame] = useState(0);
useInterval(() => {
setFrame((previousFrame) => {
const isLastFrame = previousFrame === frames.length - 1;
return isLastFrame ? 0 : previousFrame + 1;
});
}, interval);
return <Text>{frames[frame]}</Text>;
}