/** @jsxRuntime automatic */ /** @jsxImportSource @alchemy.run/sigil */ import type { ReactNode } from "react"; import { statusPaint, type StatusVariant } from "../../../Util/Theme.ts"; import { useCliEnvironment } from "./Environment.tsx"; import { Box } from "./Layout.tsx"; import { Text } from "./Typography.tsx"; export interface ProgressBarProps { /** Completion ratio. Values outside 0..1 are clamped. */ readonly value: number; /** Width in terminal cells (default: 24). */ readonly width?: number; readonly showPercent?: boolean; readonly label?: ReactNode; readonly detail?: ReactNode; readonly variant?: StatusVariant; } /** Left-to-right progress using half/full Braille cells and an ASCII fallback. */ export function ProgressBar({ value, width = 24, showPercent = true, label, detail, variant = "success", }: ProgressBarProps) { const { unicode } = useCliEnvironment(); const ratio = Math.max(0, Math.min(1, value)); const cells = Math.max(1, Math.floor(width)); const steps = Math.floor(cells * ratio * (unicode ? 2 : 1)); const filled = unicode ? Math.floor(steps / 2) : steps; const partial = unicode && steps % 2 !== 0 ? "⡇" : ""; const remaining = cells - filled - (partial === "" ? 0 : 1); return ( [ {(unicode ? "⣿" : "#").repeat(filled)} {partial} {(unicode ? " " : ".").repeat(remaining)}] {showPercent ? {`${Math.round(ratio * 100)}%`.padStart(4)} : null} {label === undefined ? null : {label}} {detail === undefined ? null : {detail}} ); }