import type { ScrollBoxRenderable } from "@opentui/core"; import { useTerminalDimensions } from "@opentui/react"; import { useEffect, useRef } from "react"; import { TUI_COLORS } from "@/lib/tui/shared/colors"; interface OutputDrawerProps { output: string; sessionName: string | null; visible: boolean; focused?: boolean; } function hashLine(line: string, index: number): string { let hash = index; for (let i = 0; i < line.length; i++) { hash = (hash * 31 + line.charCodeAt(i)) | 0; } return hash.toString(36); } export function OutputDrawer({ output, sessionName, visible, focused = false }: OutputDrawerProps) { const { height: terminalHeight } = useTerminalDimensions(); const scrollboxRef = useRef(null); const drawerHeight = Math.max(8, Math.floor(terminalHeight * 0.4)); const lines = sessionName ? output.split("\n").filter((line) => line.trim()) : []; useEffect(() => { if (scrollboxRef.current && lines.length > 0) { scrollboxRef.current.scrollTop = scrollboxRef.current.scrollHeight; } }, [lines.length]); if (!visible) { return null; } const borderColor = focused ? TUI_COLORS.ui.borderFocused : TUI_COLORS.ui.border; const title = sessionName ? `Output ยท ${sessionName}` : "Output"; return ( {!sessionName ? ( No active session output ) : lines.length === 0 ? ( Waiting for output... ) : ( {lines.map((line, idx) => ( {line} ))} )} ); }