import type { SettingRow } from "../model/settings.ts"; import { colors } from "./theme.ts"; /** Settings in place of the conversation: tui3's own (cycled with enter or a click), then the server's, read-only. */ export function SettingsView(props: { readonly rows: readonly SettingRow[]; readonly server: readonly { label: string; value: string }[]; readonly serverStatus: "loading" | "live" | "error"; /** Usage limits and the last 30 days' totals, read-only; left out until known. */ readonly usage?: readonly { label: string; value: string }[]; readonly selected: number; readonly path: string; readonly onCycle: (index: number) => void; }) { const usage = props.usage ?? []; const labelWidth = Math.max(...props.rows.map((row) => row.label.length), ...props.server.map((line) => line.label.length), ...usage.map((line) => line.label.length)) + 2; return ( Settings esc close {`tui3 · ${props.path}`} {props.rows.map((row, index) => { const selected = index === props.selected; return ( props.onCycle(index)}> {`${selected ? "▸ " : " "}${row.label.padEnd(labelWidth)}`} {row.value} {` ${row.help}`} ); })} T3 Code · change these in the app {props.serverStatus === "loading" ? Loading… : null} {props.serverStatus === "error" ? Could not read the server's settings. : null} {props.server.map((line) => ( {` ${line.label.padEnd(labelWidth)}`} {line.value} ))} {usage.length > 0 ? Usage : null} {usage.map((line) => ( {` ${line.label.padEnd(labelWidth)}`} {line.value} ))} ); }