UNPKG

lorehub

Version:

Capture and surface the collective wisdom of your codebase

43 lines 1.92 kB
import React, { useState, useEffect } from 'react'; import { Box, Text } from 'ink'; export function Progress({ message, current, total, showSpinner = true }) { const [frame, setFrame] = useState(0); const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; useEffect(() => { if (!showSpinner) return; const timer = setInterval(() => { setFrame((prev) => (prev + 1) % spinnerFrames.length); }, 80); return () => clearInterval(timer); }, [showSpinner]); const hasProgress = current !== undefined && total !== undefined && total > 0; const percentage = hasProgress ? Math.round((current / total) * 100) : 0; const progressBarWidth = 20; const filled = hasProgress ? Math.round((current / total) * progressBarWidth) : 0; return (React.createElement(Box, { flexDirection: "column", marginY: 1 }, React.createElement(Box, null, showSpinner && React.createElement(Text, { color: "cyan" }, spinnerFrames[frame], " "), React.createElement(Text, null, message), hasProgress && React.createElement(Text, { dimColor: true }, " (", current, "/", total, ")")), hasProgress && (React.createElement(Box, { marginTop: 1 }, React.createElement(Text, null, "[", '█'.repeat(filled), '░'.repeat(progressBarWidth - filled), "] ", percentage, "%"))))); } export function Loading({ message = 'Loading...' }) { return (React.createElement(Box, { flexDirection: "column", alignItems: "center", justifyContent: "center", height: 20 }, React.createElement(Progress, { message: message }))); } //# sourceMappingURL=Progress.js.map