proper-base 0.8.4 → 0.8.5

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.5]
4
+
5
+ Pi 1.7.0 compatibility release. `/tokens max` covers the GPT-6.2 models, automatic restart works for launches that use `--agent-dir`, and two features Pi now provides itself are removed. The package is tested against Pi 1.7.0.
6
+
7
+ ### Improvements
8
+
9
+ - **`/tokens max` for GPT-6.2 Sol, GPT-6.2 Astra, and GPT-6.1 Terra** - These models can use the 922K input window through `openai-codex`, CLIProxyAPI, or the `openai` API.
10
+
11
+ ### Fixes
12
+
13
+ - **Automatic restart with `--agent-dir`** - A Pi started with its new `--agent-dir` flag restarts after an update with the same profile, instead of asking for a manual restart.
14
+
15
+ ### Upgrade Notes
16
+
17
+ - The `↓ jump to bottom` row above the prompt is removed. Pi's own `Jump to latest message` label, shown in the transcript while it is scrolled up, replaces it.
18
+ - `PROPER_WHEEL_SCROLL_LINES` is removed. It has no effect on Pi 1.5.2 or later; set Pi's `fullscreenWheelScrollLines` under `/settings` instead.
19
+ - In a terminal that supports program resume, a Pi restarted by an automatic update reports no resume command. Quit and start Pi again to restore it.
20
+
3
21
  ## [0.8.4]
4
22
 
5
23
  Restores prompt display on Pi 1.5.1 and later, where slash-command prompts showed their expanded body and extra skill blocks appeared as raw text. Update notices and the updater's progress line also work again. The package is tested against Pi 1.5.2.
package/README.md CHANGED
@@ -42,9 +42,9 @@ proactive subagent delegation, and deferred automatic updates.
42
42
  - CLIProxyAPI `empty_stream` failures and `Selected model is at capacity`
43
43
  overload errors become normal retryable network errors, so Pi applies its
44
44
  existing retry budget and backoff.
45
- - `/tokens max` raises an OpenAI model's context window from its 272K default
46
- to the backend's 922K input cap for this session, through `openai-codex`,
47
- CLIProxyAPI, or the `openai` API. `/tokens default` returns to
45
+ - `/tokens max` raises an OpenAI model's context window from its 272K or 500K
46
+ default to the backend's 922K input cap for this session, through
47
+ `openai-codex`, CLIProxyAPI, or the `openai` API. `/tokens default` returns to
48
48
  the default. Append `global` to set it for every session (saved as
49
49
  `contextTokens` in `~/.pi/agent/proper-base.json`); a session choice
50
50
  overrides the global one. Bare `/tokens` shows the current window. Tab on
@@ -173,12 +173,10 @@ to the newest output.
173
173
  | Home, End, PageUp, PageDown | Stay assigned to the prompt editor. |
174
174
  | Ctrl+Shift+Home or End | Jump the transcript to its top or bottom. |
175
175
  | Ctrl+Shift+PageUp or PageDown | Scroll the transcript by one page. |
176
- | Mouse wheel | Scroll three lines per notch instead of Pi's one. |
177
176
  | Double-click | Select a complete one-line URL, path, flag, qualified identifier, or quoted value when possible. |
178
177
 
179
- Set `PROPER_WHEEL_SCROLL_LINES` to a positive integer to change the wheel step,
180
- for example `1` in a terminal that already sends one report per scrolled line.
181
- Wheel and transcript scroll keys keep working while an `ask_user_question`
178
+ The wheel step is Pi's own `fullscreenWheelScrollLines` setting, under
179
+ `/settings`. Wheel and transcript scroll keys keep working while an `ask_user_question`
182
180
  questionnaire or other overlay has focus, so earlier context stays reachable.
183
181
 
184
182
  Typing or pasting clears a mouse selection, so a stale highlight never sits
@@ -190,10 +188,6 @@ quote borders, and screen-width line breaks. Real newlines, paragraph boundaries
190
188
  and code indentation stay intact. Works with copy-on-select and Pi's configured
191
189
  copy shortcut. Lists, tables, and unmatched custom output keep native copying.
192
190
 
193
- Scrolling away from current output adds a `↓ jump to bottom` row above the
194
- prompt. Clicking it returns to the newest output without disabling scrollbar
195
- dragging.
196
-
197
191
  Extension widgets that Pi would pin above the prompt (for example the
198
192
  pi-subagents async-agents card) render at the end of the transcript instead, so
199
193
  they scroll with the session and shrink as their content does rather than
@@ -389,7 +383,7 @@ highlight. Custom replacement footers are not changed.
389
383
 
390
384
  ## Install
391
385
 
392
- Node 22.19 or newer is required. The package is tested against Pi 1.5.2.
386
+ Node 22.19 or newer is required. The package is tested against Pi 1.7.0.
393
387
 
394
388
  From npm:
395
389
 
@@ -431,7 +425,6 @@ described in [UPDATES.md](./UPDATES.md#disable).
431
425
 
432
426
  | Environment variable | Effect |
433
427
  | --- | --- |
434
- | `PROPER_WHEEL_SCROLL_LINES` | Lines per mouse-wheel notch in fullscreen mode. Default `3`. |
435
428
  | `PROPER_UPDATER_OFF=1` | Skips automatic updates for one launch, like `--no-auto-update`. |
436
429
  | `CLIPROXYAPI_FAST` | The provider's Fast override. While it is set, `/fast-global` refuses to write. |
437
430
  | `CLIPROXYAPI_PROVIDER_ID` | Provider ID that Fast mode and `/tokens` treat as CLIProxyAPI. Otherwise `providerId` from `cliproxyapi.json`, then `cliproxyapi`. |
package/UPDATES.md CHANGED
@@ -76,6 +76,11 @@ working directory, Node arguments, Pi options, environment, and the selected
76
76
  persisted session are preserved. A PID-scoped one-shot marker prevents an
77
77
  update/restart loop and is removed before descendants inherit it.
78
78
 
79
+ One variable does not survive: Pi removes the terminal's `OSC7577_TOKEN` when
80
+ it starts. In a terminal that supports program resume, a Pi restarted this way
81
+ reports no resume command, so the terminal cannot bring that session back
82
+ after it restarts itself. Quit and start Pi again to restore that.
83
+
79
84
  Pi has no public restart API. This implementation relies on Pi 0.86's graceful
80
85
  quit ending in `process.exit(0)` and Node's experimental `process.execve`.
81
86
  The restart executable is checked against the installed version before quitting.
@@ -84,7 +89,8 @@ Automatic restart is deferred, with a warning, when:
84
89
 
85
90
  - You type during updates, have an editor draft, or have active/queued work.
86
91
  - The launch includes a prompt, `@file`, `--resume`, `--fork`, `--session-id`,
87
- unknown extension flags, or invalid arguments.
92
+ unknown extension flags, or invalid arguments. Pi's own `--agent-dir` is
93
+ safe: the restarted Pi keeps the same profile.
88
94
  - A selected session cannot be verified on disk, or the updated executable
89
95
  fails its version probe.
90
96
 
package/index.ts CHANGED
@@ -69,7 +69,6 @@ import {
69
69
  type ImagePreviewController,
70
70
  installImagePreview,
71
71
  } from "./src/image-preview.ts";
72
- import { installJumpToBottom } from "./src/jump-to-bottom.ts";
73
72
  import { installOsc8LinkIds } from "./src/osc8-link-ids.ts";
74
73
  import { installOverlayScroll } from "./src/overlay-scroll.ts";
75
74
  import {
@@ -102,7 +101,6 @@ import {
102
101
  type TranscriptCleanupController,
103
102
  } from "./src/transcript-cleanup.ts";
104
103
  import { normalizeCpaTransientError } from "./src/transient-retry.ts";
105
- import { installWheelScrollLines } from "./src/wheel-scroll.ts";
106
104
  import { installWidgetTranscript } from "./src/widget-transcript.ts";
107
105
 
108
106
  /** Prompts seeded into the editor. Older prompts past this point are dropped. */
@@ -371,12 +369,10 @@ export default function (pi: ExtensionAPI) {
371
369
 
372
370
  let removeFooterColors: (() => void) | undefined;
373
371
  let removeKeybindings: (() => void) | undefined;
374
- let removeWheelScroll: (() => void) | undefined;
375
372
  // ctx.ui.addAutocompleteProvider() returns void and stacks permanently, so
376
373
  // re-registering on every session_start would leave one live provider per
377
374
  // session load. Register the model sort exactly once.
378
375
  let autocompleteInstalled = false;
379
- let removeJumpToBottom: (() => void) | undefined;
380
376
  let removePromptJump: (() => void) | undefined;
381
377
  let settings: SettingsController | undefined;
382
378
  let removeEditorMouseGuard: (() => void) | undefined;
@@ -736,13 +732,9 @@ export default function (pi: ExtensionAPI) {
736
732
  stickyDefaults.restore();
737
733
  removeKeybindings?.();
738
734
  removeKeybindings = undefined;
739
- removeWheelScroll?.();
740
- removeWheelScroll = undefined;
741
735
  removeFooterColors?.();
742
736
  removeFooterColors = undefined;
743
737
  fastOverlay.stopDisplayRefresh();
744
- removeJumpToBottom?.();
745
- removeJumpToBottom = undefined;
746
738
  removePromptJump?.();
747
739
  removePromptJump = undefined;
748
740
  settings?.dispose();
@@ -871,9 +863,6 @@ export default function (pi: ExtensionAPI) {
871
863
  new CustomEditor(tui, theme, keybindings);
872
864
  activeEditor = editor as PromptEditor;
873
865
  activeTui = tui;
874
- // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Wheel scroll rate]]
875
- removeWheelScroll?.();
876
- removeWheelScroll = installWheelScrollLines(tui);
877
866
  // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Settled transcript]]
878
867
  transcriptCleanup?.uninstall();
879
868
  transcriptCleanup = installTranscriptCleanup(tui, ctx);
@@ -899,8 +888,6 @@ export default function (pi: ExtensionAPI) {
899
888
  removeOsc8LinkIds?.();
900
889
  removeOsc8LinkIds = installOsc8LinkIds(tui);
901
890
  historyGuard = installHistoryGuard(editor);
902
- removeJumpToBottom?.();
903
- removeJumpToBottom = installJumpToBottom(editor, tui);
904
891
  removePromptJump?.();
905
892
  settings?.dispose();
906
893
  settings = installSettings(tui, editor, getAgentDir(), (error) =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proper-base",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "description": "Baseline Pi behavior for session naming, history, prompt editing, fullscreen navigation, and footer styling",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -60,6 +60,10 @@
60
60
  "@types/node": "25.9.5",
61
61
  "typescript": "6.0.2"
62
62
  },
63
+ "overrides": {
64
+ "cross-spawn@7.0.6": "7.1.2",
65
+ "minimatch@11.0.3": "11.0.9"
66
+ },
63
67
  "pi": {
64
68
  "extensions": [
65
69
  "./index.ts"
@@ -24,6 +24,7 @@ import {
24
24
  run,
25
25
  summary,
26
26
  updateStatus,
27
+ withoutAgentDir,
27
28
  } from "./runtime.ts";
28
29
  import { installSettings } from "./settings.ts";
29
30
 
@@ -63,7 +64,7 @@ export function registerAutoUpdates(pi: ExtensionAPI): void {
63
64
  let settings: ReturnType<typeof installSettings> | undefined;
64
65
  let autoUpdateEnabled = true;
65
66
  const refreshObserver = (ctx: ExtensionContext) => {
66
- const parsed = parseArgs(process.argv.slice(2));
67
+ const parsed = parseArgs(withoutAgentDir(process.argv.slice(2), agentDir));
67
68
  if (
68
69
  ctx.mode === "tui" &&
69
70
  autoUpdateEnabled &&
@@ -102,7 +103,7 @@ export function registerAutoUpdates(pi: ExtensionAPI): void {
102
103
  ctx.ui.notify(result?.slice(0, 1200) || "Updates active.", "info");
103
104
  return;
104
105
  }
105
- const rawArgs = process.argv.slice(2);
106
+ const rawArgs = withoutAgentDir(process.argv.slice(2), agentDir);
106
107
  const parsed = parseArgs(rawArgs);
107
108
  if (
108
109
  ctx.mode !== "tui" ||
@@ -1,6 +1,6 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { type FileHandle, mkdir, open, unlink } from "node:fs/promises";
3
- import { join } from "node:path";
3
+ import { join, resolve } from "node:path";
4
4
  import { stripVTControlCharacters } from "node:util";
5
5
  import type { Args } from "@earendil-works/pi-coding-agent";
6
6
 
@@ -22,6 +22,26 @@ export function consumeRestartMarker(
22
22
  return restarted;
23
23
  }
24
24
 
25
+ /**
26
+ * Pi 1.7.0 takes each `--agent-dir <dir>` pair out of its arguments before
27
+ * parsing them, whatever the value looks like, and applies it through
28
+ * PI_CODING_AGENT_DIR, which a restart inherits. Drop the pairs Pi applied so
29
+ * the parser sees what Pi saw. A pair Pi did not apply stays and reads as an
30
+ * unknown flag, which defers restart.
31
+ */
32
+ // @lat: [[auto-updates#Restart contract]]
33
+ export function withoutAgentDir(raw: string[], agentDir: string): string[] {
34
+ const args: string[] = [];
35
+ for (let i = 0; i < raw.length; i++) {
36
+ const arg = raw[i];
37
+ if (arg === "--") return [...args, ...raw.slice(i)];
38
+ const dir = raw[i + 1];
39
+ if (arg === "--agent-dir" && dir && resolve(dir) === resolve(agentDir)) i++;
40
+ else if (arg !== undefined) args.push(arg);
41
+ }
42
+ return args;
43
+ }
44
+
25
45
  // @lat: [[auto-updates#Restart contract]]
26
46
  export function restartArgs(
27
47
  raw: string[],
@@ -17,8 +17,13 @@ const GLOBAL_KEY = "contextTokens";
17
17
  */
18
18
  const MAX_INPUT = 922_000;
19
19
  const CODEX_MODELS = new Set([
20
- "gpt-6-astra",
20
+ // Not probed: OpenAI documents the same 922,000 maximum input for these
21
+ // four, and Codex's catalog gives them the same 872,000 budget.
22
+ "gpt-6.2-astra",
23
+ "gpt-6.2-sol",
24
+ "gpt-6.1-terra",
21
25
  "gpt-6.1-sol",
26
+ "gpt-6-astra",
22
27
  "gpt-6-sol",
23
28
  "gpt-6-luna",
24
29
  "gpt-5.6-sol",
@@ -124,7 +124,7 @@ export function installFooterColors(
124
124
  // so cache the raw lines per width and drop them whenever a visible input
125
125
  // changes. getLeafId() is O(1) and moves on every appended entry, which is
126
126
  // what the usage totals are derived from.
127
- const baseCache = new Map<number, string[]>();
127
+ const baseCache = new Map<number, readonly string[]>();
128
128
  let baseKey: string | undefined;
129
129
  let baseTheme: FooterTheme | undefined;
130
130
  let baseAt = 0;
@@ -133,7 +133,7 @@ export function installFooterColors(
133
133
  key: string,
134
134
  theme: FooterTheme,
135
135
  now: number,
136
- ): string[] => {
136
+ ): readonly string[] => {
137
137
  if (
138
138
  key !== baseKey ||
139
139
  theme !== baseTheme ||
@@ -196,11 +196,11 @@ export function installFooterColors(
196
196
  * the line keeps its width, matching how the provider's label would sit.
197
197
  */
198
198
  function tagFast(
199
- lines: string[],
199
+ lines: readonly string[],
200
200
  width: number,
201
201
  model: string,
202
202
  theme: FooterTheme,
203
- ): string[] {
203
+ ): readonly string[] {
204
204
  const index = lines.findIndex((line) =>
205
205
  stripTerminalSequences(line).includes(model),
206
206
  );
@@ -237,11 +237,11 @@ function tagFast(
237
237
  }
238
238
 
239
239
  function layoutFooter(
240
- lines: string[],
240
+ lines: readonly string[],
241
241
  width: number,
242
242
  theme: FooterTheme,
243
- reRender?: (width: number) => string[],
244
- ): string[] {
243
+ reRender?: (width: number) => readonly string[],
244
+ ): readonly string[] {
245
245
  if (lines.length < 2 || !Number.isFinite(width) || width < 20) return lines;
246
246
 
247
247
  let statsLine = lines[1];
@@ -331,7 +331,7 @@ function realignFooterRemainder(
331
331
  }
332
332
 
333
333
  function colorFooter(
334
- lines: string[],
334
+ lines: readonly string[],
335
335
  { level, model, now, theme }: FooterColorState,
336
336
  ): string[] {
337
337
  const result = [...lines];
@@ -7,8 +7,7 @@ import {
7
7
  visibleWidth,
8
8
  } from "@earendil-works/pi-tui";
9
9
 
10
- import { prioritize } from "./jump-to-bottom.ts";
11
- import type { OutlineEntry } from "./transcript-cleanup.ts";
10
+ import { type OutlineEntry, prioritize } from "./transcript-cleanup.ts";
12
11
 
13
12
  const INSTALLED = Symbol.for("pi-proper-base.prompt-jump");
14
13
  // Plain arrows rather than arrowheads or chevrons: U+2303/U+2304 and the
@@ -48,7 +48,7 @@ type State = {
48
48
  type AssistantRenderCache = {
49
49
  message: AssistantMessage;
50
50
  width: number;
51
- lines: Map<string, string[]>;
51
+ lines: Map<string, readonly string[]>;
52
52
  };
53
53
  type DetailKind = "tool" | "error";
54
54
  /**
@@ -255,7 +255,9 @@ function renderActive(
255
255
  sink: OutlineEntry[],
256
256
  base: number,
257
257
  ): string[] {
258
- const output: string[][] = Array.from({ length: children.length });
258
+ const output: (readonly string[])[] = Array.from({
259
+ length: children.length,
260
+ });
259
261
  const hits: DetailHit[][] = Array.from({ length: children.length });
260
262
  let hasTextBelow = false;
261
263
  for (let index = children.length - 1; index >= 0; index--) {
@@ -484,7 +486,7 @@ function renderExpandable(
484
486
  child: Component,
485
487
  width: number,
486
488
  state: State,
487
- ): string[] {
489
+ ): readonly string[] {
488
490
  const expandable = child as ToolComponent;
489
491
  if (typeof expandable.setExpanded !== "function") return child.render(width);
490
492
  expandable.setExpanded(state.expanded.get(child) ?? state.globalExpanded);
@@ -506,7 +508,7 @@ function renderAssistantContent(
506
508
  content: AssistantMessage["content"],
507
509
  width: number,
508
510
  state: State,
509
- ): string[] {
511
+ ): readonly string[] {
510
512
  if (!assistant.updateContent) return assistant.render(width);
511
513
  // The updateContent swap below rebuilds the component's children and
512
514
  // discards their internal render caches, so re-running it every frame
@@ -530,11 +532,11 @@ function renderAssistantContent(
530
532
  }
531
533
  }
532
534
 
533
- function withVerticalSpacing(lines: string[]): string[] {
535
+ function withVerticalSpacing(lines: readonly string[]): string[] {
534
536
  return lines.length ? ["", ...lines, ""] : [];
535
537
  }
536
538
 
537
- function hasSectionText(lines: string[]): boolean {
539
+ function hasSectionText(lines: readonly string[]): boolean {
538
540
  return lines.some((line) => {
539
541
  const text = stripTerminalSequences(line).trim();
540
542
  return (
@@ -716,7 +718,14 @@ function screenLines(tui: TUI): string[] {
716
718
  return host.previousScreen ?? host.previousLines ?? [];
717
719
  }
718
720
 
719
- function prioritize(tui: TUI, listener: TuiInputListener): void {
721
+ /**
722
+ * Pi's alternate-screen renderer consumes every mouse event from a listener it
723
+ * registers in its own constructor, so an extension listener never sees a
724
+ * click. Moving ours to the front of the set is the only way a control can
725
+ * respond to the mouse; if that internal field ever changes shape the control
726
+ * keeps rendering and simply stops reacting.
727
+ */
728
+ export function prioritize(tui: TUI, listener: TuiInputListener): void {
720
729
  const listeners = (tui as MouseTui).inputListeners;
721
730
  if (!listeners?.has(listener)) return;
722
731
  const rest = [...listeners].filter((entry) => entry !== listener);
@@ -1,126 +0,0 @@
1
- import type { Component, TUI, TuiInputListener } from "@earendil-works/pi-tui";
2
- import { visibleWidth } from "@earendil-works/pi-tui";
3
-
4
- import { rowsBelow } from "./autocomplete-details.ts";
5
-
6
- const INSTALLED = Symbol.for("pi-proper-base.jump-to-bottom");
7
- const LABEL = "↓ jump to bottom";
8
- const COMPACT_LABEL = "↓";
9
- /** Columns kept clear to the right of the button, matching the footer. */
10
- const RIGHT_GAP = 1;
11
- // ESC prefix is matched separately: biome bans control characters in
12
- // regexes, and string literals carry it fine.
13
- const SGR_MOUSE_TAIL = /^\[<(\d+);(\d+);(\d+)([Mm])$/;
14
- const LEFT_BUTTON = "0";
15
-
16
- /** Alternate-screen renderer surface used for the button. */
17
- type ScrollableTui = TUI & {
18
- readonly isFollowingOutput: boolean;
19
- scrollToBottom(): void;
20
- };
21
- type ListenerHost = TUI & { inputListeners?: Set<TuiInputListener> };
22
- type JumpEditor = Component & { [INSTALLED]?: () => void };
23
- /** Screen position of the rendered button, in 0-based terminal cells. */
24
- type Hit = { row: number; start: number; end: number };
25
-
26
- function scrollableTui(tui: TUI): ScrollableTui | undefined {
27
- const candidate = tui as Partial<ScrollableTui>;
28
- return typeof candidate.scrollToBottom === "function" &&
29
- typeof candidate.isFollowingOutput === "boolean"
30
- ? (candidate as ScrollableTui)
31
- : undefined;
32
- }
33
-
34
- /**
35
- * Pi's alternate-screen renderer consumes every mouse event from a listener it
36
- * registers in its own constructor, so an extension listener never sees a
37
- * click. Moving ours to the front of the set is the only way the button can
38
- * respond to the mouse; if that internal field ever changes shape the button
39
- * keeps rendering and simply stops reacting.
40
- */
41
- export function prioritize(tui: TUI, listener: TuiInputListener): void {
42
- const listeners = (tui as ListenerHost).inputListeners;
43
- if (!listeners?.has(listener)) return;
44
- const rest = [...listeners].filter((entry) => entry !== listener);
45
- listeners.clear();
46
- listeners.add(listener);
47
- for (const entry of rest) listeners.add(entry);
48
- }
49
-
50
- /**
51
- * Render a clickable jump-to-bottom button above the prompt while the
52
- * transcript viewport is scrolled up.
53
- *
54
- * The row is part of the editor's own render output rather than an overlay:
55
- * any visible overlay disables Pi's scrollbar dragging, which is exactly the
56
- * gesture in use while the button is on screen.
57
- *
58
- * Regular-mode terminals scroll themselves, so nothing is installed there.
59
- */
60
- export function installJumpToBottom(
61
- editor: Component,
62
- tui: TUI,
63
- ): (() => void) | undefined {
64
- const target = editor as JumpEditor;
65
- const existing = target[INSTALLED];
66
- if (existing) return existing;
67
- const view = scrollableTui(tui);
68
- if (!view) return undefined;
69
-
70
- let hit: Hit | undefined;
71
-
72
- const render = target.render.bind(target);
73
- target.render = (width: number) => {
74
- const lines = render(width);
75
- if (view.isFollowingOutput) {
76
- hit = undefined;
77
- return lines;
78
- }
79
-
80
- const label =
81
- width >= visibleWidth(LABEL) + 2 + RIGHT_GAP ? LABEL : COMPACT_LABEL;
82
- const chipWidth = visibleWidth(label) + 2;
83
- const start = width - RIGHT_GAP - chipWidth;
84
- if (start < 0) {
85
- hit = undefined;
86
- return lines;
87
- }
88
-
89
- hit = {
90
- row: tui.terminal.rows - lines.length - 1 - rowsBelow(tui, target, width),
91
- start,
92
- end: start + chipWidth,
93
- };
94
- return [
95
- `${" ".repeat(start)}\x1b[7m ${label} \x1b[0m${" ".repeat(RIGHT_GAP)}`,
96
- ...lines,
97
- ];
98
- };
99
-
100
- const listener: TuiInputListener = (data) => {
101
- const button = hit;
102
- if (!button) return undefined;
103
- if (!data.startsWith("\x1b")) return undefined;
104
- const match = SGR_MOUSE_TAIL.exec(data.slice(1));
105
- if (!match || match[1] !== LEFT_BUTTON) return undefined;
106
- const column = Number.parseInt(match[2] ?? "", 10) - 1;
107
- const row = Number.parseInt(match[3] ?? "", 10) - 1;
108
- if (row !== button.row || column < button.start || column >= button.end) {
109
- return undefined;
110
- }
111
- // Consume the release too, so the renderer never sees a half press and
112
- // starts a text selection at the button.
113
- if (match[4] === "M") view.scrollToBottom();
114
- return { consume: true };
115
- };
116
- const unsubscribe = tui.addInputListener(listener);
117
- prioritize(tui, listener);
118
-
119
- const dispose = () => {
120
- unsubscribe();
121
- hit = undefined;
122
- delete target[INSTALLED];
123
- };
124
- target[INSTALLED] = dispose;
125
- return dispose;
126
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * Pi's fullscreen renderer scrolls its transcript exactly one line per
3
- * mouse-wheel report. Proper-base raises that to the terminal convention.
4
- */
5
-
6
- const DEFAULT_WHEEL_SCROLL_LINES = 3;
7
- const INSTALLED = Symbol.for("pi-proper-base.wheel-scroll-lines");
8
-
9
- type WheelController = { restore(): void };
10
- type WheelHost = {
11
- wheelScrollLines?: unknown;
12
- [INSTALLED]?: WheelController;
13
- };
14
-
15
- /** Lines per wheel event: a positive integer override, else three. */
16
- export function resolveWheelScrollLines(
17
- env: Record<string, string | undefined> = process.env,
18
- ): number {
19
- const parsed = Number.parseInt(env.PROPER_WHEEL_SCROLL_LINES ?? "", 10);
20
- return parsed >= 1 ? parsed : DEFAULT_WHEEL_SCROLL_LINES;
21
- }
22
-
23
- /** Patch a fullscreen renderer and return an ownership-checked restoration. */
24
- export function installWheelScrollLines(
25
- tui: unknown,
26
- lines: number = resolveWheelScrollLines(),
27
- ): (() => void) | undefined {
28
- const host = tui as WheelHost;
29
- host[INSTALLED]?.restore();
30
- if (typeof host.wheelScrollLines !== "number") return undefined;
31
- const original = host.wheelScrollLines;
32
- const applied = Math.floor(lines);
33
- const controller: WheelController = {
34
- restore() {
35
- if (host[INSTALLED] !== controller) return;
36
- if (host.wheelScrollLines === applied) host.wheelScrollLines = original;
37
- delete host[INSTALLED];
38
- },
39
- };
40
- host.wheelScrollLines = applied;
41
- host[INSTALLED] = controller;
42
- return () => controller.restore();
43
- }