import React from 'react' import { Box, Text } from 'ink' import { theme } from '../theme.js' export interface KeyValueItem { /** * The label/key to display */ key: string /** * The value to display */ value: string | number | React.ReactNode /** * Optional custom color for the value */ valueColor?: string /** * Optional custom color for the key */ keyColor?: string /** * Whether this item should be visually separated from the next one */ separator?: boolean } export interface KeyValueProps { /** * Array of key-value pairs to display */ items: KeyValueItem[] /** * Width of the key column (defaults to auto-calculated) */ keyWidth?: number /** * Whether to show a title above the key-value pairs */ title?: string /** * Optional icon to show next to the title */ titleIcon?: string /** * Indentation level (0 = no indent, 1 = 2 spaces, 2 = 4 spaces, etc.) */ indent?: number } /** * KeyValue component for displaying label-value pairs in a consistent format. * Replaces manual console.log formatting with aligned key-value output. * * @example * ```tsx * * ``` */ export function KeyValue({ items, keyWidth, title, titleIcon, indent = 0, }: KeyValueProps): React.ReactElement { // Calculate max key width if not provided (including the colon) const maxKeyWidth = keyWidth || Math.max(...items.map((item) => item.key.length)) + 2 const indentSpaces = ' '.repeat(indent * 2) return ( {title && ( {titleIcon && {titleIcon} } {title} )} {items.map((item, index) => ( {indent > 0 && {indentSpaces}} {item.key}: {item.value} {item.separator && index < items.length - 1 && ( )} ))} ) }