Add mouse support across the TUI
Drag to select copies on release. Request cards, the queue, attachments, the PR view and the key hints get clickable buttons. Prompts, folds, commands and diff files respond to clicks; prompts, replies, commands and the PR view get right-click menus. Clicking a pane focuses it, the wheel scrolls the thread list and palette, rows highlight under the pointer, and the thread list's border drags to resize.
This commit is contained in:
1 parent
fbdfb5c3e0
commit
12e1e0ba7a
27 files changed
+639
-116
No files matched your search
@@ -0,0 +1,31 @@
|
||||
/** A key a hint names, as the keyboard handler receives it. */
|
||||
export interface HintKey {
|
||||
readonly name: string;
|
||||
readonly sequence: string;
|
||||
readonly shift: boolean;
|
||||
readonly ctrl: boolean;
|
||||
}
|
||||
|
||||
const NAMED: Record<string, string> = { esc: "escape", enter: "return", tab: "tab" };
|
||||
|
||||
/**
|
||||
* The key at the start of a hint like "y approve" or "ctrl+k commands", so a click on the hint
|
||||
* can press it. Hints that name a choice of keys ("j/k move", "1-9 pick") or a chord that
|
||||
* sends a message ("alt+enter steer") aren't clickable.
|
||||
*/
|
||||
export function hintKey(hint: string, mode: string): HintKey | null {
|
||||
const token = hint.trim().split(/\s+/)[0] ?? "";
|
||||
if (hint.includes(" or ") || /^\d-\d$/.test(token)) return null;
|
||||
if (token.length > 1 && token.includes("/")) return null;
|
||||
const ctrl = token.startsWith("ctrl+");
|
||||
const key = ctrl ? token.slice(5) : token;
|
||||
if (key.includes("+") || key.includes("↑") || key.includes("↓")) return null;
|
||||
// In the composer, enter is the composer's own: it sends, and a click shouldn't.
|
||||
if (key === "enter" && (mode === "input" || ctrl)) return null;
|
||||
const named = NAMED[key];
|
||||
if (named) return { name: named, sequence: named === "return" ? "\r" : named === "tab" ? "\t" : "\x1b", shift: false, ctrl };
|
||||
if ([...key].length !== 1) return null;
|
||||
const lower = key.toLowerCase();
|
||||
const shift = lower !== key;
|
||||
return { name: lower, sequence: ctrl ? String.fromCharCode(lower.charCodeAt(0) & 0x1f) : key, shift, ctrl };
|
||||
}
|
||||
+13
-9
@@ -1,5 +1,5 @@
|
||||
import { turnTargets, type TurnTarget } from "./turns.ts";
|
||||
import type { OrchestrationV2ThreadProjection } from "@t3tools/contracts";
|
||||
import type { OrchestrationV2ThreadProjection, RunAttemptId, RunId } from "@t3tools/contracts";
|
||||
import {
|
||||
deriveRunlessWorkStartedAt,
|
||||
deriveThreadActivityRun,
|
||||
@@ -42,6 +42,7 @@ interface TimelineCache {
|
||||
readonly rows: { readonly input: MessagesTimelineRowsInput; readonly rows: MessagesTimelineRow[] };
|
||||
readonly stable: StableMessagesTimelineRowsState;
|
||||
readonly expandAll: boolean;
|
||||
readonly expanded: ReadonlySet<string>;
|
||||
}
|
||||
|
||||
/** Answers yes for every id: "expand everything" without knowing the group ids up front. */
|
||||
@@ -50,15 +51,17 @@ class EverySet<T> extends Set<T> {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
const EVERYTHING = new EverySet<never>();
|
||||
const NOTHING = new Set<never>();
|
||||
const EVERYTHING: ReadonlySet<string> = new EverySet<string>();
|
||||
const NOTHING: ReadonlySet<string> = new Set<string>();
|
||||
|
||||
export function buildTimeline(
|
||||
projection: OrchestrationV2ThreadProjection,
|
||||
options: { readonly expandAll: boolean; readonly historyComplete: boolean },
|
||||
/** `expanded` holds the run, attempt and work group ids opened one at a time (by a click). */
|
||||
options: { readonly expandAll: boolean; readonly expanded?: ReadonlySet<string>; readonly historyComplete: boolean },
|
||||
previous: Timeline | null,
|
||||
): Timeline {
|
||||
const cache = previous?.cache.expandAll === options.expandAll ? previous.cache : null;
|
||||
const opened = options.expanded ?? NOTHING;
|
||||
const cache = previous?.cache.expandAll === options.expandAll && previous.cache.expanded === opened ? previous.cache : null;
|
||||
const entries = deriveTimelineEntriesFromVisibleTurnItemsWithState(
|
||||
{
|
||||
visibleTurnItems: projection.visibleTurnItems,
|
||||
@@ -75,15 +78,16 @@ export function buildTimeline(
|
||||
const isWorking = derivePhase(runtime) === "running" || runlessStartedAt !== null;
|
||||
const workStartedAt = deriveActiveWorkStartedAt(latestRun, runtime, null) ?? runlessStartedAt;
|
||||
const pending = derivePendingThreadRequests(projection);
|
||||
const expanded = options.expandAll ? EVERYTHING : NOTHING;
|
||||
const expanded = options.expandAll ? EVERYTHING : opened;
|
||||
const rows = deriveMessagesTimelineRowsWithState(
|
||||
{
|
||||
timelineEntries: entries.entries,
|
||||
pendingApprovalRequestIds: new Set(pending.approvals.map((approval) => approval.requestId)),
|
||||
latestRun,
|
||||
runningRunId: runtime?.activeRunId ?? null,
|
||||
expandedRunIds: expanded,
|
||||
expandedAttemptIds: expanded,
|
||||
// The ids are branded strings; one set of plain ones holds all three kinds.
|
||||
expandedRunIds: expanded as ReadonlySet<RunId>,
|
||||
expandedAttemptIds: expanded as ReadonlySet<RunAttemptId>,
|
||||
expandedWorkGroupIds: expanded,
|
||||
isWorking,
|
||||
runlessWorkActive: runlessStartedAt !== null,
|
||||
@@ -100,6 +104,6 @@ export function buildTimeline(
|
||||
turns: turnTargets(projection, entries.entries, isWorking ? runtime?.activeRunId ?? null : null, options.historyComplete),
|
||||
isWorking,
|
||||
workStartedAt,
|
||||
cache: { entries, rows, stable, expandAll: options.expandAll },
|
||||
cache: { entries, rows, stable, expandAll: options.expandAll, expanded: opened },
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user