From c2696328fecc70e768841497b6016f296a2ffa76 Mon Sep 17 00:00:00 2001 From: Callum Alpass Date: Tue, 3 Nov 2026 08:37:25 +1100 Subject: [PATCH] Add a tab strip and a horizontal drag edge; keep the drawer's height and terminal placement in the layout --- src/layout.ts | 8 +++++++- src/ui/Button.tsx | 47 ++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/layout.ts b/src/layout.ts index 5c72676..d2ce349 100644 --- a/src/layout.ts +++ b/src/layout.ts @@ -16,9 +16,13 @@ export interface Layout { readonly listHidden: boolean; /** The details column shown or hidden with `d`; null follows the window's width. */ readonly details: boolean | null; + /** The terminal drawer's height once its edge is dragged; null is the default height. */ + readonly drawerHeight: number | null; + /** Where terminals open: in a drawer below the conversation, or in the right-hand column. */ + readonly terminalPlacement: "bottom" | "side"; } -export const DEFAULT_LAYOUT: Layout = { listWidth: null, detailsWidth: null, listHidden: false, details: null }; +export const DEFAULT_LAYOUT: Layout = { listWidth: null, detailsWidth: null, listHidden: false, details: null, drawerHeight: null, terminalPlacement: "bottom" }; const layoutPath = () => join(configDir(), "layout.json"); @@ -38,6 +42,8 @@ export function parseLayout(raw: unknown): Layout { detailsWidth: positiveInteger(record.detailsWidth), listHidden: record.listHidden === true, details: typeof record.details === "boolean" ? record.details : null, + drawerHeight: positiveInteger(record.drawerHeight), + terminalPlacement: record.terminalPlacement === "side" ? "side" : "bottom", }; } diff --git a/src/ui/Button.tsx b/src/ui/Button.tsx index 52322cd..f3599b0 100644 --- a/src/ui/Button.tsx +++ b/src/ui/Button.tsx @@ -2,7 +2,7 @@ import type { MouseEvent } from "@opentui/core"; import type { BoxProps as OpenTuiBoxProps } from "@opentui/react"; import { useState, type ReactNode } from "react"; -import { BAR } from "./edges.ts"; +import { BAR, NO_BORDER } from "./edges.ts"; import { colors } from "./theme.ts"; /** Hover state for a clickable box. Moving between a box and its own text sends out then over, so it settles on the right value. */ @@ -75,28 +75,61 @@ export function wheelStep(event: MouseEvent): -1 | 0 | 1 { } /** - * The 1-column drag target between the conversation and the list or details. At rest it is invisible + * The 1-column drag target between the conversation and the list or details, or with + * `horizontal` the 1-row one above the terminal drawer. 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 * pointer, so the app's root follows the drag (see App). */ -export function ResizeHandle(props: { readonly active: boolean; readonly onStart: () => void; readonly onReset: () => void }) { +export function ResizeHandle(props: { readonly active: boolean; readonly horizontal?: boolean; readonly onStart: (event: MouseEvent) => void; readonly onReset: () => void }) { const [hover, hoverProps] = useHover(); return ( { event.stopPropagation(); if (isRightClick(event)) props.onReset(); - else if (isLeftClick(event)) props.onStart(); + else if (isLeftClick(event)) props.onStart(event); }} /> ); } + +/** + * A one-line strip of tabs: the active one in the accent on a raised block, the rest muted. + * A click switches; anything after the tabs (a `+`, a key hint) goes in `children`. + */ +export function Tabs(props: { readonly tabs: readonly { readonly id: string; readonly label: string }[]; readonly active: string | null; readonly onPick: (id: string) => void; readonly children?: ReactNode }) { + return ( + + {props.tabs.map((tab) => ( + props.onPick(tab.id)} /> + ))} + {props.children} + + ); +} + +export function Tab(props: { readonly label: string; readonly active?: boolean; readonly onPress: () => void }) { + const [hover, hoverProps] = useHover(); + return ( + { + event.stopPropagation(); + if (isLeftClick(event)) props.onPress(); + }} + > + {props.label} + + ); +}