From bbf8ff49e1a363d857d9268ec048f5d1b7123c6f Mon Sep 17 00:00:00 2001 From: Callum Alpass Date: Tue, 3 Nov 2026 01:49:12 +1100 Subject: [PATCH] Resize the details column by dragging its edge Like the thread list: drag to resize, right-click to reset, kept as detailsWidth in layout.json. The conversation keeps its minimum width; a dragged width gives way to it before the panel goes in place. --- src/layout.ts | 9 +++++--- src/ui/App.tsx | 50 ++++++++++++++++++++++++++++--------------- src/ui/Button.tsx | 2 +- test/app/app.test.tsx | 17 +++++++++++++++ 4 files changed, 57 insertions(+), 21 deletions(-) diff --git a/src/layout.ts b/src/layout.ts index 7c43417..ffd3b05 100644 --- a/src/layout.ts +++ b/src/layout.ts @@ -10,9 +10,11 @@ import { configDir } from "./client/auth.ts"; export interface Layout { /** The thread list's width once its border is dragged; null follows the window. */ readonly listWidth: number | null; + /** The details column's width once its border is dragged; null is the default width. */ + readonly detailsWidth: number | null; } -export const DEFAULT_LAYOUT: Layout = { listWidth: null }; +export const DEFAULT_LAYOUT: Layout = { listWidth: null, detailsWidth: null }; const layoutPath = () => join(configDir(), "layout.json"); @@ -27,10 +29,11 @@ export async function loadLayout(): Promise { export function parseLayout(raw: unknown): Layout { const record = raw && typeof raw === "object" ? (raw as Record) : {}; - const width = record.listWidth; - return { listWidth: typeof width === "number" && Number.isInteger(width) && width > 0 ? width : null }; + return { listWidth: positiveInteger(record.listWidth), detailsWidth: positiveInteger(record.detailsWidth) }; } +const positiveInteger = (value: unknown) => (typeof value === "number" && Number.isInteger(value) && value > 0 ? value : null); + export async function saveLayout(layout: Layout): Promise { await mkdir(configDir(), { recursive: true }); await writeFile(layoutPath(), `${JSON.stringify(layout, null, 2)}\n`); diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 40936a5..de6109e 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -80,6 +80,8 @@ const MAX_COMPOSER_LINES = 8; /** Sections folded to a count unless you filter or press z, like the web sidebar's. */ const FOLDED_SECTIONS: readonly Section[] = ["snoozed", "settled"]; const DETAILS_WIDTH = 38; +/** The narrowest the details column can be dragged. */ +const MIN_DETAILS_WIDTH = 28; /** Below this, the details panel takes the conversation's place instead of a column beside it. */ const MIN_CONVERSATION_WIDTH = 70; @@ -111,13 +113,15 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui const [expandAll, setExpandAll] = useState(false); /** Folds opened one at a time by a click, for the open thread. */ const [expandedIds, setExpandedIds] = useState>(() => new Set()); - /** The thread list's width once its border is dragged; null follows the window. */ + /** The thread list's and details column's widths once their edges are dragged; null follows the window. */ const [listWidthPref, setListWidthPref] = useState(props.layout?.listWidth ?? null); - const listWidthNow = useRef(listWidthPref); - listWidthNow.current = listWidthPref; + const [detailsWidthPref, setDetailsWidthPref] = useState(props.layout?.detailsWidth ?? null); + const layoutNow = useRef({ listWidth: listWidthPref, detailsWidth: detailsWidthPref }); + layoutNow.current = { listWidth: listWidthPref, detailsWidth: detailsWidthPref }; /** Kept for the next run; a failed save only costs that. */ - const saveListWidth = (listWidth: number | null) => void saveLayout({ listWidth }).catch(() => {}); - const [resizing, setResizing] = useState(false); + const saveLayoutNow = (change: Partial = {}) => void saveLayout({ ...layoutNow.current, ...change }).catch(() => {}); + /** The edge being dragged. */ + const [resizing, setResizing] = useState<"list" | "details" | null>(null); const [diff, setDiff] = useState(null); const [config, setConfig] = useState(props.config); const [settingsIndex, setSettingsIndex] = useState(null); @@ -978,7 +982,10 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui const headerRoom = width - 18 - (headerProject ? headerProject.length + 3 : 0) - (headerStatus ? headerStatus.text.length + 2 : 0) - (shell.status.type !== "live" ? status.length + 2 : 0) - (usageInfo.note ? usageInfo.note.length + 2 : 0); const headerTitle = truncate(title, Math.max(8, headerRoom)); const listWidth = attached ? 0 : clampListWidth(listWidthPref ?? Math.min(46, Math.max(28, Math.floor(width * 0.3))), width); - const detailsColumn = panel.show && width - listWidth - DETAILS_WIDTH >= MIN_CONVERSATION_WIDTH; + // Room for the details column and its edge beside the conversation; a dragged width gives way to the conversation first. + const detailsRoom = width - listWidth - 1 - MIN_CONVERSATION_WIDTH; + const detailsWidth = Math.min(detailsWidthPref ?? DETAILS_WIDTH, Math.max(DETAILS_WIDTH, detailsRoom)); + const detailsColumn = panel.show && detailsWidth <= detailsRoom; const detailsInPlace = panel.show && !detailsColumn; // The block's height: a row of padding on top, the text, then the model line inside it. // Padding row, text, a blank row, then the model line. @@ -1017,7 +1024,7 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui details={panel.details} // Idle subagents are left out of the shell, which is where details come from; newer servers serve them on request. {...(threadId && !threadShell ? { empty: supportsFamilies ? "Loading details…" : "No details for idle subagent threads on this server. u goes to the parent." } : {})} - width={inPlace ? width - listWidth : DETAILS_WIDTH} + width={inPlace ? width - listWidth : detailsWidth} loading={panel.loading} unfolded={panel.unfolded} inPlace={inPlace} @@ -1034,14 +1041,15 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui backgroundColor={colors.bg} {...(resizing ? { - onMouseDrag: (event: MouseEvent) => setListWidthPref(clampListWidth(event.x, width)), + onMouseDrag: (event: MouseEvent) => + resizing === "list" ? setListWidthPref(clampListWidth(event.x, width)) : setDetailsWidthPref(Math.max(MIN_DETAILS_WIDTH, Math.min(width - event.x - 1, detailsRoom))), onMouseUp: () => { - setResizing(false); - saveListWidth(listWidthNow.current); + setResizing(null); + saveLayoutNow(); }, onMouseDragEnd: () => { - setResizing(false); - saveListWidth(listWidthNow.current); + setResizing(null); + saveLayoutNow(); }, } : {})} @@ -1091,9 +1099,9 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui shelfStatus={library.error ?? (library.loading ? "Loading…" : library.archived ? "Archived threads · A to go back" : null)} /> )} - {attached ? null : setResizing(true)} onReset={() => { + {attached ? null : setResizing("list")} onReset={() => { setListWidthPref(null); - saveListWidth(null); + saveLayoutNow({ listWidth: null }); }} />} @@ -1149,7 +1157,7 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui {workspace.note ? {workspace.note} : null} {find.open ? setMode("nav")} /> : null} {mode !== "confirm" && secret.request ? : null} - {queue.queued.length > 0 ? : null} + {queue.queued.length > 0 ? : null} {mode !== "confirm" && questions.request && questions.draft ? ) : null} - {menu ? : null} + {menu ? : null} {attach.pending.length > 0 ? ( Attached: @@ -1253,7 +1261,15 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui ) : null} - {detailsColumn ? detailsPanel(false) : null} + {detailsColumn ? ( + <> + setResizing("details")} onReset={() => { + setDetailsWidthPref(null); + saveLayoutNow({ detailsWidth: null }); + }} /> + {detailsPanel(false)} + + ) : null} {flash ? {flash.text} : } diff --git a/src/ui/Button.tsx b/src/ui/Button.tsx index 5e793b2..52322cd 100644 --- a/src/ui/Button.tsx +++ b/src/ui/Button.tsx @@ -75,7 +75,7 @@ export function wheelStep(event: MouseEvent): -1 | 0 | 1 { } /** - * The 1-column drag target between the list and the conversation. At rest it is invisible + * The 1-column drag target between the conversation and the list or details. At rest it is invisible * (the panel/background shade change is the edge, and the bar is drawn in the background * colour, which also keeps it findable on screen for tests); under the pointer or while * dragging it shows as an accent bar. OpenTUI sends a drag to whatever is under the diff --git a/test/app/app.test.tsx b/test/app/app.test.tsx index 76a4cb8..400f3bf 100644 --- a/test/app/app.test.tsx +++ b/test/app/app.test.tsx @@ -386,4 +386,21 @@ describe("mouse", () => { const next = await open({ layout }); expect(next.find("┃").x).toBe(before + 7); }); + + test("dragging the details edge resizes it and keeps the width; right-click resets it", async () => { + // Wide enough for the details column to open by itself. + const first = await open({ width: 200 }); + // The details edge is the last bar on a row above the composer. + const edge = () => first.frame().split("\n")[10]!.lastIndexOf("┃"); + const before = edge(); + expect(before).toBe(200 - 38 - 1); + await first.mockMouse.drag(before, 10, before - 10, 10); + await first.settle(100); + expect(edge()).toBe(before - 10); + expect((await loadLayout()).detailsWidth).toBe(48); + await first.click(before - 10, 10, 2); + await first.settle(100); + expect(edge()).toBe(before); + expect((await loadLayout()).detailsWidth).toBeNull(); + }); });