/** * Plugin/Callback interface for ink-terminal. * * All app-specific dependencies are injected via configure(), * rather than hardcoded imports. This keeps the rendering engine * decoupled from any specific application. * * All callbacks are on COLD paths (logging, lifecycle). * Hot paths (cellAt, diffEach, setCellAt, blitRegion) have * ZERO external dependency calls. */ export type InkTerminalConfig = { /** * Debug logging function. Called throughout the rendering pipeline. * Default: no-op * Replaces: src/utils/debug.ts logForDebugging (used in 7 files) */ logForDebugging?: (message: string, opts?: { level: string }) => void /** * Error logging function. * Default: console.error * Replaces: src/utils/log.ts logError (used in 2 files) */ logError?: (message: string, ...args: unknown[]) => void /** * Terminal name for capability detection. * Default: auto-detect from TERM_PROGRAM env var * Replaces: src/utils/env.ts env.terminal */ terminalName?: string /** * Called before each frame render. * Default: no-op * Replaces: src/bootstrap/state.ts flushInteractionTime */ onBeforeRender?: () => void /** * Called when scroll activity occurs. * Default: no-op * Replaces: src/bootstrap/state.ts markScrollActivity */ onScrollActivity?: () => void /** * Called when interaction time should be updated. * Default: no-op * Replaces: src/bootstrap/state.ts updateLastInteractionTime */ onInteraction?: (immediate?: boolean) => void /** * Environment variable truthiness check. * Default: checks '1', 'true', 'yes' * Replaces: src/utils/envUtils.ts isEnvTruthy */ isEnvTruthy?: (value: string | boolean | undefined) => boolean /** * Called when first stdin data is received. * Default: no-op * Replaces: src/utils/earlyInput.ts stopCapturingEarlyInput */ onFirstInput?: () => void /** * Whether mouse clicks are disabled. * Default: () => false * Replaces: src/utils/fullscreen.ts isMouseClicksDisabled */ isMouseClicksDisabled?: () => boolean } // Module-level singleton with sensible defaults let _config: Required = { logForDebugging: () => {}, logError: console.error, terminalName: process.env.TERM_PROGRAM ?? '', onBeforeRender: () => {}, onScrollActivity: () => {}, onInteraction: () => {}, isEnvTruthy: (v) => v === true || v === '1' || v === 'true' || v === 'yes', onFirstInput: () => {}, isMouseClicksDisabled: () => false, } /** * Configure ink-terminal with application-specific callbacks. * Call this once during application bootstrap, before any rendering. * * @example * ```typescript * import { configure } from 'ink-terminal' * * configure({ * logForDebugging: (msg) => console.debug(`[ink] ${msg}`), * terminalName: 'my-app', * }) * ``` */ export function configure(config: Partial): void { _config = { ..._config, ...config } } /** * Get the current configuration. * Used internally by rendering engine modules. */ export function getConfig(): Required { return _config }