From 9293be206caf53c44ad8fca003b89dd3336dd3c0 Mon Sep 17 00:00:00 2001 From: Callum Alpass Date: Mon, 2 Nov 2026 23:58:19 +1100 Subject: [PATCH] Shared bar edge, invisible resize handle, quieter hint bar edges.ts carries opencode's border chars (BAR/NO_BORDER). The resize handle is a bar in the background colour at rest and accent under the pointer. Hint keys sit in text over faint labels, and hints that don't fit drop whole from the end. --- src/ui/Button.tsx | 22 ++++++++++++++-------- src/ui/HintBar.tsx | 39 +++++++++++++++++++++++++++------------ src/ui/edges.ts | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 20 deletions(-) create mode 100644 src/ui/edges.ts diff --git a/src/ui/Button.tsx b/src/ui/Button.tsx index 44b946d..5e793b2 100644 --- a/src/ui/Button.tsx +++ b/src/ui/Button.tsx @@ -2,6 +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 { 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. */ @@ -18,15 +19,15 @@ export const isRightClick = (event: MouseEvent) => event.button === 2; * A clickable label with its key beside it: `Approve y`. It takes the click for itself, so the * card or pane under it doesn't react too, and its text can't be drag-selected. */ -export function Button(props: { readonly label: string; readonly shortcut?: string | undefined; readonly color?: string | undefined; readonly onPress: () => void }) { +export function Button(props: { readonly label: string; readonly shortcut?: string | undefined; readonly color?: string | undefined; /** No background or padding: a bare clickable label, as in the header. */ readonly plain?: boolean; readonly onPress: () => void }) { const [hover, hoverProps] = useHover(); return ( { event.stopPropagation(); @@ -74,8 +75,11 @@ export function wheelStep(event: MouseEvent): -1 | 0 | 1 { } /** - * The border between two panes, pressed to start resizing the one on its left. OpenTUI sends a - * drag to whatever is under the pointer, so the app's root follows the drag (see App). + * The 1-column drag target between the list and the conversation. 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 }) { const [hover, hoverProps] = useHover(); @@ -83,8 +87,10 @@ export function ResizeHandle(props: { readonly active: boolean; readonly onStart { event.stopPropagation(); diff --git a/src/ui/HintBar.tsx b/src/ui/HintBar.tsx index e29a2c6..4b72a8c 100644 --- a/src/ui/HintBar.tsx +++ b/src/ui/HintBar.tsx @@ -4,11 +4,31 @@ import type { Hint } from "../model/keymap.ts"; import { isLeftClick, useHover } from "./Button.tsx"; import { colors } from "./theme.ts"; -/** The key hints along the bottom; a click on one does what its key does. */ -export function HintBar(props: { readonly hints: readonly Hint[] }) { +const SEPARATOR = " · "; + +/** The width a hint takes on screen: its key, a space, then its label. */ +const hintWidth = (hint: Hint) => Bun.stringWidth(hint.key ? `${hint.key} ${hint.label}` : hint.label); + +/** + * The key hints along the bottom; a click on one does what its key does. When they don't + * fit the width, whole hints drop off the end rather than one being cut mid-word. + */ +export function HintBar(props: { readonly hints: readonly Hint[]; readonly width?: number }) { + let shown = props.hints; + if (props.width !== undefined) { + let used = 0; + let count = 0; + for (const hint of props.hints) { + const next = used + (count > 0 ? SEPARATOR.length : 0) + hintWidth(hint); + if (next > props.width) break; + used = next; + count++; + } + shown = props.hints.slice(0, count); + } return ( - {props.hints.map((hint, index) => ( + {shown.map((hint, index) => ( 0} /> ))} @@ -19,15 +39,10 @@ function HintItem(props: { readonly hint: Hint; readonly separator: boolean }) { const [hover, hoverProps] = useHover(); const { key, label, run } = props.hint; return ( - - {props.separator ? {" · "} : null} - isLeftClick(event) && run() } : {})} - > - {key ? `${key} ${label}` : label} - + isLeftClick(event) && run() } : {})}> + {props.separator ? {SEPARATOR} : null} + {key ? {`${key} `} : null} + {label} ); } diff --git a/src/ui/edges.ts b/src/ui/edges.ts new file mode 100644 index 0000000..a3bcefa --- /dev/null +++ b/src/ui/edges.ts @@ -0,0 +1,33 @@ +/** + * Border characters for opencode's signature edge: a heavy left bar and + * nothing else. Use with `border={["left"]}` and a background colour, so the + * block's shade, not a box outline, is what separates it. + */ +export const BAR = { + topLeft: "", + bottomLeft: "", + vertical: "┃", + topRight: "", + bottomRight: "", + horizontal: " ", + bottomT: "", + topT: "", + cross: "", + leftT: "", + rightT: "", +}; + +/** No visible border at all; the space keeps a border's width where one is needed for layout. */ +export const NO_BORDER = { + topLeft: "", + bottomLeft: "", + vertical: "", + topRight: "", + bottomRight: "", + horizontal: " ", + bottomT: "", + topT: "", + cross: "", + leftT: "", + rightT: "", +};