The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 56 lines 1.89 KB
Raw
1 /** @jsxRuntime automatic */
2 /** @jsxImportSource @alchemy.run/sigil */
3 import type { ReactNode } from "react";
4 import { statusPaint, type StatusVariant } from "../../../Util/Theme.ts";
5 import { useCliEnvironment } from "./Environment.tsx";
6 import { Box } from "./Layout.tsx";
7 import { Text } from "./Typography.tsx";
8
9 export interface ProgressBarProps {
10 /** Completion ratio. Values outside 0..1 are clamped. */
11 readonly value: number;
12 /** Width in terminal cells (default: 24). */
13 readonly width?: number;
14 readonly showPercent?: boolean;
15 readonly label?: ReactNode;
16 readonly detail?: ReactNode;
17 readonly variant?: StatusVariant;
18 }
19
20 /** Left-to-right progress using half/full Braille cells and an ASCII fallback. */
21 export function ProgressBar({
22 value,
23 width = 24,
24 showPercent = true,
25 label,
26 detail,
27 variant = "success",
28 }: ProgressBarProps) {
29 const { unicode } = useCliEnvironment();
30 const ratio = Math.max(0, Math.min(1, value));
31 const cells = Math.max(1, Math.floor(width));
32 const steps = Math.floor(cells * ratio * (unicode ? 2 : 1));
33 const filled = unicode ? Math.floor(steps / 2) : steps;
34 const partial = unicode && steps % 2 !== 0 ? "⡇" : "";
35 const remaining = cells - filled - (partial === "" ? 0 : 1);
36 return (
37 <Box
38 gap={1}
39 aria-role="progressbar"
40 aria-label={`${Math.round(ratio * 100)}%`}
41 aria-state={{ busy: ratio < 1 }}
42 >
43 <Text>
44 <Text tone="muted">[</Text>
45 <Text color={statusPaint(variant)}>
46 {(unicode ? "⣿" : "#").repeat(filled)}
47 {partial}
48 </Text>
49 <Text tone="muted">{(unicode ? " " : ".").repeat(remaining)}]</Text>
50 </Text>
51 {showPercent ? <Text tone="muted">{`${Math.round(ratio * 100)}%`.padStart(4)}</Text> : null}
52 {label === undefined ? null : <Text>{label}</Text>}
53 {detail === undefined ? null : <Text tone="muted">{detail}</Text>}
54 </Box>
55 );
56 }