import { Box, Text } from "../../ui"; import { t } from "../../i18n"; import { TextAttributes } from "../../ui"; import type { PaneSettingField } from "../../types/plugin"; import { colors } from "../../theme/colors"; import { useViewport } from "../../react/input"; import { DialogFrame, ListView } from "../ui"; import type { ListViewProps } from "../ui/list-view"; import { isPaneSettingDisabled, summarizePaneSettingValue } from "./value"; /** Terminal rows a settings dialog spends around its list: edge, frame, title, description. */ const TUI_DIALOG_LIST_CHROME_ROWS = 11; /** The most list rows a terminal settings dialog shows before the list scrolls. */ export function useTuiDialogListRows(): number { return Math.max(3, useViewport().height - TUI_DIALOG_LIST_CHROME_ROWS); } /** * A list in a terminal settings dialog. Past the rows the terminal has room * for it scrolls to the cursor instead of running under the dialog's edge, * and the highlighted row's description sits under it. */ export function TuiDialogList(props: ListViewProps) { const maxRows = useTuiDialogListRows(); const scrollable = props.items.length > maxRows; const description = props.selectedIndex >= 0 ? props.items[props.selectedIndex]?.description : undefined; return ( <> {description && ( <> {" "}{t(description)} )} ); } export function TuiUnavailablePaneSettingsDialog() { return ( {t("This pane is no longer configurable.")} ); } export function TuiPaneSettingsDialogBody({ title, fields, selectedIndex, settings, onSelect, onActivate, }: { title: string; fields: PaneSettingField[]; selectedIndex: number; settings: Record; onSelect: (index: number) => void; onActivate: (field: PaneSettingField | undefined) => void; }) { return ( ({ id: field.key, label: t(field.label), description: field.description ? t(field.description) : field.description, detail: summarizePaneSettingValue(field, settings[field.key]), disabled: isPaneSettingDisabled(field), }))} selectedIndex={selectedIndex} bgColor={colors.commandBg} onSelect={onSelect} onActivate={(_, index) => { onActivate(fields[index]); }} renderRow={(item, rowState) => ( {rowState.selected ? "▸ " : " "} {item.label} {item.detail} )} /> {fields.length === 0 && ( {t("No settings available.")} )} ); }