proper-base 0.6.0 → 0.7.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.
@@ -1,22 +1,18 @@
1
1
  /**
2
2
  * Pi's fullscreen renderer scrolls its transcript exactly one line per
3
- * mouse-wheel report: the renderer's `wheelScrollLines` option defaults to 1
4
- * and pi passes no override and exposes no setting. Terminals natively
5
- * multiply a wheel notch to about three lines, so fullscreen scrolling feels
6
- * slower than every other terminal surface.
7
- *
8
- * No escape sequence lets an application query the terminal's own wheel
9
- * configuration, so the step defaults to the 3-line application convention
10
- * (vim, less) and honors a per-terminal `PROPER_WHEEL_SCROLL_LINES`
11
- * environment override that each terminal's profile can export.
3
+ * mouse-wheel report. Proper-base raises that to the terminal convention.
12
4
  */
13
5
 
14
6
  const DEFAULT_WHEEL_SCROLL_LINES = 3;
7
+ const INSTALLED = Symbol.for("pi-proper-base.wheel-scroll-lines");
15
8
 
16
- /** Renderer surface carrying the per-wheel-event line count. */
17
- type WheelHost = { wheelScrollLines?: unknown };
9
+ type WheelController = { restore(): void };
10
+ type WheelHost = {
11
+ wheelScrollLines?: unknown;
12
+ [INSTALLED]?: WheelController;
13
+ };
18
14
 
19
- /** Lines per wheel event: a positive integer override, else the 3-line convention. */
15
+ /** Lines per wheel event: a positive integer override, else three. */
20
16
  export function resolveWheelScrollLines(
21
17
  env: Record<string, string | undefined> = process.env,
22
18
  ): number {
@@ -24,23 +20,24 @@ export function resolveWheelScrollLines(
24
20
  return parsed >= 1 ? parsed : DEFAULT_WHEEL_SCROLL_LINES;
25
21
  }
26
22
 
27
- /**
28
- * Raise the fullscreen renderer's wheel step. Only a renderer that already
29
- * exposes a numeric `wheelScrollLines` is touched, so regular mode — where
30
- * the terminal scrolls natively — and a renamed upstream field fail open to
31
- * pi's own behavior.
32
- *
33
- * ponytail: SGR wheel reports cannot distinguish a discrete mouse notch from
34
- * one line of a high-rate trackpad stream, so a terminal emitting one report
35
- * per native line scrolls proportionally faster; exporting
36
- * PROPER_WHEEL_SCROLL_LINES=1 there restores pi's original pace.
37
- */
23
+ /** Patch a fullscreen renderer and return an ownership-checked restoration. */
38
24
  export function installWheelScrollLines(
39
25
  tui: unknown,
40
26
  lines: number = resolveWheelScrollLines(),
41
- ): boolean {
27
+ ): (() => void) | undefined {
42
28
  const host = tui as WheelHost;
43
- if (typeof host.wheelScrollLines !== "number") return false;
44
- host.wheelScrollLines = Math.floor(lines);
45
- return true;
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();
46
43
  }