import React from "react" import { Box, Text, useStdout } from "ink" import type { UiCommand } from "../commands" export function CommandInput(props: { selected: number; message?: string; commands: UiCommand[] }) { const { stdout } = useStdout() const commands = props.commands const commandWidth = Math.max(22, ...commands.map((command) => command.name.length + 4)) const descriptionWidth = Math.max(20, (stdout.columns ?? 100) - commandWidth - 6) return ( {commands.map((command, index) => ( {props.selected === index ? "› " : " "} {command.name} {truncate(command.description, descriptionWidth)} ))} {props.message && ( {"─".repeat(Math.min(60, stdout.columns ?? 60))} {"⚡ "}{props.message} )} ) } function truncate(value: string, width: number) { return value.length > width ? `${value.slice(0, Math.max(0, width - 1))}…` : value }