@lune_99/pi-core-theme 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,80 @@
1
+ import type { ExtensionAPI, Theme } from "@earendil-works/pi-coding-agent";
2
+ import { Text, type Container, type TUI } from "@earendil-works/pi-tui";
3
+
4
+ interface ListingOptions {
5
+ force?: boolean;
6
+ }
7
+
8
+ interface ResourceMode {
9
+ loadedResourcesContainer: Container;
10
+ ui: Pick<TUI, "requestRender">;
11
+ shouldShowStartupDetails(): boolean;
12
+ getStartupExpansionState(): boolean;
13
+ }
14
+
15
+ type ShowLoadedResources = (this: ResourceMode, options?: ListingOptions) => void;
16
+
17
+ /** Pi has no public API for appending to its startup resource list. */
18
+ export function installStartupAgents({
19
+ interactiveMode,
20
+ events,
21
+ getTheme,
22
+ }: {
23
+ interactiveMode: { prototype: object } | undefined;
24
+ events: ExtensionAPI["events"];
25
+ getTheme: () => Theme | undefined;
26
+ }): { dispose(): void } {
27
+ const prototype = interactiveMode?.prototype as
28
+ | { showLoadedResources?: ShowLoadedResources }
29
+ | undefined;
30
+ if (!prototype || typeof prototype.showLoadedResources !== "function") {
31
+ return { dispose() {} };
32
+ }
33
+ let names: readonly string[] = [];
34
+ // Factories run before session_start, so either extension load order receives the names.
35
+ const stop = events.on("lune-subagent:agents-loaded", (data) => {
36
+ names = data as readonly string[];
37
+ });
38
+ let expanded = false;
39
+ const text = new Text("", 0, 0);
40
+ const section = {
41
+ setExpanded(value: boolean) {
42
+ expanded = value;
43
+ },
44
+ invalidate() {
45
+ text.invalidate();
46
+ },
47
+ render(width: number): string[] {
48
+ const theme = getTheme();
49
+ if (!theme || names.length === 0) return [];
50
+ const body = expanded
51
+ ? names.map((name) => ` ${name}`).join("\n")
52
+ : ` ${names.join(", ")}`;
53
+ text.setText(`${theme.fg("mdHeading", "[Agents]")}\n${theme.fg("dim", body)}`);
54
+ return [...text.render(width), ""];
55
+ },
56
+ };
57
+ let unmount: (() => void) | undefined;
58
+ const original = prototype.showLoadedResources;
59
+ const show: ShowLoadedResources = function (options) {
60
+ original.call(this, options);
61
+ unmount = undefined;
62
+ if (!(options?.force || this.shouldShowStartupDetails())) return;
63
+ expanded = this.getStartupExpansionState();
64
+ this.loadedResourcesContainer.addChild(section);
65
+ unmount = () => {
66
+ this.loadedResourcesContainer.removeChild(section);
67
+ this.ui.requestRender();
68
+ };
69
+ };
70
+ prototype.showLoadedResources = show;
71
+ return {
72
+ dispose() {
73
+ stop();
74
+ names = [];
75
+ if (prototype.showLoadedResources === show) prototype.showLoadedResources = original;
76
+ unmount?.();
77
+ unmount = undefined;
78
+ },
79
+ };
80
+ }
@@ -20,10 +20,15 @@ export class CallList {
20
20
  previewCount(total: number, expanded: boolean): number {
21
21
  return expanded ? total : Math.min(total, PREVIEW_LIMIT, config.previewLines);
22
22
  }
23
+ /**
24
+ * A running list follows its current call and a settled list keeps its newest calls, so the
25
+ * last call settling does not swap every visible row back to the first calls.
26
+ */
23
27
  previewStart(total: number, expanded: boolean, running: boolean, current = total - 1): number {
24
- if (expanded || !running) return 0;
28
+ if (expanded) return 0;
25
29
  const count = this.previewCount(total, expanded);
26
- return Math.max(0, Math.min(total - count, current - count + 1));
30
+ const focus = running ? current : total - 1;
31
+ return Math.max(0, Math.min(total - count, focus - count + 1));
27
32
  }
28
33
  /** `indent` is part of the returned row so hint hit-testing matches what is painted. */
29
34
  renderHeader(
@@ -0,0 +1,214 @@
1
+ import {
2
+ copyToClipboard,
3
+ type ContextUsage,
4
+ type ExtensionContext,
5
+ type Theme,
6
+ } from "@earendil-works/pi-coding-agent";
7
+ import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
8
+ import { formatTokens } from "../utils/format-tokens.ts";
9
+ import { TextPanel, type TextPanelItem, type TextPanelOptions } from "./text-panel.ts";
10
+
11
+ type Color = Parameters<Theme["fg"]>[0];
12
+
13
+ export interface ContextCategory {
14
+ label: string;
15
+ content: string;
16
+ tokens: number;
17
+ }
18
+
19
+ type PanelHost = Pick<TextPanelOptions, "theme" | "rows" | "repaint" | "close" | "copy" | "notify">;
20
+
21
+ // Category colors are semantic Pi tokens; the active palette owns every foreground and background.
22
+ const CATEGORY_COLORS = [
23
+ "thinkingLow",
24
+ "thinkingMedium",
25
+ "thinkingHigh",
26
+ "thinkingXhigh",
27
+ "customMessageLabel",
28
+ "success",
29
+ ] as const;
30
+
31
+ function align(left: string, right: string, width: number): string {
32
+ const end = truncateToWidth(right, Math.max(0, width - visibleWidth(left) - 1), "…");
33
+ return left + " ".repeat(Math.max(0, width - visibleWidth(left) - visibleWidth(end))) + end;
34
+ }
35
+
36
+ function metricRows(label: string, value: string, width: number): string[] {
37
+ return visibleWidth(label) + visibleWidth(value) + 1 <= width
38
+ ? [align(label, value, width)]
39
+ : [label, value];
40
+ }
41
+
42
+ function composition(
43
+ usage: ContextUsage,
44
+ categories: readonly ContextCategory[],
45
+ width: number,
46
+ theme: Theme,
47
+ ): string {
48
+ if (usage.contextWindow <= 0) return theme.fg("dim", "Window size unavailable");
49
+ let previous = 0;
50
+ let cumulative = 0;
51
+ const used = categories
52
+ .map((category, index) => {
53
+ cumulative += category.tokens;
54
+ // This chart shows category estimates; Pi's reported usage remains in the header.
55
+ const end = Math.min(width, Math.round((cumulative / usage.contextWindow) * width));
56
+ const segment = theme.fg(CATEGORY_COLORS[index]!, "█".repeat(end - previous));
57
+ previous = end;
58
+ return segment;
59
+ })
60
+ .join("");
61
+ return used + theme.fg("dim", "░".repeat(width - previous));
62
+ }
63
+
64
+ export function formatContextOverview(
65
+ usage: ContextUsage,
66
+ categories: readonly ContextCategory[],
67
+ ): string {
68
+ const remaining =
69
+ usage.tokens !== null && usage.contextWindow > 0
70
+ ? Math.max(0, usage.contextWindow - usage.tokens)
71
+ : null;
72
+ return [
73
+ "Context window",
74
+ `Pi context usage: ${usage.tokens === null ? "unknown" : usage.tokens.toLocaleString("en-US")} / ${usage.contextWindow > 0 ? usage.contextWindow.toLocaleString("en-US") : "unknown"} tokens`,
75
+ `Pi context share: ${usage.percent === null ? "unknown" : `${usage.percent.toFixed(1)}%`}`,
76
+ `Remaining: ${remaining === null ? "unknown" : remaining.toLocaleString("en-US")} tokens`,
77
+ "",
78
+ ...categories.map(
79
+ (category) =>
80
+ `${category.label}: ${category.tokens.toLocaleString("en-US")} estimated tokens`,
81
+ ),
82
+ ].join("\n");
83
+ }
84
+
85
+ function renderOverview(
86
+ usage: ContextUsage,
87
+ categories: readonly ContextCategory[],
88
+ width: number,
89
+ theme: Theme,
90
+ ): string[] {
91
+ const share = (tokens: number) =>
92
+ usage.contextWindow > 0 ? ` ${((tokens / usage.contextWindow) * 100).toFixed(1)}%` : "";
93
+ const lines = [
94
+ "",
95
+ theme.bold(theme.fg("mdHeading", "Context window")),
96
+ theme.fg(
97
+ "dim",
98
+ `${usage.tokens === null ? "?" : formatTokens(usage.tokens)} / ${usage.contextWindow > 0 ? formatTokens(usage.contextWindow) : "?"} tokens · Pi context usage`,
99
+ ),
100
+ "",
101
+ composition(usage, categories, width, theme),
102
+ "",
103
+ ...categories.flatMap((category, index) => {
104
+ const color = CATEGORY_COLORS[index]!;
105
+ return metricRows(
106
+ theme.fg(color, "● ") + theme.fg("text", category.label),
107
+ theme.fg(color, category.tokens.toLocaleString("en-US") + share(category.tokens)),
108
+ width,
109
+ );
110
+ }),
111
+ ];
112
+ return lines.flatMap((line) => wrapTextWithAnsi(line, width));
113
+ }
114
+
115
+ /** Style structural headings without parsing an entire session into a Markdown syntax tree. */
116
+ function renderDocument(content: string, width: number, theme: Theme): string[] {
117
+ let code = false;
118
+ const rows: string[] = [""];
119
+ for (const line of content.split("\n")) {
120
+ const fence = line.match(/^```(.*)$/);
121
+ if (fence) {
122
+ if (!code && fence[1])
123
+ rows.push(...wrapTextWithAnsi(theme.fg("dim", fence[1].toUpperCase()), width));
124
+ else rows.push("");
125
+ code = !code;
126
+ continue;
127
+ }
128
+ const heading = !code && line.match(/^#{1,6}\s+(.+)$/);
129
+ const text = heading
130
+ ? theme.bold(theme.fg("mdHeading", heading[1]!))
131
+ : theme.fg("text", line);
132
+ rows.push(...wrapTextWithAnsi(text, width));
133
+ }
134
+ return rows;
135
+ }
136
+
137
+ function renderHeader(usage: ContextUsage, width: number, theme: Theme): string[] {
138
+ const { tokens, contextWindow, percent } = usage;
139
+ const color: Color = percent !== null && percent >= 90 ? "warning" : "accent";
140
+ const title = theme.fg("accent", "◐ ") + theme.bold(theme.fg("text", "LUNE · Context"));
141
+ const amount = `${tokens === null ? "?" : formatTokens(tokens)} / ${contextWindow > 0 ? formatTokens(contextWindow) : "?"} tokens`;
142
+ const remaining =
143
+ tokens !== null && contextWindow > 0 ? Math.max(0, contextWindow - tokens) : null;
144
+ const detail = `${percent === null ? "?" : percent.toFixed(1)}% used · ${remaining === null ? "?" : formatTokens(remaining)} available`;
145
+ const showDetail = width >= 54;
146
+ const meterWidth = Math.max(1, width - (showDetail ? visibleWidth(detail) + 3 : 0));
147
+ const cells =
148
+ percent === null
149
+ ? 0
150
+ : Math.max(0, Math.min(meterWidth, Math.round((percent / 100) * meterWidth)));
151
+ const meter =
152
+ theme.fg(color, "━".repeat(cells)) +
153
+ theme.fg("borderMuted", "━".repeat(meterWidth - cells));
154
+ return [
155
+ align(title, theme.fg("muted", amount), width),
156
+ meter + (showDetail ? " " + theme.fg("muted", detail) : ""),
157
+ theme.fg(
158
+ "dim",
159
+ `${tokens === null ? "Pi context usage unknown" : "Pi context usage"} · category sizes estimated`,
160
+ ),
161
+ ];
162
+ }
163
+
164
+ export function createContextPanel(
165
+ usage: ContextUsage,
166
+ categories: readonly ContextCategory[],
167
+ host: PanelHost,
168
+ ): TextPanel {
169
+ const items: TextPanelItem[] = [
170
+ {
171
+ label: "Overview",
172
+ content: formatContextOverview(usage, categories),
173
+ render: (_content, width, theme) => renderOverview(usage, categories, width, theme),
174
+ },
175
+ ...categories.map((category, index) => ({
176
+ label: category.label,
177
+ content: category.content,
178
+ badge: formatTokens(category.tokens),
179
+ color: CATEGORY_COLORS[index]!,
180
+ render: renderDocument,
181
+ })),
182
+ ];
183
+ return new TextPanel({
184
+ ...host,
185
+ title: "LUNE · Context",
186
+ maxHeight: 24,
187
+ items,
188
+ navigationTitle: "Categories · est. tokens",
189
+ header: (width, theme) =>
190
+ renderHeader(usage, width, theme).slice(0, host.rows() < 18 ? 1 : 3),
191
+ });
192
+ }
193
+
194
+ export async function showContextBrowser(
195
+ ctx: Pick<ExtensionContext, "ui">,
196
+ usage: ContextUsage,
197
+ categories: readonly ContextCategory[],
198
+ ) {
199
+ await ctx.ui.custom<void>(
200
+ (tui, _theme, _keys, done) =>
201
+ createContextPanel(usage, categories, {
202
+ theme: () => ctx.ui.theme,
203
+ rows: () => tui.terminal.rows,
204
+ repaint: () => tui.requestRender(),
205
+ close: () => done(),
206
+ copy: copyToClipboard,
207
+ notify: (message, level) => ctx.ui.notify(message, level),
208
+ }),
209
+ {
210
+ overlay: true,
211
+ overlayOptions: { width: 100, maxHeight: 24, anchor: "center", margin: 2 },
212
+ },
213
+ );
214
+ }
package/src/ui/hover.ts CHANGED
@@ -40,21 +40,35 @@ export class HoverState {
40
40
  }
41
41
  }
42
42
 
43
- /** Fullscreen consumes motion before extension listeners; observe its session instance before native dispatch. */
44
- export function installHoverTracking(tui: object, hover: HoverState, repaint: () => void) {
45
- const host = tui as { handleViewportInput?: (data: string) => unknown };
46
- const original = host.handleViewportInput;
43
+ /** Wraps one method of a TUI instance; the undo leaves a newer wrapper in place. */
44
+ export function patchMethod<F extends (...args: never[]) => unknown>(
45
+ host: object,
46
+ name: string,
47
+ wrap: (original: F) => F,
48
+ ) {
49
+ const target = host as Record<string, unknown>;
50
+ const original = target[name];
47
51
  if (typeof original !== "function") return () => {};
48
- const owned = Object.hasOwn(host, "handleViewportInput");
49
- const handler = function (this: typeof host, data: string) {
50
- const mouse = /^\x1b\[<(\d+);\d+;\d+M$/.exec(data);
51
- if (mouse && (Number(mouse[1]) & 32) !== 0) hover.beginMove(repaint);
52
- return original.call(this, data);
53
- };
54
- host.handleViewportInput = handler;
52
+ const owned = Object.hasOwn(target, name);
53
+ const patched = wrap(original as F);
54
+ target[name] = patched;
55
55
  return () => {
56
- if (host.handleViewportInput !== handler) return;
57
- if (owned) host.handleViewportInput = original;
58
- else delete host.handleViewportInput;
56
+ if (target[name] !== patched) return;
57
+ if (owned) target[name] = original;
58
+ else delete target[name];
59
59
  };
60
60
  }
61
+
62
+ /** Fullscreen consumes motion before extension listeners; observe its session instance before native dispatch. */
63
+ export function installHoverTracking(tui: object, hover: HoverState, repaint: () => void) {
64
+ return patchMethod<(data: string) => unknown>(
65
+ tui,
66
+ "handleViewportInput",
67
+ (original) =>
68
+ function (this: unknown, data) {
69
+ const mouse = /^\x1b\[<(\d+);\d+;\d+M$/.exec(data);
70
+ if (mouse && (Number(mouse[1]) & 32) !== 0) hover.beginMove(repaint);
71
+ return original.call(this, data);
72
+ },
73
+ );
74
+ }
@@ -0,0 +1,226 @@
1
+ import { visibleWidth } from "@earendil-works/pi-tui";
2
+ import { patchMethod } from "./hover.ts";
3
+
4
+ // CSI, OSC and APC sequences; everything between them is text.
5
+ const escapes = /\x1b(?:\[[0-?]*[ -/]*[@-~]|[\]_][^\x07\x1b]*(?:\x07|\x1b\\))/g;
6
+ const osc8 = /^\x1b\]8;[^;]*;([^\x07\x1b]*)/;
7
+ const wordCharacter = /[\p{L}\p{N}]/u;
8
+
9
+ type Piece = { code: string } | { text: string };
10
+
11
+ function* pieces(line: string): Generator<Piece> {
12
+ let index = 0;
13
+ for (const match of line.matchAll(escapes)) {
14
+ if (match.index > index) yield { text: line.slice(index, match.index) };
15
+ yield { code: match[0] };
16
+ index = match.index + match[0].length;
17
+ }
18
+ if (index < line.length) yield { text: line.slice(index) };
19
+ }
20
+
21
+ /** The underline state an SGR sequence leaves, or undefined when it does not change underline. */
22
+ function underlineAfter(code: string): boolean | undefined {
23
+ const params = /^\x1b\[([\d;:]*)m$/.exec(code)?.[1];
24
+ if (params === undefined) return undefined;
25
+ if (!params) return false;
26
+ let underline: boolean | undefined;
27
+ const parts = params.split(";");
28
+ for (let index = 0; index < parts.length; index++) {
29
+ const part = parts[index]!;
30
+ if (part === "0" || part === "24" || part === "4:0") underline = false;
31
+ else if (part === "4" || part.startsWith("4:")) underline = true;
32
+ // Extended colors carry numbers that are not attributes, such as the 4 in `38;5;4`.
33
+ else if (part === "38" || part === "48" || part === "58")
34
+ index += parts[index + 1] === "5" ? 2 : parts[index + 1] === "2" ? 4 : 0;
35
+ }
36
+ return underline;
37
+ }
38
+
39
+ /** One OSC 8 link on a row. `ordinal` counts the links on the row; `start` and `end` are columns. */
40
+ export interface LinkSpan {
41
+ href: string;
42
+ ordinal: number;
43
+ start: number;
44
+ end: number;
45
+ /** No letter or digit comes before the link: it may continue a link wrapped from the row above. */
46
+ leading: boolean;
47
+ /** No letter or digit comes after the link: it may continue on the row below. */
48
+ trailing: boolean;
49
+ }
50
+
51
+ export function findLinks(line: string): LinkSpan[] {
52
+ if (!line.includes("\x1b]8;")) return [];
53
+ const spans: LinkSpan[] = [];
54
+ // Where each span's text ends in `text`, to look at what follows it once the row is known.
55
+ const ends: number[] = [];
56
+ let text = "";
57
+ let column = 0;
58
+ let open: { href: string; start: number; offset: number } | undefined;
59
+ const close = () => {
60
+ if (!open) return;
61
+ spans.push({
62
+ href: open.href,
63
+ ordinal: spans.length,
64
+ start: open.start,
65
+ end: column,
66
+ leading: !wordCharacter.test(text.slice(0, open.offset)),
67
+ trailing: true,
68
+ });
69
+ ends.push(text.length);
70
+ open = undefined;
71
+ };
72
+ for (const piece of pieces(line)) {
73
+ if ("text" in piece) {
74
+ text += piece.text;
75
+ column += visibleWidth(piece.text);
76
+ continue;
77
+ }
78
+ const link = osc8.exec(piece.code);
79
+ if (!link) continue;
80
+ close();
81
+ if (link[1]) open = { href: link[1], start: column, offset: text.length };
82
+ }
83
+ close();
84
+ spans.forEach((span, index) => {
85
+ span.trailing = !wordCharacter.test(text.slice(ends[index]));
86
+ });
87
+ return spans;
88
+ }
89
+
90
+ /**
91
+ * Link text is underlined only for the links in `picked` (by ordinal); text outside links keeps
92
+ * its own underline.
93
+ */
94
+ export function underlineLinks(line: string, picked?: ReadonlySet<number>): string {
95
+ if (!line.includes("\x1b]8;")) return line;
96
+ let result = "";
97
+ let ordinal = -1;
98
+ let linked = false;
99
+ // Underline as the line asks for it, and as the terminal shows it after our changes.
100
+ let requested = false;
101
+ let shown = false;
102
+ const show = (underline: boolean) => {
103
+ if (underline !== shown) result += underline ? "\x1b[4m" : "\x1b[24m";
104
+ shown = underline;
105
+ };
106
+ for (const piece of pieces(line)) {
107
+ if ("text" in piece) {
108
+ show(linked ? !!picked?.has(ordinal) : requested);
109
+ result += piece.text;
110
+ continue;
111
+ }
112
+ result += piece.code;
113
+ const link = osc8.exec(piece.code);
114
+ if (link) {
115
+ linked = !!link[1];
116
+ if (linked) ordinal++;
117
+ } else {
118
+ const underline = underlineAfter(piece.code);
119
+ if (underline !== undefined) requested = shown = underline;
120
+ }
121
+ }
122
+ show(requested);
123
+ return result;
124
+ }
125
+
126
+ export interface Pointer {
127
+ row: number;
128
+ column: number;
129
+ }
130
+
131
+ function linkAt(lines: readonly string[], pointer: Pointer | undefined) {
132
+ const line = pointer && lines[pointer.row];
133
+ if (!pointer || line === undefined) return undefined;
134
+ return findLinks(line).find(
135
+ (span) => span.start <= pointer.column && pointer.column < span.end,
136
+ );
137
+ }
138
+
139
+ /**
140
+ * The links to underline for a pointer, by row. Only the link under the pointer counts, not other
141
+ * links with the same target; a link wrapped over several rows counts on all of them.
142
+ */
143
+ export function hoveredLinks(
144
+ lines: readonly string[],
145
+ pointer: Pointer | undefined,
146
+ ): Map<number, Set<number>> {
147
+ const picked = new Map<number, Set<number>>();
148
+ const hit = linkAt(lines, pointer);
149
+ if (!pointer || !hit) return picked;
150
+ picked.set(pointer.row, new Set([hit.ordinal]));
151
+ // A wrapped link ends one row and starts the next with nothing but markup around it.
152
+ const extend = (step: 1 | -1) => {
153
+ let span = hit;
154
+ for (let row = pointer.row + step; row >= 0 && row < lines.length; row += step) {
155
+ if (step === 1 ? !span.trailing : !span.leading) return;
156
+ const spans = findLinks(lines[row]!);
157
+ const next = step === 1 ? spans[0] : spans.at(-1);
158
+ if (next?.href !== hit.href || !(step === 1 ? next.leading : next.trailing)) return;
159
+ picked.set(row, new Set([next.ordinal]));
160
+ span = next;
161
+ }
162
+ };
163
+ extend(1);
164
+ extend(-1);
165
+ return picked;
166
+ }
167
+
168
+ /**
169
+ * Pi underlines every link. Each frame drops that underline and adds it to the link under the
170
+ * pointer instead. Only fullscreen reports pointer motion; elsewhere the terminal shows hover.
171
+ */
172
+ export function installLinkHover(tui: object, repaint: () => void) {
173
+ const host = tui as { getScreenLines?: () => string[] };
174
+ let pointer: Pointer | undefined;
175
+ // The main screen passes the whole transcript on every frame, almost all of it unchanged, so
176
+ // rows without a hovered link reuse the last frame's result. Keeping only that frame's rows
177
+ // bounds the cache by what is rendered.
178
+ let previous = new Map<string, string>();
179
+ const stopFrames = patchMethod<(lines: string[]) => string[]>(
180
+ tui,
181
+ "applyLineResets",
182
+ (original) =>
183
+ function (this: unknown, lines) {
184
+ const picked = hoveredLinks(lines, pointer);
185
+ const next = new Map<string, string>();
186
+ for (let row = 0; row < lines.length; row++) {
187
+ const line = lines[row]!;
188
+ const hovered = picked.get(row);
189
+ if (hovered) {
190
+ lines[row] = underlineLinks(line, hovered);
191
+ continue;
192
+ }
193
+ const plain = previous.get(line) ?? underlineLinks(line);
194
+ next.set(line, plain);
195
+ lines[row] = plain;
196
+ }
197
+ previous = next;
198
+ return original.call(this, lines);
199
+ },
200
+ );
201
+ const stopInput = patchMethod<(data: string) => unknown>(
202
+ tui,
203
+ "handleViewportInput",
204
+ (original) =>
205
+ function (this: unknown, data) {
206
+ const mouse = /^\x1b\[<(\d+);(\d+);(\d+)[Mm]$/.exec(data);
207
+ const code = Number(mouse?.[1]);
208
+ // Motion with no button held; a drag selects text and a wheel scrolls it.
209
+ if (mouse && (code & 32) !== 0 && (code & 3) === 3) {
210
+ const screen = host.getScreenLines?.() ?? [];
211
+ const key = (at: Pointer | undefined) => {
212
+ const hit = linkAt(screen, at);
213
+ return hit && `${at!.row}:${hit.ordinal}`;
214
+ };
215
+ const before = key(pointer);
216
+ pointer = { row: Number(mouse[3]) - 1, column: Number(mouse[2]) - 1 };
217
+ if (key(pointer) !== before) repaint();
218
+ }
219
+ return original.call(this, data);
220
+ },
221
+ );
222
+ return () => {
223
+ stopInput();
224
+ stopFrames();
225
+ };
226
+ }