/** * Main composable terminal hook. * * Orchestrates all terminal sub-hooks into a single unified API: * connection state, font size, pane management, dimensions, keyboard * shortcuts, and a `resttyProps` spread object for zero-config wiring. * * This is the recommended entry point for building custom terminal UIs. * * @module @mks2508/mks-ui/react/blocks/Terminal/hooks/useTerminal * * @example * ```tsx * // Tier 2: Composable with chrome * const terminal = useTerminal({ wsUrl: 'ws://localhost:3100/pty' }); * * } * footer={} * > * * * * // Tier 3: Fully custom layout * const terminal = useTerminal({ wsUrl: 'ws://...', keyboardShortcuts: true }); * *
* * {terminal.paneCount} panes, {terminal.dimensions.cols}×{terminal.dimensions.rows} *
* ``` */ import type { IResttyTerminalRef, ResttyPaneSplitDirection } from '../restty/ResttyTerminal.types'; import type { TTerminalConnectionStatusToken } from '../Terminal.tokens'; import type { ITerminalSettings } from './useTerminalSettings'; import { type ITerminalDimensions } from './useTerminalDimensions'; /** * Options for useTerminal. */ export interface IUseTerminalOptions { /** WebSocket URL for PTY connection. */ wsUrl?: string; /** Initial font size in CSS pixels. Defaults to value from useTerminalSettings. */ fontSize?: number; /** Enable keyboard shortcuts (default: false — opt-in to avoid conflicts). */ keyboardShortcuts?: boolean; /** Persist font size to localStorage (default: true). */ persistFontSize?: boolean; /** Called when PTY connection opens. */ onConnect?: () => void; /** Called when PTY connection closes. */ onDisconnect?: () => void; /** Called on connection error. */ onError?: (message: string) => void; /** Called when terminal grid dimensions change. */ onResize?: (cols: number, rows: number) => void; /** Called when a pane is split. */ onPaneSplit?: (sourceId: number, createdId: number, direction: string) => void; /** Called when a pane is closed. */ onPaneClose?: (paneId: number) => void; /** Called when a pane is created. */ onPaneCreated?: (paneId: number) => void; /** Called when the active pane changes. */ onActivePaneChange?: (paneId: number | null) => void; } /** * Props to spread onto ``. * * Contains all callback handlers wired to the composed hooks. * Spread with `{...terminal.resttyProps}` for zero-config wiring. */ export interface ITerminalResttyProps { /** WebSocket URL for PTY connection. */ wsUrl?: string; /** Font size in CSS pixels. */ fontSize: number; /** Resize handler. */ onResize: (cols: number, rows: number) => void; /** Connection open handler. */ onConnect: () => void; /** Connection close handler. */ onDisconnect: () => void; /** Error handler. */ onError: (message: string) => void; /** PTY status handler. */ onPtyStatus: (status: string) => void; /** Pane created handler. */ onPaneCreated: (paneId: number) => void; /** Pane closed handler. */ onPaneClosed: (paneId: number) => void; /** Pane split handler. */ onPaneSplit: (sourceId: number, createdId: number, direction: ResttyPaneSplitDirection) => void; /** Active pane change handler. */ onActivePaneChange: (paneId: number | null) => void; } /** * Return type for useTerminal. */ export interface IUseTerminalReturn { /** Ref to pass to ``. */ ref: React.RefObject; /** Current connection status. */ status: TTerminalConnectionStatusToken; /** Whether the PTY is connected. */ isConnected: boolean; /** Reconnect the PTY. */ reconnect: () => void; /** Disconnect the PTY. */ disconnect: () => void; /** Uptime in seconds since connection (null if not connected). */ uptimeSeconds: number | null; /** Current font size in CSS pixels. */ fontSize: number; /** Increase font size by 1. */ fontIncrease: () => void; /** Decrease font size by 1. */ fontDecrease: () => void; /** Set exact font size. */ setFontSize: (size: number) => void; /** Whether font is at minimum bound. */ isFontMin: boolean; /** Whether font is at maximum bound. */ isFontMax: boolean; /** Current number of panes. */ paneCount: number; /** Active pane ID (null if none). */ activePaneId: number | null; /** Split the active pane in the given direction. */ splitActive: (direction: 'horizontal' | 'vertical') => void; /** Split a specific pane by ID. */ splitPane: (paneId: number, direction: 'horizontal' | 'vertical') => void; /** Close a specific pane by ID. */ closePane: (paneId: number) => void; /** Set the active pane by ID. */ setActivePane: (paneId: number) => void; /** Current terminal grid dimensions. */ dimensions: ITerminalDimensions; /** Clear the terminal screen and scrollback. */ clear: () => void; /** Focus the terminal for keyboard input. */ focus: () => void; /** Send raw input to the terminal PTY. */ sendInput: (data: string) => void; /** Copy current text selection to clipboard. */ copySelection: () => Promise; /** Paste clipboard contents into the terminal. */ pasteClipboard: () => Promise; /** Global terminal settings snapshot. */ settings: ITerminalSettings; /** Pre-composed props to spread onto ``. */ resttyProps: ITerminalResttyProps; } /** * Main composable terminal hook. * * Composes `useTerminalConnection`, `useTerminalFontSize`, * `useTerminalPaneManager`, `useTerminalDimensions`, and * `useTerminalKeyboardShortcuts` into a single unified API. * * Returns everything needed to build a fully interactive terminal UI: * - **Connection** state + reconnect/disconnect * - **Font size** with increase/decrease/set * - **Pane management** with split/close/setActive * - **Dimensions** tracking (cols × rows) * - **Actions**: clear, focus, sendInput * - **`resttyProps`**: spread onto `` for zero-config wiring * * @param options - Terminal configuration * @returns Unified terminal state and controls * * @example * ```tsx * function MyTerminal() { * const terminal = useTerminal({ * wsUrl: 'ws://localhost:3100/pty', * keyboardShortcuts: true, * }); * * return ( *
*
* {terminal.isConnected ? 'Connected' : 'Disconnected'} * * * * *
* * {terminal.dimensions.cols}×{terminal.dimensions.rows} | {terminal.paneCount} panes *
* ); * } * ``` */ export declare function useTerminal(options?: IUseTerminalOptions): IUseTerminalReturn; //# sourceMappingURL=useTerminal.d.ts.map