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.
This commit is contained in:
Callum Alpass committed 2026-11-02 23:58:19 +11:00
1 parent e22885d802
commit 9293be206c
3 files changed
+74 -20

No files matched your search

+14 -8
View File
@@ -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 (
<box
flexDirection="row"
flexShrink={0}
paddingLeft={1}
paddingRight={1}
backgroundColor={hover ? colors.selectedBg : colors.buttonBg}
paddingLeft={props.plain ? 0 : 1}
paddingRight={props.plain ? 0 : 1}
backgroundColor={props.plain ? "transparent" : hover ? colors.selectedBg : colors.buttonBg}
{...hoverProps}
onMouseDown={(event: MouseEvent) => {
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
<box
width={1}
flexShrink={0}
border={["right"]}
borderColor={hover || props.active ? colors.borderFocused : colors.border}
border={["left"]}
customBorderChars={BAR}
borderColor={hover || props.active ? colors.accent : colors.bg}
backgroundColor={colors.bg}
{...hoverProps}
onMouseDown={(event: MouseEvent) => {
event.stopPropagation();
+27 -12
View File
@@ -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 (
<box flexDirection="row" overflow="hidden">
{props.hints.map((hint, index) => (
{shown.map((hint, index) => (
<HintItem key={`${index}:${hint.key}:${hint.label}`} hint={hint} separator={index > 0} />
))}
</box>
@@ -19,15 +39,10 @@ function HintItem(props: { readonly hint: Hint; readonly separator: boolean }) {
const [hover, hoverProps] = useHover();
const { key, label, run } = props.hint;
return (
<box flexDirection="row" flexShrink={0}>
{props.separator ? <text fg={colors.faint} selectable={false}>{" · "}</text> : null}
<text
fg={run && hover ? colors.text : colors.faint}
selectable={false}
{...(run ? { ...hoverProps, onMouseDown: (event: MouseEvent) => isLeftClick(event) && run() } : {})}
>
{key ? `${key} ${label}` : label}
</text>
<box flexDirection="row" flexShrink={0} {...(run ? { ...hoverProps, onMouseDown: (event: MouseEvent) => isLeftClick(event) && run() } : {})}>
{props.separator ? <text fg={colors.faint} selectable={false}>{SEPARATOR}</text> : null}
{key ? <text fg={colors.text} selectable={false}>{`${key} `}</text> : null}
<text fg={run && hover ? colors.text : colors.faint} selectable={false}>{label}</text>
</box>
);
}
+33
View File
@@ -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: "",
};