import React, { useEffect, useRef } from 'react'; import { SerialLogEntry, ViewMode } from '../types'; import { formatTime, uInt8ArrayToAscii, uInt8ArrayToHex } from '../utils'; interface TerminalProps { title: string; logs: SerialLogEntry[]; viewMode: ViewMode; isConnected: boolean; onClear: () => void; onSave: () => void; className?: string; headerControls?: React.ReactNode; } const Terminal: React.FC = ({ title, logs, viewMode, isConnected, onClear, onSave, className, headerControls }) => { const bottomRef = useRef(null); useEffect(() => { // Auto-scroll to bottom on new logs if (bottomRef.current) { bottomRef.current.scrollIntoView({ behavior: "smooth" }); } }, [logs]); return (
{/* Terminal Header */}

{title}

{/* Custom Header Controls (e.g. Baud Rate, Connect Button) */} {headerControls && (
{headerControls}
)}
{/* Save Button (Icon Only) */} {/* Clear Button (Icon Only - Trash) */}
{/* Log Area */}
{logs.length === 0 && (

Waiting for data...

)} {logs.map((log) => (
[{formatTime(log.timestamp)}] {log.direction} {viewMode === ViewMode.ASCII ? uInt8ArrayToAscii(log.data) : uInt8ArrayToHex(log.data) }
))}
); }; export default Terminal;