"use client"; import * as React from "react"; import { cn } from "./lib/utils"; export interface ConsoleLine { id: string; text: string; tone?: "input" | "output" | "error" | "accent"; } export interface ConsolePanelProps extends Omit, "onSubmit"> { lines: ConsoleLine[]; prompt?: string; onSubmit?: (command: string) => void; } /** Interactive console panel: terminal logs + command prompt. */ export function ConsolePanel({ lines = [], prompt = ">", onSubmit, className, ...props }: ConsolePanelProps) { const [input, setInput] = React.useState(""); const scrollRef = React.useRef(null); const inputRef = React.useRef(null); React.useEffect(() => { scrollRef.current?.scrollTo({ top: scrollRef.current.scrollHeight }); }, [lines.length]); const toneClass = { input: "text-accent", output: "text-foreground/90", error: "text-destructive", accent: "text-success", }; return (
inputRef.current?.focus()} {...props} >
console
{lines.map((line, idx) => (
{line.tone === "input" && {prompt}} {line.text}
))}
setInput(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter" && input.trim()) { onSubmit?.(input.trim()); setInput(""); } }} className="min-w-0 flex-1 bg-transparent text-foreground focus-visible:outline-none" aria-label="Command prompt input" spellCheck={false} autoComplete="off" />
); }