"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 (
✓ {line.text} {cursorEl}
); } return (→ {line.text} {cursorEl}
); }