/** * @license * Copyright 2025 Vybestack LLC * SPDX-License-Identifier: Apache-2.0 */ import type React from 'react'; import { Box, Text } from 'ink'; import { theme } from '../semantic-colors.js'; import { getBorderStyle } from '../contexts/UnicodeRenderingContext.js'; export interface Column { key: string; header: React.ReactNode; width?: number; flexGrow?: number; flexShrink?: number; flexBasis?: number | string; renderCell?: (item: T) => React.ReactNode; } interface TableProps { data: T[]; columns: Array>; } /** * Resolve the Ink `flexBasis` for a column. An explicit `flexBasis` wins; * otherwise a column with a positive width flexes from its width (`undefined`) * while a column without a usable width starts from `0`. */ function resolveFlexBasis(col: Column): number | string | undefined { if (col.flexBasis !== undefined) { return col.flexBasis; } return col.width === undefined || col.width === 0 ? 0 : undefined; } export function Table({ data, columns }: TableProps) { return ( {/* Header */} {columns.map((col, index) => ( {typeof col.header === 'string' ? ( {col.header} ) : ( col.header )} ))} {/* Divider */} {/* Rows */} {data.map((item, rowIndex) => ( {columns.map((col, colIndex) => ( {col.renderCell ? ( col.renderCell(item) ) : ( {String((item as Record)[col.key])} )} ))} ))} ); }