refactor(tui): move remaining dialogs onto DialogLayout (#55523)

This commit is contained in:
James Long
2026-10-15 13:11:49 -04:00
committed by GitHub
Unverified
parent 09a075d90c
commit 1d07373cae
8 changed files with 301 additions and 269 deletions
@@ -5,7 +5,7 @@ import { useConfig } from "../config"
import { Keymap } from "../context/keymap"
import type { TuiHighlight } from "../context/runtime"
import { useTheme } from "../context/theme"
import { DIALOG_INSET, DialogHeader, useDialog } from "../ui/dialog"
import { DIALOG_INSET, DialogBleed, DialogHeader, DialogLayout, useDialog } from "../ui/dialog"
import { getScrollAcceleration } from "../util/scroll"
export function DialogHighlights(props: { version: string; items: ReadonlyArray<TuiHighlight> }) {
@@ -33,56 +33,55 @@ export function DialogHighlights(props: { version: string; items: ReadonlyArray<
}))
return (
<box gap={1} paddingBottom={1}>
<DialogHeader newInset={DIALOG_INSET} title={`What's new in ${props.version}`} />
{/* The band owns the vertical padding so it stays visible while the highlights scroll. */}
<box backgroundColor={overlay.background.raised.high} paddingTop={1} paddingBottom={1}>
<scrollbox
ref={(element: ScrollBoxRenderable) => (scroll = element)}
maxHeight={maxHeight()}
contentOptions={{ minHeight: 0 }}
backgroundColor={overlay.background.raised.high}
scrollbarOptions={{ visible: false }}
scrollAcceleration={getScrollAcceleration(config)}
>
<box gap={1} paddingLeft={DIALOG_INSET} paddingRight={DIALOG_INSET}>
<For each={props.items}>
{(item) => (
<box>
<text attributes={TextAttributes.BOLD} fg={overlay.text.base}>
{item.title}
</text>
{/* Backticks mark code spans, which stand out from the muted description. */}
<text fg={overlay.text.muted} wrapMode="word">
<For each={item.body.split("`")}>
{(part, index) =>
index() % 2 === 1 ? <span style={{ fg: overlay.text.base }}>{part}</span> : part
}
</For>
</text>
</box>
)}
</For>
<DialogLayout
header={<DialogHeader title={`What's new in ${props.version}`} />}
footer={
<box flexDirection="row" justifyContent="space-between" alignItems="center">
<text fg={theme.text.muted}>↑/↓ scroll</text>
<box
paddingLeft={3}
paddingRight={3}
backgroundColor={theme.background.action.primary.focused}
onMouseUp={() => dialog.clear()}
>
<text fg={theme.text.action.primary.focused}>ok</text>
</box>
</scrollbox>
</box>
<box
flexDirection="row"
justifyContent="space-between"
alignItems="center"
paddingLeft={DIALOG_INSET}
paddingRight={DIALOG_INSET}
>
<text fg={theme.text.muted}>↑/↓ scroll</text>
<box
paddingLeft={3}
paddingRight={3}
backgroundColor={theme.background.action.primary.focused}
onMouseUp={() => dialog.clear()}
>
<text fg={theme.text.action.primary.focused}>ok</text>
</box>
</box>
</box>
}
>
{/* The band owns the vertical padding so it stays visible while the highlights scroll. */}
<DialogBleed>
<box backgroundColor={overlay.background.raised.high} paddingTop={1} paddingBottom={1}>
<scrollbox
ref={(element: ScrollBoxRenderable) => (scroll = element)}
maxHeight={maxHeight()}
contentOptions={{ minHeight: 0 }}
backgroundColor={overlay.background.raised.high}
scrollbarOptions={{ visible: false }}
scrollAcceleration={getScrollAcceleration(config)}
>
<box gap={1} paddingLeft={DIALOG_INSET} paddingRight={DIALOG_INSET}>
<For each={props.items}>
{(item) => (
<box>
<text attributes={TextAttributes.BOLD} fg={overlay.text.base}>
{item.title}
</text>
{/* Backticks mark code spans, which stand out from the muted description. */}
<text fg={overlay.text.muted} wrapMode="word">
<For each={item.body.split("`")}>
{(part, index) =>
index() % 2 === 1 ? <span style={{ fg: overlay.text.base }}>{part}</span> : part
}
</For>
</text>
</box>
)}
</For>
</box>
</scrollbox>
</box>
</DialogBleed>
</DialogLayout>
)
}
@@ -21,7 +21,15 @@ import { useClient } from "../context/client"
import { Keymap } from "../context/keymap"
import { useLocation } from "../context/location"
import { useTheme } from "../context/theme"
import { DIALOG_INSET, DIALOG_LIST_INSET, DialogFooter, DialogHeader, useDialog } from "../ui/dialog"
import {
DIALOG_INSET,
DIALOG_LIST_INSET,
DialogBleed,
DialogFooter,
DialogHeader,
DialogLayout,
useDialog,
} from "../ui/dialog"
import { DialogPrompt } from "../ui/dialog-prompt"
import { DialogSelect } from "../ui/dialog-select"
import { Link } from "../ui/link"
@@ -509,21 +517,22 @@ function CommandView(props: { title: string; output: string; message: string })
const overlayTheme = useTheme()
onMount(() => dialog.setSize("large"))
return (
<box gap={1} paddingBottom={1}>
<DialogHeader newInset={DIALOG_INSET} title={props.title} closeLabel="esc close" />
<box
backgroundColor={overlayTheme.background.raised.high}
paddingLeft={DIALOG_INSET}
paddingRight={DIALOG_INSET}
paddingTop={1}
paddingBottom={1}
>
<text fg={overlayTheme.text.base}>{props.output.trim()}</text>
</box>
<box paddingLeft={DIALOG_INSET} paddingRight={DIALOG_INSET}>
<DialogLayout header={<DialogHeader title={props.title} closeLabel="esc close" />}>
<box gap={1}>
<DialogBleed>
<box
backgroundColor={overlayTheme.background.raised.high}
paddingLeft={DIALOG_INSET}
paddingRight={DIALOG_INSET}
paddingTop={1}
paddingBottom={1}
>
<text fg={overlayTheme.text.base}>{props.output.trim()}</text>
</box>
</DialogBleed>
<text fg={theme.text.muted}>{props.message}</text>
</box>
</box>
</DialogLayout>
)
}
@@ -5,7 +5,7 @@ import { createStore } from "solid-js/store"
import { FilePath } from "../ui/file-path"
import { useTheme } from "../context/theme"
import { useConfig } from "../config"
import { DIALOG_INSET, DialogHeader, useDialog, type DialogContext } from "../ui/dialog"
import { DIALOG_INSET, DialogBleed, DialogHeader, DialogLayout, useDialog, type DialogContext } from "../ui/dialog"
import { getScrollAcceleration } from "../util/scroll"
const options = ["no", "yes"] as const
@@ -72,71 +72,72 @@ export function DialogWorkspaceFileChanges(props: {
})
return (
<box gap={1}>
<DialogHeader newInset={DIALOG_INSET} title={props.title ?? "File Changes Found"} />
<box paddingLeft={DIALOG_INSET} paddingRight={DIALOG_INSET}>
<DialogLayout
header={<DialogHeader title={props.title ?? "File Changes Found"} />}
footer={
<box flexDirection="row" justifyContent="flex-end">
<For each={options}>
{(item) => (
<box
paddingLeft={2}
paddingRight={2}
backgroundColor={item === store.active ? theme.background.action.primary.focused : undefined}
onMouseUp={() => {
setStore("active", item)
props.onSelect(item)
dialog.clear()
}}
>
<text fg={item === store.active ? theme.text.action.primary.focused : theme.text.muted}>{item}</text>
</box>
)}
</For>
</box>
}
>
<box gap={1}>
<text fg={theme.text.muted} wrapMode="word">
{props.message ?? "Do you want to move these changes with the session?"}
</text>
</box>
<scrollbox
height={height()}
backgroundColor={overlayTheme.background.raised.high}
scrollbarOptions={{ visible: false }}
scrollAcceleration={scrollAcceleration()}
>
<For each={props.files}>
{(item) => (
<box
flexDirection="row"
justifyContent="space-between"
paddingLeft={DIALOG_INSET}
paddingRight={DIALOG_INSET}
>
<box flexDirection="row" minWidth={0} flexShrink={1}>
<box width={2} flexShrink={0}>
<text fg={overlayTheme.text.muted}>{statusLabel(item.status)}</text>
<DialogBleed>
<scrollbox
height={height()}
backgroundColor={overlayTheme.background.raised.high}
scrollbarOptions={{ visible: false }}
scrollAcceleration={scrollAcceleration()}
>
<For each={props.files}>
{(item) => (
<box
flexDirection="row"
justifyContent="space-between"
paddingLeft={DIALOG_INSET}
paddingRight={DIALOG_INSET}
>
<box flexDirection="row" minWidth={0} flexShrink={1}>
<box width={2} flexShrink={0}>
<text fg={overlayTheme.text.muted}>{statusLabel(item.status)}</text>
</box>
<FilePath value={item.file} maxWidth={fileNameWidth()} fg={overlayTheme.text.muted} />
</box>
<box flexDirection="row" gap={1} minWidth={7} flexShrink={0} justifyContent="flex-end">
<text>
{" "}
{item.additions ? (
<span style={{ fg: overlayTheme.diff.text.added }}>+{item.additions}</span>
) : null}
{item.deletions ? (
<span style={{ fg: overlayTheme.diff.text.removed }}> -{item.deletions}</span>
) : null}
</text>
</box>
</box>
<FilePath value={item.file} maxWidth={fileNameWidth()} fg={overlayTheme.text.muted} />
</box>
<box flexDirection="row" gap={1} minWidth={7} flexShrink={0} justifyContent="flex-end">
<text>
{" "}
{item.additions ? <span style={{ fg: overlayTheme.diff.text.added }}>+{item.additions}</span> : null}
{item.deletions ? (
<span style={{ fg: overlayTheme.diff.text.removed }}> -{item.deletions}</span>
) : null}
</text>
</box>
</box>
)}
</For>
</scrollbox>
<box
flexDirection="row"
justifyContent="flex-end"
paddingLeft={DIALOG_INSET}
paddingRight={DIALOG_INSET}
paddingBottom={1}
>
<For each={options}>
{(item) => (
<box
paddingLeft={2}
paddingRight={2}
backgroundColor={item === store.active ? theme.background.action.primary.focused : undefined}
onMouseUp={() => {
setStore("active", item)
props.onSelect(item)
dialog.clear()
}}
>
<text fg={item === store.active ? theme.text.action.primary.focused : theme.text.muted}>{item}</text>
</box>
)}
</For>
)}
</For>
</scrollbox>
</DialogBleed>
</box>
</box>
</DialogLayout>
)
}
+50 -45
View File
@@ -8,7 +8,7 @@ import { useClipboard } from "../../context/clipboard"
import { Keymap } from "../../context/keymap"
import { useTheme, useThemes } from "../../context/theme"
import { usePlugin } from "../../plugin/context"
import { DIALOG_INSET, DialogFooter, DialogHeader } from "../../ui/dialog"
import { DIALOG_INSET, DialogBleed, DialogFooter, DialogHeader, DialogLayout } from "../../ui/dialog"
import { useToast } from "../../ui/toast"
import { getScrollAcceleration } from "../../util/scroll"
@@ -124,50 +124,55 @@ export function Answer(props: {
})
return (
<box gap={1} paddingBottom={1}>
<DialogHeader
gap={2}
newInset={DIALOG_INSET}
titleView={
<text attributes={TextAttributes.BOLD} fg={theme.text.base} flexShrink={0}>
/btw
<DialogLayout
header={
<DialogHeader
gap={2}
titleView={
<text attributes={TextAttributes.BOLD} fg={theme.text.base} flexShrink={0}>
/btw
</text>
}
>
<text fg={theme.text.muted} wrapMode="none" flexGrow={1} truncate>
{props.question.replace(/\s+/g, " ")}
</text>
}
>
<text fg={theme.text.muted} wrapMode="none" flexGrow={1} truncate>
{props.question.replace(/\s+/g, " ")}
</text>
</DialogHeader>
<scrollbox
ref={(element: ScrollBoxRenderable) => (scroll = element)}
maxHeight={maxHeight()}
contentOptions={{ minHeight: 0 }}
backgroundColor={overlay.background.raised.high}
scrollbarOptions={{ visible: false }}
scrollAcceleration={getScrollAcceleration(config)}
>
<box paddingLeft={DIALOG_INSET} paddingRight={DIALOG_INSET} paddingTop={1} paddingBottom={1}>
<markdown
syntaxStyle={syntax()}
renderNode={props.markdown()}
content={props.answer}
conceal
internalBlockMode="top-level"
tableOptions={{ style: "grid", cellPaddingX: 1 }}
fg={overlay.markdown.text}
bg={overlay.background.raised.high}
/>
</box>
</scrollbox>
<DialogFooter
newInset={DIALOG_INSET}
actions={[
copied()
? { title: "✓ copied", color: theme.text.feedback.success.base, onTrigger: copy }
: { title: "copy", key: "c", onTrigger: copy },
{ title: "scroll", key: "j/k ↑/↓" },
]}
/>
</box>
</DialogHeader>
}
footer={
<DialogFooter
actions={[
copied()
? { title: "✓ copied", color: theme.text.feedback.success.base, onTrigger: copy }
: { title: "copy", key: "c", onTrigger: copy },
{ title: "scroll", key: "j/k ↑/↓" },
]}
/>
}
>
<DialogBleed>
<scrollbox
ref={(element: ScrollBoxRenderable) => (scroll = element)}
maxHeight={maxHeight()}
contentOptions={{ minHeight: 0 }}
backgroundColor={overlay.background.raised.high}
scrollbarOptions={{ visible: false }}
scrollAcceleration={getScrollAcceleration(config)}
>
<box paddingLeft={DIALOG_INSET} paddingRight={DIALOG_INSET} paddingTop={1} paddingBottom={1}>
<markdown
syntaxStyle={syntax()}
renderNode={props.markdown()}
content={props.answer}
conceal
internalBlockMode="top-level"
tableOptions={{ style: "grid", cellPaddingX: 1 }}
fg={overlay.markdown.text}
bg={overlay.background.raised.high}
/>
</box>
</scrollbox>
</DialogBleed>
</DialogLayout>
)
}
@@ -17,7 +17,7 @@ import { createEffect, createMemo, createResource, createSignal, For, Match, onC
import { DiffViewerFileTree } from "./diff-viewer-file-tree"
import { DiffFileMenu } from "./diff-viewer-file-menu"
import { DiffViewerImage, isDiffImageFile } from "./diff-viewer-image"
import { DIALOG_INSET, DIALOG_LIST_INSET } from "../../ui/dialog"
import { DIALOG_LIST_INSET, DialogHeader, DialogLayout } from "../../ui/dialog"
import { DialogSelect } from "../../ui/dialog-select"
import { EmptyBorder } from "../../ui/border"
import { SESSION_PANEL_SPLIT_MIN_WIDTH } from "../../ui/layout"
@@ -1256,15 +1256,11 @@ function DiffViewerHelpDialog(props: { context: Plugin.Context; single: boolean;
]
return (
<box paddingLeft={DIALOG_INSET} paddingRight={DIALOG_INSET} paddingBottom={1} gap={1}>
<box flexDirection="row" justifyContent="space-between">
<text attributes={TextAttributes.BOLD} fg={theme.text.base}>
Diff shortcuts
</text>
<text fg={theme.text.muted} selectable={false} onMouseUp={() => props.context.ui.dialog.clear()}>
esc close
</text>
</box>
<DialogLayout
header={
<DialogHeader title="Diff shortcuts" closeLabel="esc close" onClose={() => props.context.ui.dialog.clear()} />
}
>
<scrollbox
id="diff-help-scroll"
focused
@@ -1302,7 +1298,7 @@ function DiffViewerHelpDialog(props: { context: Plugin.Context; single: boolean;
</For>
</box>
</scrollbox>
</box>
</DialogLayout>
)
}
@@ -8,7 +8,15 @@ import { useConfig } from "../../config"
import { useClipboard } from "../../context/clipboard"
import { Keymap } from "../../context/keymap"
import { useTheme, useThemes } from "../../context/theme"
import { DIALOG_INSET, DialogFooter, DialogHeader, dialogWidth, useDialog } from "../../ui/dialog"
import {
DIALOG_INSET,
DialogBleed,
DialogFooter,
DialogHeader,
DialogLayout,
dialogWidth,
useDialog,
} from "../../ui/dialog"
import { useToast } from "../../ui/toast"
import { Locale } from "../../util/locale"
import { getScrollAcceleration } from "../../util/scroll"
@@ -92,92 +100,97 @@ export function DialogExecute(props: { part: SessionMessageAssistantTool }) {
}))
return (
<box gap={1} paddingBottom={1}>
<DialogHeader
gap={2}
newInset={DIALOG_INSET}
titleView={
<text fg={theme.text.base} attributes={TextAttributes.BOLD} flexGrow={1}>
execute
</text>
}
>
<text fg={failed() ? theme.text.feedback.error.base : theme.text.muted}>{status()}</text>
</DialogHeader>
<scrollbox
id="execute-detail-scroll"
ref={(value: ScrollBoxRenderable) => (scroll = value)}
height={height()}
contentOptions={{ minHeight: 0 }}
backgroundColor={contentTheme.background.raised.high}
scrollbarOptions={{ visible: false }}
scrollAcceleration={getScrollAcceleration(config)}
>
<box gap={1} paddingLeft={DIALOG_INSET} paddingRight={DIALOG_INSET} paddingTop={1} paddingBottom={1}>
<box>
<text fg={contentTheme.text.muted} attributes={TextAttributes.BOLD}>
Code
<DialogLayout
header={
<DialogHeader
gap={2}
titleView={
<text fg={theme.text.base} attributes={TextAttributes.BOLD} flexGrow={1}>
execute
</text>
<Show when={code()} fallback={<text fg={contentTheme.text.muted}>Waiting for code…</text>}>
{(value) => <GutteredCode content={value()} filetype="typescript" digits={digits()} />}
</Show>
}
>
<text fg={failed() ? theme.text.feedback.error.base : theme.text.muted}>{status()}</text>
</DialogHeader>
}
footer={
<DialogFooter
actions={[
{ title: "scroll", key: "↑/↓" },
copied() === "code"
? { title: "✓ copied", color: theme.text.feedback.success.base, onTrigger: () => copy("code") }
: { title: "copy code", key: "c", onTrigger: () => copy("code") },
copied() === "output"
? { title: "✓ copied", color: theme.text.feedback.success.base, onTrigger: () => copy("output") }
: { title: "copy output", key: "o", onTrigger: () => copy("output") },
{ title: "back", key: "esc", onTrigger: () => dialog.clear() },
]}
/>
}
>
<DialogBleed>
<scrollbox
id="execute-detail-scroll"
ref={(value: ScrollBoxRenderable) => (scroll = value)}
height={height()}
contentOptions={{ minHeight: 0 }}
backgroundColor={contentTheme.background.raised.high}
scrollbarOptions={{ visible: false }}
scrollAcceleration={getScrollAcceleration(config)}
>
<box gap={1} paddingLeft={DIALOG_INSET} paddingRight={DIALOG_INSET} paddingTop={1} paddingBottom={1}>
<box>
<text fg={contentTheme.text.muted} attributes={TextAttributes.BOLD}>
Code
</text>
<Show when={code()} fallback={<text fg={contentTheme.text.muted}>Waiting for code…</text>}>
{(value) => <GutteredCode content={value()} filetype="typescript" digits={digits()} />}
</Show>
</box>
<box>
<text fg={contentTheme.text.muted} attributes={TextAttributes.BOLD}>
Output
</text>
<Show
when={highlighted()}
fallback={
<text
fg={
text()
? failed()
? contentTheme.text.feedback.error.base
: contentTheme.text.base
: contentTheme.text.muted
}
wrapMode="word"
>
{text() ?? (props.part.state.status === "completed" ? "No output" : "Waiting for output…")}
</text>
}
>
{(body) => (
<>
<GutteredCode content={body().json} filetype="json" digits={digits()} />
<Show when={body().rest}>
{(rest) => (
<box paddingLeft={digits() + 1}>
<text
fg={failed() ? contentTheme.text.feedback.error.base : contentTheme.text.base}
wrapMode="word"
>
{rest()}
</text>
</box>
)}
</Show>
</>
)}
</Show>
</box>
</box>
<box>
<text fg={contentTheme.text.muted} attributes={TextAttributes.BOLD}>
Output
</text>
<Show
when={highlighted()}
fallback={
<text
fg={
text()
? failed()
? contentTheme.text.feedback.error.base
: contentTheme.text.base
: contentTheme.text.muted
}
wrapMode="word"
>
{text() ?? (props.part.state.status === "completed" ? "No output" : "Waiting for output…")}
</text>
}
>
{(body) => (
<>
<GutteredCode content={body().json} filetype="json" digits={digits()} />
<Show when={body().rest}>
{(rest) => (
<box paddingLeft={digits() + 1}>
<text
fg={failed() ? contentTheme.text.feedback.error.base : contentTheme.text.base}
wrapMode="word"
>
{rest()}
</text>
</box>
)}
</Show>
</>
)}
</Show>
</box>
</box>
</scrollbox>
<DialogFooter
newInset={DIALOG_INSET}
actions={[
{ title: "scroll", key: "↑/↓" },
copied() === "code"
? { title: "✓ copied", color: theme.text.feedback.success.base, onTrigger: () => copy("code") }
: { title: "copy code", key: "c", onTrigger: () => copy("code") },
copied() === "output"
? { title: "✓ copied", color: theme.text.feedback.success.base, onTrigger: () => copy("output") }
: { title: "copy output", key: "o", onTrigger: () => copy("output") },
{ title: "back", key: "esc", onTrigger: () => dialog.clear() },
]}
/>
</box>
</scrollbox>
</DialogBleed>
</DialogLayout>
)
}
@@ -4,7 +4,7 @@ import { useRoute } from "../../context/route"
import { useClient } from "../../context/client"
import { Spinner } from "../../component/spinner"
import { DialogSelect, type DialogSelectOption } from "../../ui/dialog-select"
import { DIALOG_INSET, useDialog } from "../../ui/dialog"
import { DialogHeader, DialogLayout, useDialog } from "../../ui/dialog"
import { useToast } from "../../ui/toast"
import { errorMessage } from "../../util/error"
import { Locale } from "../../util/locale"
@@ -74,9 +74,9 @@ export function DialogFork(props: { sessionID: string; messageID?: string; onMov
<Show
when={!pending()}
fallback={
<box paddingLeft={DIALOG_INSET} paddingRight={DIALOG_INSET} paddingBottom={1}>
<DialogLayout header={<DialogHeader title="Fork session" />}>
<Spinner>Forking session…</Spinner>
</box>
</DialogLayout>
}
>
<DialogSelect onMove={(option) => props.onMove?.(option.value)} title="Fork session" options={options()} />
+9
View File
@@ -145,6 +145,15 @@ export function DialogLayout(
)
}
/** Stretches a raised band inside a `DialogLayout` across the side padding; its content re-applies `DIALOG_INSET`. */
export function DialogBleed(props: ParentProps) {
return (
<box marginLeft={-DIALOG_INSET} marginRight={-DIALOG_INSET}>
{props.children}
</box>
)
}
export type DialogFooterAction = {
title: string
/** Literal key label, e.g. "enter". */