/** * Column definition for table output. * * @typeParam T - The type of data items being rendered */ export interface ColumnDef { /** Column header label */ header: string; /** Function to extract display value from a data item */ get: (item: T) => string; /** Minimum width in characters (optional) */ minWidth?: number; /** Whether this column is only shown in extended mode (optional) */ extended?: boolean; } /** * Options for table rendering. */ export interface TableRenderOptions { /** Terminal width override (defaults to process.stdout.columns or 120) */ termWidth?: number; /** Column padding (defaults to 2) */ padding?: number; } /** * A reusable table renderer for CLI output. * * Handles dynamic column width calculation based on content and provides * consistent table formatting across all CLI commands. * * @typeParam T - The type of data items being rendered * * @example * ```typescript * // Define columns for your data type * const columns: Record> = { * id: { header: 'ID', get: (d) => d.id }, * name: { header: 'Name', get: (d) => d.name }, * status: { header: 'Status', get: (d) => d.status }, * }; * * // Create renderer and render data * const table = new TableRenderer(columns); * table.render(items, ['id', 'name', 'status']); * * // Or with custom options * table.render(items, ['id', 'name'], { padding: 3 }); * ``` */ export declare class TableRenderer { private columns; /** * Creates a new TableRenderer. * * @param columns - Column definitions keyed by column identifier */ constructor(columns: Record>); /** * Renders data as a formatted table to stdout. * * @param data - Array of data items to render * @param columnKeys - Array of column keys to display (in order) * @param options - Optional rendering options */ render(data: T[], columnKeys: string[], options?: TableRenderOptions): void; /** * Gets the list of available column keys. * * @returns Array of all column keys */ getColumnKeys(): string[]; /** * Gets column keys excluding extended columns. * * @returns Array of non-extended column keys */ getDefaultColumnKeys(): string[]; /** * Validates and filters column keys. * * @param requested - Requested column keys * @returns Valid column keys that exist in the columns definition */ validateColumnKeys(requested: string[]): string[]; /** * Calculates dynamic column widths based on content. * * @param data - Data items to measure * @param columnKeys - Columns to calculate widths for * @param padding - Padding to add to each column * @returns Map of column key to calculated width */ private calculateColumnWidths; } /** * Creates a TableRenderer instance. * * Convenience function for creating a table renderer. * * @typeParam T - The type of data items being rendered * @param columns - Column definitions * @returns A new TableRenderer instance * * @example * ```typescript * const table = createTable({ * name: { header: 'Name', get: (u) => u.name }, * email: { header: 'Email', get: (u) => u.email }, * }); * table.render(users, ['name', 'email']); * ``` */ export declare function createTable(columns: Record>): TableRenderer;