"use client"; import { useEffect, useState } from "react"; import type { TermLine } from "@/i18n/dictionaries/en"; const TYPE_SPEED = 26; const LINE_PAUSE = 320; export default function Terminal({ title, lines }: { title: string; lines: TermLine[] }) { const [step, setStep] = useState(0); const [chars, setChars] = useState(0); useEffect(() => { if (step >= lines.length) return; const line = lines[step]; if (line.kind === "cmd") { if (chars < line.text.length) { const id = setTimeout(() => setChars((c) => c + 1), TYPE_SPEED); return () => clearTimeout(id); } const id = setTimeout(() => { setStep((s) => s + 1); setChars(0); }, LINE_PAUSE); return () => clearTimeout(id); } const id = setTimeout(() => setStep((s) => s + 1), LINE_PAUSE); return () => clearTimeout(id); }, [step, chars, lines]); const done = step >= lines.length; return (
{title}
{lines.slice(0, step).map((line, i) => ( ))} {!done && lines[step] && ( )} {done && (

)}
); } function Prompt() { return $; } function TermLineRow({ line, cursor }: { line: TermLine; cursor?: boolean }) { const cursorEl = cursor && ( ); if (line.kind === "cmd") { return (

{line.text} {cursorEl}

); } if (line.kind === "ok") { return (

{line.text} {cursorEl}

); } return (

{line.text} {cursorEl}

); }