feat(tui): match settings and export dialogs to new designs (#56099)

This commit is contained in:
Aarav Sareen
2026-10-20 15:27:46 +05:30
committed by GitHub
Unverified
parent 2b3fc31451
commit d249607e90
4 changed files with 164 additions and 34 deletions
+21 -3
View File
@@ -1,8 +1,10 @@
import { createMemo, createSignal } from "solid-js"
import { useConfig, useNewDesigns } from "../config"
import { useThemes } from "../context/theme"
import { DialogSelect } from "../ui/dialog-select"
import { useDialog, type DialogContext } from "../ui/dialog"
import { DialogSelect, DialogSelectChoice } from "../ui/dialog-select"
import { useToast } from "../ui/toast"
import { DialogThemeList } from "./dialog-theme-list"
type Setting = {
title: string
@@ -16,6 +18,8 @@ type Setting = {
max?: number
format?: (value: unknown) => string
keywords?: readonly string[]
/** Under the "new-designs" experiment, enter opens this picker instead of cycling. ←/→ still cycle. */
open?: (dialog: DialogContext) => void
}
export const settings: Setting[] = [
@@ -25,6 +29,10 @@ export const settings: Setting[] = [
path: ["theme", "name"],
default: "opencode",
keywords: ["color scheme", "colors"],
open: (dialog) =>
dialog.replace(() => (
<DialogThemeList onClose={() => dialog.replace(() => <DialogConfig current="theme.name" />)} />
)),
},
{
title: "Color mode",
@@ -333,6 +341,7 @@ export function settingID(setting: Setting) {
export function DialogConfig(props: { current?: string }) {
const config = useConfig()
const newDesigns = useNewDesigns()
const dialog = useDialog()
const toast = useToast()
const themes = useThemes()
const current = Math.max(
@@ -365,7 +374,12 @@ export function DialogConfig(props: { current?: string }) {
title: setting.title,
category: setting.category,
searchText: setting.keywords?.join(" "),
footer: display(setting),
footer: newDesigns() ? (
<DialogSelectChoice value={display(setting)} active={selected() === index} open={setting.open !== undefined} />
) : (
display(setting)
),
footerOverhang: newDesigns() ? 2 : undefined,
value: index,
})),
)
@@ -401,7 +415,11 @@ export function DialogConfig(props: { current?: string }) {
current={current}
filterThreshold={0.7}
onMove={(option) => setSelected(option.value)}
onSelect={(option) => void change(1, option.value)}
onSelect={(option) => {
const open = settings[option.value].open
if (newDesigns() && open) return open(dialog)
void change(1, option.value)
}}
footerHints={newDesigns() ? [] : [{ title: "change", label: "←/→" }]}
bindings={[
{
@@ -3,7 +3,8 @@ import { useThemes } from "../context/theme"
import { useDialog } from "../ui/dialog"
import { onCleanup } from "solid-js"
export function DialogThemeList() {
/** `onClose` returns to the caller, e.g. Settings, instead of closing every dialog. */
export function DialogThemeList(props: { onClose?: () => void }) {
const themes = useThemes()
const options = Object.keys(themes.all())
.sort((a, b) => a.localeCompare(b, undefined, { sensitivity: "base" }))
@@ -27,12 +28,14 @@ export function DialogThemeList() {
titlePlaceholder="Search themes"
options={options}
current={initial}
onCancel={props.onClose}
onMove={(opt) => {
themes.set(opt.value)
}}
onSelect={(opt) => {
themes.set(opt.value)
confirmed = true
if (props.onClose) return props.onClose()
dialog.clear()
}}
ref={(r) => {
+112 -26
View File
@@ -2,8 +2,9 @@ import { Keymap } from "../context/keymap"
import { useNewDesigns } from "../config"
import { useTheme } from "../context/theme"
import { DialogHeader, DialogLayout, type DialogContext } from "./dialog"
import { DialogSelect, DialogSelectChoice } from "./dialog-select"
import { createStore } from "solid-js/store"
import { For, Show } from "solid-js"
import { createMemo, createSignal, For, Show } from "solid-js"
export type ExportFormat = "markdown" | "json"
@@ -22,8 +23,110 @@ export type DialogExportOptionsProps = {
type Active = ExportFormat | "thinking" | "tools" | "sanitize" | "copy" | "export"
export function DialogExportOptions(props: DialogExportOptionsProps) {
const theme = useTheme().surface("dialog")
const newDesigns = useNewDesigns()
return (
<Show when={newDesigns()} fallback={<LegacyDialogExportOptions {...props} />}>
<DialogExportOptionsList {...props} />
</Show>
)
}
type Row = "format" | "thinking" | "tools" | "sanitize"
/** Export options as a list of values, under the "new-designs" experiment: ↑/↓ moves, ←/→ or space changes. */
function DialogExportOptionsList(props: DialogExportOptionsProps) {
const [store, setStore] = createStore({
format: "markdown" as ExportFormat,
thinking: props.defaultThinking,
tools: true,
sanitize: false,
})
const [selected, setSelected] = createSignal<Row>("format")
const confirm = (action: "copy" | "export") =>
props.onConfirm?.({
action,
format: store.format,
thinking: store.thinking,
tools: store.tools,
sanitize: store.sanitize,
})
const change = (row: Row) => {
if (row === "format") return setStore("format", store.format === "markdown" ? "json" : "markdown")
setStore(row, !store[row])
}
const include = (value: boolean) => (value ? "include" : "exclude")
const options = createMemo(() => [
{
title: "Format",
value: "format" as Row,
onSelect: () => change("format"),
footerOverhang: 2,
footer: <DialogSelectChoice value={store.format} active={selected() === "format"} />,
},
...(store.format === "markdown"
? [
{
title: "Thinking",
value: "thinking" as Row,
onSelect: () => change("thinking"),
category: "Options",
footerOverhang: 2,
footer: <DialogSelectChoice value={include(store.thinking)} active={selected() === "thinking"} />,
},
{
title: "Tools",
value: "tools" as Row,
onSelect: () => change("tools"),
category: "Options",
footerOverhang: 2,
footer: <DialogSelectChoice value={include(store.tools)} active={selected() === "tools"} />,
},
]
: [
{
title: "Sanitize",
value: "sanitize" as Row,
onSelect: () => change("sanitize"),
category: "Options",
footerOverhang: 2,
footer: <DialogSelectChoice value={store.sanitize ? "on" : "off"} active={selected() === "sanitize"} />,
},
]),
])
return (
<DialogSelect
title="Export session"
renderFilter={false}
footerGap={2}
options={options()}
onMove={(option) => setSelected(option.value)}
actions={[
{
command: "dialog.export.copy",
title: "copy",
bind: "c",
selection: "none",
group: "primary",
onTrigger: () => confirm("copy"),
},
]}
footerHints={[{ title: "save to file", label: "enter", group: "primary" }]}
bindings={[
{ bind: "left", title: "Previous value", group: "Dialog", run: () => change(selected()) },
{ bind: "right", title: "Next value", group: "Dialog", run: () => change(selected()) },
{ bind: "space", title: "Change export option", group: "Dialog", run: () => change(selected()) },
{ bind: "return", title: "Save to file", group: "Dialog", run: () => confirm("export") },
]}
/>
)
}
function LegacyDialogExportOptions(props: DialogExportOptionsProps) {
const theme = useTheme().surface("dialog")
// Same field styling as the question form: only the focused row is highlighted, and the
// mark alone shows what's checked.
const markColor = (active: boolean, checked: boolean) =>
@@ -60,7 +163,7 @@ export function DialogExportOptions(props: DialogExportOptionsProps) {
const move = (offset: number) => {
const options: Active[] =
store.format === "markdown" ? ["markdown", "json", "thinking", "tools"] : ["markdown", "json", "sanitize"]
const order: Active[] = newDesigns() ? options : [...options, "copy", "export"]
const order: Active[] = [...options, "copy", "export"]
setStore("active", order[(order.indexOf(store.active) + offset + order.length) % order.length])
}
@@ -69,21 +172,12 @@ export function DialogExportOptions(props: DialogExportOptionsProps) {
commands: [
{ bind: "tab", title: "Next export option", group: "Dialog", run: () => move(1) },
{ bind: "shift+tab", title: "Previous export option", group: "Dialog", run: () => move(-1) },
...(newDesigns()
? [
// The footer owns enter (save) and c (copy), so space toggles the focused option instead.
{ bind: "return", title: "Save to file", group: "Dialog", run: () => confirm("export") },
{ bind: "c", title: "Copy export", group: "Dialog", run: () => confirm("copy") },
{ bind: "space", title: "Toggle export option", group: "Dialog", run: activate },
]
: [
{
bind: "return",
title: "Select export option",
group: "Dialog",
run: activate,
},
]),
{
bind: "return",
title: "Select export option",
group: "Dialog",
run: activate,
},
],
}))
@@ -95,14 +189,6 @@ export function DialogExportOptions(props: DialogExportOptionsProps) {
return (
<DialogLayout
header={<DialogHeader title="Export session" />}
footer={{
actions: {
primary: [
{ title: "copy", key: "c", onTrigger: () => confirm("copy") },
{ title: "save to file", key: "enter", onTrigger: () => confirm("export") },
],
},
}}
legacyFooter={
<box flexDirection="row" justifyContent="flex-end" gap={1}>
<box
+27 -4
View File
@@ -28,6 +28,8 @@ export interface DialogSelectProps<T> {
titleView?: JSX.Element
/** Faint line below the title, under the "new-designs" experiment. Not shown with `searchInTitle`. */
description?: string
/** Blank rows above the footer under the "new-designs" experiment. Defaults to 1. */
footerGap?: number
placeholder?: string
footer?: JSX.Element
emptyView?: JSX.Element
@@ -101,6 +103,8 @@ export interface DialogSelectOption<T = any> {
details?: string[]
footer?: JSX.Element | string
footerColor?: RGBA
/** Cells the footer extends into the row's right padding, e.g. 2 for a `DialogSelectChoice` so its value lines up with plain footers. */
footerOverhang?: number
titleWidth?: number
truncateTitle?: boolean | "left"
category?: string
@@ -257,13 +261,15 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
const limit = createMemo(() => Math.floor(dimensions().height / 2) - 6)
// Under new designs an overflowing list gives its last row to a "…" indicator.
const overflows = createMemo(() => newDesigns() && rows() > limit())
const height = createMemo(() => Math.min(rows(), limit()) - (overflows() ? 1 : 0))
// Computed once here so per-row details do not each call useTerminalDimensions(),
// which registers one renderer resize listener per mounted row.
const detailsWidth = createMemo(() =>
dialogSelectContentWidth(Math.min(dialogWidth(dialog.size), dimensions().width)),
)
const [moreBelow, setMoreBelow] = createSignal(false)
// At the bottom of the list the "…" row hands its row back to the list, so the dialog keeps its height.
const ellipsis = () => overflows() && moreBelow()
const height = createMemo(() => Math.min(rows(), limit()) - (ellipsis() ? 1 : 0))
function updateMoreBelow() {
if (!scroll || scroll.isDestroyed) return
setMoreBelow(scroll.scrollTop + scroll.viewport.height < scroll.scrollHeight)
@@ -676,6 +682,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
return (
<DialogLayout
footerGap={props.footerGap}
header={
// Rows reserve a gutter, so the header and footer line up with the list's inset rather than the layout's.
<box paddingLeft={DIALOG_LIST_INSET - DIALOG_INSET} paddingRight={DIALOG_LIST_INSET - DIALOG_INSET}>
@@ -799,6 +806,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
flatten() ? (option.searchFooter ?? option.category ?? option.footer) : option.footer
}
footerColor={option.footerColor}
footerOverhang={option.footerOverhang}
titleWidth={option.titleWidth}
truncateTitle={option.truncateTitle}
description={option.description !== category ? option.description : undefined}
@@ -818,9 +826,9 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
)}
</For>
</scrollbox>
<Show when={overflows()}>
<Show when={ellipsis()}>
<box paddingLeft={DIALOG_LIST_INSET} flexShrink={0}>
<text fg={theme.text.faint}>{moreBelow() ? "…" : " "}</text>
<text fg={theme.text.faint}>…</text>
</box>
</Show>
{/* Reserved whenever any option has a detail, so the dialog does not resize as the selection moves. */}
@@ -845,6 +853,20 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
)
}
/**
* Trailing value of a row that can be changed, under the "new-designs" experiment. The selected row shows how:
* `‹ dark ›` cycles with ←/→, `opencode ↵` opens a picker. Other rows pad the value to the same width so it does
* not shift as the selection moves. Pass it with `footerOverhang: 2` so the value itself ends where plain footers do.
*/
export function DialogSelectChoice(props: { value: string; active: boolean; open?: boolean }) {
const theme = useTheme().surface("dialog")
const text = () => {
if (!props.active) return ` ${props.value} `
return props.open ? ` ${props.value} ↵` : `‹ ${props.value} ›`
}
return <span style={{ fg: props.active ? theme.text.action.primary.focused : theme.text.faint }}>{text()}</span>
}
function DialogSelectCategory(props: { title: string; first: boolean }) {
const theme = useTheme().surface("dialog")
const newDesigns = useNewDesigns()
@@ -865,6 +887,7 @@ function DialogSelectRow(props: {
current: boolean
footer?: JSX.Element | string
footerColor?: RGBA
footerOverhang?: number
titleWidth?: number
truncateTitle?: boolean | "left"
gutter?: (color: RGBA) => JSX.Element
@@ -930,7 +953,7 @@ function DialogSelectRow(props: {
</Show>
</text>
<Show when={props.footer}>
<box flexShrink={0}>
<box flexShrink={0} marginRight={props.footerOverhang ? -props.footerOverhang : undefined}>
<text fg={props.active || !props.footerColor ? secondary() : props.footerColor}>{props.footer}</text>
</box>
</Show>