@narumitw/pi-btw 0.58.1 → 0.59.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,11 +1,11 @@
1
1
  import {
2
- isKeyRelease,
3
- isKittyProtocolActive,
4
- KeybindingsManager,
5
- type KeyId,
6
- matchesKey,
7
- type TUI,
8
- TUI_KEYBINDINGS,
2
+ isKeyRelease,
3
+ isKittyProtocolActive,
4
+ KeybindingsManager,
5
+ type KeyId,
6
+ matchesKey,
7
+ type TUI,
8
+ TUI_KEYBINDINGS,
9
9
  } from "@earendil-works/pi-tui";
10
10
  import { formatKeyLabel } from "./text.js";
11
11
 
@@ -16,315 +16,273 @@ export type BtwKeybindingOverrides = Partial<Record<BtwShortcutAction, string>>;
16
16
  const MODIFIERS = ["shift", "alt", "ctrl", "super"] as const;
17
17
  const SYMBOLS = "`-=[]\\;',./!@#$%^&*()_|~{}:<>?";
18
18
  const SPECIAL: Record<string, number> = {
19
- escape: 27,
20
- tab: 9,
21
- enter: 13,
22
- space: 32,
23
- backspace: 127,
24
- insert: 57425,
25
- delete: 57426,
26
- home: 57423,
27
- end: 57424,
28
- pageup: 57421,
29
- pagedown: 57422,
30
- left: 57417,
31
- right: 57418,
32
- up: 57419,
33
- down: 57420,
19
+ escape: 27,
20
+ tab: 9,
21
+ enter: 13,
22
+ space: 32,
23
+ backspace: 127,
24
+ insert: 57425,
25
+ delete: 57426,
26
+ home: 57423,
27
+ end: 57424,
28
+ pageup: 57421,
29
+ pagedown: 57422,
30
+ left: 57417,
31
+ right: 57418,
32
+ up: 57419,
33
+ down: 57420,
34
34
  };
35
- const FUNCTION_INPUTS = [
36
- "OP",
37
- "OQ",
38
- "OR",
39
- "OS",
40
- "[15~",
41
- "[17~",
42
- "[18~",
43
- "[19~",
44
- "[20~",
45
- "[21~",
46
- "[23~",
47
- "[24~",
48
- ];
35
+ const FUNCTION_INPUTS = ["OP", "OQ", "OR", "OS", "[15~", "[17~", "[18~", "[19~", "[20~", "[21~", "[23~", "[24~"];
49
36
  // All cross-identity legacy collisions in Pi's matchesKey(): raw Ctrl bytes,
50
37
  // ESC-prefixed bytes (including Alt+arrows), BS/DEL, Enter and Shift+Tab.
51
38
  // CSI-u, keypad, lock bits, shifted letters and modifyOtherKeys normalize to
52
39
  // the same key+modifiers; probe that identity instead of duplicating the parser.
53
40
  const LEGACY_INPUTS = [
54
- ...Array.from({ length: 128 }, (_, code) => String.fromCharCode(code)),
55
- ...Array.from({ length: 128 }, (_, code) => `\u001b${String.fromCharCode(code)}`),
56
- "\u001b[Z",
57
- "\u001bOM",
58
- "\u001b[E",
59
- "\u001b[e",
60
- "\u001bOe",
61
- ...FUNCTION_INPUTS.map((suffix) => `\u001b${suffix}`),
41
+ ...Array.from({ length: 128 }, (_, code) => String.fromCharCode(code)),
42
+ ...Array.from({ length: 128 }, (_, code) => `\u001b${String.fromCharCode(code)}`),
43
+ "\u001b[Z",
44
+ "\u001bOM",
45
+ "\u001b[E",
46
+ "\u001b[e",
47
+ "\u001bOe",
48
+ ...FUNCTION_INPUTS.map((suffix) => `\u001b${suffix}`),
62
49
  ];
63
50
 
64
51
  /** Strict settings syntax; Pi itself ignores unknown/duplicate modifier tokens. */
65
52
  export function normalizeBtwKey(value: unknown): string | undefined {
66
- if (typeof value !== "string" || value.length > 80 || /[\s\p{Cc}]/u.test(value)) return undefined;
67
- const parts = value.toLowerCase().split("+");
68
- let base = parts.pop();
69
- if (!base) return undefined;
70
- if (base === "esc") base = "escape";
71
- if (base === "return") base = "enter";
72
- if (
73
- new Set(parts).size !== parts.length ||
74
- parts.some((part) => !MODIFIERS.includes(part as never))
75
- )
76
- return undefined;
77
- if (
78
- !Object.hasOwn(SPECIAL, base) &&
79
- base !== "clear" &&
80
- !/^f(?:[1-9]|1[0-2])$/u.test(base) &&
81
- !(base.length === 1 && (/^[a-z0-9]$/u.test(base) || SYMBOLS.includes(base)))
82
- )
83
- return undefined;
84
- if ((base === "escape" || (base.startsWith("f") && base.length > 1)) && parts.length)
85
- return undefined;
86
- if (
87
- base === "clear" &&
88
- (parts.length > 1 || (parts.length === 1 && !["ctrl", "shift"].includes(parts[0] ?? "")))
89
- )
90
- return undefined;
91
- return [...MODIFIERS.filter((part) => parts.includes(part)), base].join("+");
53
+ if (typeof value !== "string" || value.length > 80 || /[\s\p{Cc}]/u.test(value)) return undefined;
54
+ const parts = value.toLowerCase().split("+");
55
+ let base = parts.pop();
56
+ if (!base) return undefined;
57
+ if (base === "esc") base = "escape";
58
+ if (base === "return") base = "enter";
59
+ if (new Set(parts).size !== parts.length || parts.some((part) => !MODIFIERS.includes(part as never)))
60
+ return undefined;
61
+ if (
62
+ !Object.hasOwn(SPECIAL, base) &&
63
+ base !== "clear" &&
64
+ !/^f(?:[1-9]|1[0-2])$/u.test(base) &&
65
+ !(base.length === 1 && (/^[a-z0-9]$/u.test(base) || SYMBOLS.includes(base)))
66
+ )
67
+ return undefined;
68
+ if ((base === "escape" || (base.startsWith("f") && base.length > 1)) && parts.length) return undefined;
69
+ if (base === "clear" && (parts.length > 1 || (parts.length === 1 && !["ctrl", "shift"].includes(parts[0] ?? ""))))
70
+ return undefined;
71
+ return [...MODIFIERS.filter((part) => parts.includes(part)), base].join("+");
92
72
  }
93
73
 
94
74
  /** Representative inputs are checked by Pi, including its live terminal-mode branches. */
95
75
  function inputsFor(key: string): string[] {
96
- const parts = key.split("+");
97
- const base = parts.pop() ?? "";
98
- const modifier = MODIFIERS.reduce(
99
- (mask, part, bit) => mask | (parts.includes(part) ? 1 << bit : 0),
100
- 0,
101
- );
102
- const code = SPECIAL[base] ?? (base.length === 1 ? base.charCodeAt(0) : undefined);
103
- const inputs =
104
- code === undefined ? LEGACY_INPUTS : [...LEGACY_INPUTS, `\u001b[${code};${modifier + 1}u`];
105
- return inputs.filter((input) => matchesKey(input, key as KeyId));
76
+ const parts = key.split("+");
77
+ const base = parts.pop() ?? "";
78
+ const modifier = MODIFIERS.reduce((mask, part, bit) => mask | (parts.includes(part) ? 1 << bit : 0), 0);
79
+ const code = SPECIAL[base] ?? (base.length === 1 ? base.charCodeAt(0) : undefined);
80
+ const inputs = code === undefined ? LEGACY_INPUTS : [...LEGACY_INPUTS, `\u001b[${code};${modifier + 1}u`];
81
+ return inputs.filter((input) => matchesKey(input, key as KeyId));
106
82
  }
107
83
 
108
84
  export function btwKeysOverlap(first: string, second: string): boolean {
109
- const normalized = normalizeBtwKey(first);
110
- return (
111
- normalized !== undefined &&
112
- inputsFor(normalized).some((input) => matchesKey(input, second as KeyId))
113
- );
85
+ const normalized = normalizeBtwKey(first);
86
+ return normalized !== undefined && inputsFor(normalized).some((input) => matchesKey(input, second as KeyId));
114
87
  }
115
88
 
116
89
  export interface BtwShortcuts {
117
- keys: Record<BtwShortcutAction, readonly string[]>;
118
- warnings: readonly string[];
119
- matches(data: string, action: BtwShortcutAction): boolean;
120
- label(action: BtwShortcutAction): string;
90
+ keys: Record<BtwShortcutAction, readonly string[]>;
91
+ warnings: readonly string[];
92
+ matches(data: string, action: BtwShortcutAction): boolean;
93
+ label(action: BtwShortcutAction): string;
121
94
  }
122
95
 
123
96
  function reservedKeys(keybindings: KeybindingsManager, copyOnSelect: boolean): string[] {
124
- // Editor has no autocomplete provider here. Select bindings are still reserved
125
- // because exit also applies to BTW-owned nested review/menu components.
126
- return [
127
- "ctrl+c",
128
- "shift+backspace",
129
- "shift+delete",
130
- "shift+space",
131
- // Exact-range review uses these fixed selection actions even if Editor is remapped.
132
- "shift+left",
133
- "shift+right",
134
- "shift+up",
135
- "shift+down",
136
- "left",
137
- "right",
138
- "enter",
139
- "alt+enter",
140
- "ctrl+j",
141
- "pageUp",
142
- "pageDown",
143
- ...Object.keys(TUI_KEYBINDINGS).flatMap((id) =>
144
- keybindings.getKeys(id as keyof typeof TUI_KEYBINDINGS),
145
- ),
146
- ...(!copyOnSelect ? keybindings.getKeys("app.message.copy") : []),
147
- ];
97
+ // Editor has no autocomplete provider here. Select bindings are still reserved
98
+ // because exit also applies to BTW-owned nested review/menu components.
99
+ return [
100
+ "ctrl+c",
101
+ "shift+backspace",
102
+ "shift+delete",
103
+ "shift+space",
104
+ // Exact-range review uses these fixed selection actions even if Editor is remapped.
105
+ "shift+left",
106
+ "shift+right",
107
+ "shift+up",
108
+ "shift+down",
109
+ "left",
110
+ "right",
111
+ "enter",
112
+ "alt+enter",
113
+ "ctrl+j",
114
+ "pageUp",
115
+ "pageDown",
116
+ ...Object.keys(TUI_KEYBINDINGS).flatMap((id) => keybindings.getKeys(id as keyof typeof TUI_KEYBINDINGS)),
117
+ ...(!copyOnSelect ? keybindings.getKeys("app.message.copy") : []),
118
+ ];
148
119
  }
149
120
 
150
121
  function isTextKey(key: string): boolean {
151
- const parts = key.split("+");
152
- const base = parts.at(-1) ?? "";
153
- return (
154
- (base.length === 1 || base === "space") &&
155
- !parts.some((part) => ["ctrl", "alt", "super"].includes(part))
156
- );
122
+ const parts = key.split("+");
123
+ const base = parts.at(-1) ?? "";
124
+ return (base.length === 1 || base === "space") && !parts.some((part) => ["ctrl", "alt", "super"].includes(part));
157
125
  }
158
126
 
159
127
  export function resolveBtwShortcuts(
160
- overrides: BtwKeybindingOverrides = {},
161
- keybindings: KeybindingsManager,
162
- copyOnSelect = true,
128
+ overrides: BtwKeybindingOverrides = {},
129
+ keybindings: KeybindingsManager,
130
+ copyOnSelect = true,
163
131
  ): BtwShortcuts {
164
- let mode = isKittyProtocolActive();
165
- let snapshot = resolveShortcutSnapshot(overrides, keybindings, copyOnSelect);
166
- const current = () => {
167
- if (mode !== isKittyProtocolActive()) {
168
- mode = isKittyProtocolActive();
169
- snapshot = resolveShortcutSnapshot(overrides, keybindings, copyOnSelect);
170
- }
171
- return snapshot;
172
- };
173
- // ProcessTerminal negotiates Kitty asynchronously after the dedicated TUI starts.
174
- // Hints and matching must use the same policy after that mode transition.
175
- return {
176
- get keys() {
177
- return current().keys;
178
- },
179
- get warnings() {
180
- return current().warnings;
181
- },
182
- matches: (data, action) => current().matches(data, action),
183
- label: (action) => current().label(action),
184
- };
132
+ let mode = isKittyProtocolActive();
133
+ let snapshot = resolveShortcutSnapshot(overrides, keybindings, copyOnSelect);
134
+ const current = () => {
135
+ if (mode !== isKittyProtocolActive()) {
136
+ mode = isKittyProtocolActive();
137
+ snapshot = resolveShortcutSnapshot(overrides, keybindings, copyOnSelect);
138
+ }
139
+ return snapshot;
140
+ };
141
+ // ProcessTerminal negotiates Kitty asynchronously after the dedicated TUI starts.
142
+ // Hints and matching must use the same policy after that mode transition.
143
+ return {
144
+ get keys() {
145
+ return current().keys;
146
+ },
147
+ get warnings() {
148
+ return current().warnings;
149
+ },
150
+ matches: (data, action) => current().matches(data, action),
151
+ label: (action) => current().label(action),
152
+ };
185
153
  }
186
154
 
187
155
  function resolveShortcutSnapshot(
188
- overrides: BtwKeybindingOverrides = {},
189
- keybindings: KeybindingsManager,
190
- copyOnSelect = true,
156
+ overrides: BtwKeybindingOverrides = {},
157
+ keybindings: KeybindingsManager,
158
+ copyOnSelect = true,
191
159
  ): BtwShortcuts {
192
- const reserved = reservedKeys(keybindings, copyOnSelect);
193
- const keys: BtwShortcuts["keys"] = { exit: ["ctrl+c"], cycleThinkingLevel: [], bringToMain: [] };
194
- const warnings: string[] = [];
195
- const defaults: Record<BtwShortcutAction, readonly string[]> = {
196
- exit: ["ctrl+c"],
197
- cycleThinkingLevel: keybindings.getKeys("app.thinking.cycle"),
198
- bringToMain: ["ctrl+r"],
199
- };
200
- const usable = (
201
- action: BtwShortcutAction,
202
- candidate: string,
203
- inherited = false,
204
- ): string | undefined => {
205
- const key = normalizeBtwKey(candidate);
206
- if (!key || (!inherited && isTextKey(key))) return undefined;
207
- const inputs = inputsFor(key);
208
- if (!inputs.length) return undefined;
209
- if (action === "exit" && key === "ctrl+c") return key;
210
- if (
211
- reserved.some(
212
- (other) =>
213
- typeof other === "string" && inputs.some((input) => matchesKey(input, other as KeyId)),
214
- )
215
- )
216
- return undefined;
217
- return key;
218
- };
219
- const candidates: BtwKeybindingOverrides = {};
220
- const availableDefaults = { ...defaults };
221
- for (const action of BTW_SHORTCUT_ACTIONS) {
222
- availableDefaults[action] = defaults[action]
223
- .map((key) => usable(action, key, action === "cycleThinkingLevel"))
224
- .filter((key): key is string => key !== undefined);
225
- const override = overrides[action];
226
- if (override !== undefined) candidates[action] = usable(action, override);
227
- }
228
- // Compare the complete proposal, not only actions visited earlier. Reject conflicts
229
- // together, then repeat because a rejected override restores its default bindings.
230
- for (;;) {
231
- const rejected = BTW_SHORTCUT_ACTIONS.filter((action) => {
232
- const candidate = candidates[action];
233
- return (
234
- candidate !== undefined &&
235
- BTW_SHORTCUT_ACTIONS.some(
236
- (other) =>
237
- other !== action &&
238
- (candidates[other] ? [candidates[other]] : availableDefaults[other]).some((key) =>
239
- btwKeysOverlap(candidate, key),
240
- ),
241
- )
242
- );
243
- });
244
- if (!rejected.length) break;
245
- for (const action of rejected) delete candidates[action];
246
- }
247
- for (const action of BTW_SHORTCUT_ACTIONS) {
248
- const override = overrides[action];
249
- const selected = candidates[action];
250
- if (override !== undefined && !selected)
251
- warnings.push(
252
- `${action}: configured shortcut is invalid or conflicts with a reserved action; using an available default.`,
253
- );
254
- const effective = selected
255
- ? [selected]
256
- : availableDefaults[action].filter(
257
- (key) =>
258
- !BTW_SHORTCUT_ACTIONS.some(
259
- (other) => other !== action && keys[other].some((used) => btwKeysOverlap(key, used)),
260
- ),
261
- );
262
- keys[action] = action === "exit" ? [...new Set([...effective, "ctrl+c"])] : effective;
263
- if (!keys[action].length && (override !== undefined || defaults[action].length > 0))
264
- warnings.push(`${action}: no usable shortcut; change Pi BTW Settings or Pi keybindings.`);
265
- }
266
- return {
267
- keys,
268
- warnings,
269
- matches: (data, action) =>
270
- !isKeyRelease(data) && keys[action].some((key) => matchesKey(data, key as KeyId)),
271
- label: (action) =>
272
- keys[action].length ? formatKeyLabel(keys[action][0] ?? "") : "Unavailable",
273
- };
160
+ const reserved = reservedKeys(keybindings, copyOnSelect);
161
+ const keys: BtwShortcuts["keys"] = { exit: ["ctrl+c"], cycleThinkingLevel: [], bringToMain: [] };
162
+ const warnings: string[] = [];
163
+ const defaults: Record<BtwShortcutAction, readonly string[]> = {
164
+ exit: ["ctrl+c"],
165
+ cycleThinkingLevel: keybindings.getKeys("app.thinking.cycle"),
166
+ bringToMain: ["ctrl+r"],
167
+ };
168
+ const usable = (action: BtwShortcutAction, candidate: string, inherited = false): string | undefined => {
169
+ const key = normalizeBtwKey(candidate);
170
+ if (!key || (!inherited && isTextKey(key))) return undefined;
171
+ const inputs = inputsFor(key);
172
+ if (!inputs.length) return undefined;
173
+ if (action === "exit" && key === "ctrl+c") return key;
174
+ if (
175
+ reserved.some((other) => typeof other === "string" && inputs.some((input) => matchesKey(input, other as KeyId)))
176
+ )
177
+ return undefined;
178
+ return key;
179
+ };
180
+ const candidates: BtwKeybindingOverrides = {};
181
+ const availableDefaults = { ...defaults };
182
+ for (const action of BTW_SHORTCUT_ACTIONS) {
183
+ availableDefaults[action] = defaults[action]
184
+ .map((key) => usable(action, key, action === "cycleThinkingLevel"))
185
+ .filter((key): key is string => key !== undefined);
186
+ const override = overrides[action];
187
+ if (override !== undefined) candidates[action] = usable(action, override);
188
+ }
189
+ // Compare the complete proposal, not only actions visited earlier. Reject conflicts
190
+ // together, then repeat because a rejected override restores its default bindings.
191
+ for (;;) {
192
+ const rejected = BTW_SHORTCUT_ACTIONS.filter((action) => {
193
+ const candidate = candidates[action];
194
+ return (
195
+ candidate !== undefined &&
196
+ BTW_SHORTCUT_ACTIONS.some(
197
+ (other) =>
198
+ other !== action &&
199
+ (candidates[other] ? [candidates[other]] : availableDefaults[other]).some((key) =>
200
+ btwKeysOverlap(candidate, key),
201
+ ),
202
+ )
203
+ );
204
+ });
205
+ if (!rejected.length) break;
206
+ for (const action of rejected) delete candidates[action];
207
+ }
208
+ for (const action of BTW_SHORTCUT_ACTIONS) {
209
+ const override = overrides[action];
210
+ const selected = candidates[action];
211
+ if (override !== undefined && !selected)
212
+ warnings.push(
213
+ `${action}: configured shortcut is invalid or conflicts with a reserved action; using an available default.`,
214
+ );
215
+ const effective = selected
216
+ ? [selected]
217
+ : availableDefaults[action].filter(
218
+ (key) =>
219
+ !BTW_SHORTCUT_ACTIONS.some(
220
+ (other) => other !== action && keys[other].some((used) => btwKeysOverlap(key, used)),
221
+ ),
222
+ );
223
+ keys[action] = action === "exit" ? [...new Set([...effective, "ctrl+c"])] : effective;
224
+ if (!keys[action].length && (override !== undefined || defaults[action].length > 0))
225
+ warnings.push(`${action}: no usable shortcut; change Pi BTW Settings or Pi keybindings.`);
226
+ }
227
+ return {
228
+ keys,
229
+ warnings,
230
+ matches: (data, action) => !isKeyRelease(data) && keys[action].some((key) => matchesKey(data, key as KeyId)),
231
+ label: (action) => (keys[action].length ? formatKeyLabel(keys[action][0] ?? "") : "Unavailable"),
232
+ };
274
233
  }
275
234
 
276
235
  export function validateBtwShortcutEdit(
277
- action: BtwShortcutAction,
278
- value: string | undefined,
279
- overrides: BtwKeybindingOverrides,
280
- keybindings: KeybindingsManager,
281
- copyOnSelect: boolean,
236
+ action: BtwShortcutAction,
237
+ value: string | undefined,
238
+ overrides: BtwKeybindingOverrides,
239
+ keybindings: KeybindingsManager,
240
+ copyOnSelect: boolean,
282
241
  ): string | undefined {
283
- // Reset must remain available even when several existing overrides conflict.
284
- if (value === undefined) return undefined;
285
- if (!normalizeBtwKey(value))
286
- return "Invalid key combination. Use a Pi key name such as ctrl+q or f6.";
287
- const next = { ...overrides, [action]: value };
288
- const resolved = resolveBtwShortcuts(next, keybindings, copyOnSelect);
289
- const previous = resolveBtwShortcuts(overrides, keybindings, copyOnSelect);
290
- // Reject edits that disable another binding as well as the edited binding.
291
- for (const item of BTW_SHORTCUT_ACTIONS) {
292
- if (
293
- (item === action && !resolved.keys[item].includes(normalizeBtwKey(value) ?? "")) ||
294
- (item !== action && previous.keys[item].some((key) => !resolved.keys[item].includes(key)))
295
- ) {
296
- return `${item} conflicts with another BTW shortcut, editing, selection, search, scrolling, or copying. Choose a different key.`;
297
- }
298
- }
299
- return undefined;
242
+ // Reset must remain available even when several existing overrides conflict.
243
+ if (value === undefined) return undefined;
244
+ if (!normalizeBtwKey(value)) return "Invalid key combination. Use a Pi key name such as ctrl+q or f6.";
245
+ const next = { ...overrides, [action]: value };
246
+ const resolved = resolveBtwShortcuts(next, keybindings, copyOnSelect);
247
+ const previous = resolveBtwShortcuts(overrides, keybindings, copyOnSelect);
248
+ // Reject edits that disable another binding as well as the edited binding.
249
+ for (const item of BTW_SHORTCUT_ACTIONS) {
250
+ if (
251
+ (item === action && !resolved.keys[item].includes(normalizeBtwKey(value) ?? "")) ||
252
+ (item !== action && previous.keys[item].some((key) => !resolved.keys[item].includes(key)))
253
+ ) {
254
+ return `${item} conflicts with another BTW shortcut, editing, selection, search, scrolling, or copying. Choose a different key.`;
255
+ }
256
+ }
257
+ return undefined;
300
258
  }
301
259
 
302
260
  const bindingsByTui = new WeakMap<TUI, BtwShortcuts>();
303
261
  export function setBtwShortcuts(tui: TUI, shortcuts: BtwShortcuts): void {
304
- bindingsByTui.set(tui, shortcuts);
262
+ bindingsByTui.set(tui, shortcuts);
305
263
  }
306
264
  export function getBtwShortcuts(tui: TUI, keybindings?: KeybindingsManager): BtwShortcuts {
307
- return (
308
- bindingsByTui.get(tui) ??
309
- resolveBtwShortcuts(
310
- {},
311
- keybindings ??
312
- new KeybindingsManager({
313
- ...TUI_KEYBINDINGS,
314
- "app.thinking.cycle": { defaultKeys: "shift+tab" },
315
- }),
316
- )
317
- );
265
+ return (
266
+ bindingsByTui.get(tui) ??
267
+ resolveBtwShortcuts(
268
+ {},
269
+ keybindings ??
270
+ new KeybindingsManager({
271
+ ...TUI_KEYBINDINGS,
272
+ "app.thinking.cycle": { defaultKeys: "shift+tab" },
273
+ }),
274
+ )
275
+ );
318
276
  }
319
277
 
320
278
  /** Keep split bracketed-paste payloads away from screen-level shortcuts. */
321
279
  export class BtwPasteGuard {
322
- private active = false;
323
- consume(data: string): boolean {
324
- const wasActive = this.active;
325
- const starts = data.includes("\u001b[200~");
326
- if (starts) this.active = true;
327
- if (this.active && data.includes("\u001b[201~")) this.active = false;
328
- return wasActive || starts;
329
- }
280
+ private active = false;
281
+ consume(data: string): boolean {
282
+ const wasActive = this.active;
283
+ const starts = data.includes("\u001b[200~");
284
+ if (starts) this.active = true;
285
+ if (this.active && data.includes("\u001b[201~")) this.active = false;
286
+ return wasActive || starts;
287
+ }
330
288
  }