@floydous/pi-agent-kernel 0.2.0 → 0.3.1

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.
@@ -4,6 +4,7 @@ import { Text, makeOutputText } from "../ui/tui_utils";
4
4
  import * as path from "node:path";
5
5
  import * as fs from "node:fs";
6
6
  import { extractSymbolContent } from "../retrieval/symbol_reader";
7
+ import { findSymbolSuggestions } from "../retrieval/ast_search";
7
8
  import {
8
9
  globalEpistemicGuard,
9
10
  resolveUserPath,
@@ -21,35 +22,31 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
21
22
  name: "read",
22
23
  label: "Read File / Symbol",
23
24
  description:
24
- "Read file contents (text/images) or surgically extract specific AST code symbols (function, class, method, interface, type). Supports optional pagination ('offset', 'limit') or direct surgical extraction via 'symbol'.",
25
- promptSnippet:
26
- "Read file contents or surgically extract specific AST code symbols via 'symbol'",
25
+ "Read file contents or surgically extract an AST symbol (function, class, method, type). Supports line paging ('offset', 'limit') or symbol extraction ('symbol').",
26
+ promptSnippet: "Read file lines or extract an AST symbol via 'symbol'",
27
27
  renderShell: "default",
28
28
  parameters: Type.Object({
29
29
  path: Type.String({
30
- description: "Path to the file to read (relative or absolute)",
30
+ description: "File path (relative or absolute)",
31
31
  }),
32
32
  symbol: Type.Optional(
33
33
  Type.String({
34
- description:
35
- "Optional name of the function, class, method, or type to extract surgically from the file without paging",
34
+ description: "Symbol name to extract surgically without paging",
36
35
  }),
37
36
  ),
38
37
  offset: Type.Optional(
39
38
  Type.Number({
40
- description:
41
- "Line number to start reading from (1-indexed, for full file reading)",
39
+ description: "Start line number (1-indexed)",
42
40
  }),
43
41
  ),
44
42
  limit: Type.Optional(
45
43
  Type.Number({
46
- description: "Maximum number of lines to read (for full file reading)",
44
+ description: "Maximum lines to read",
47
45
  }),
48
46
  ),
49
47
  surrounding_lines: Type.Optional(
50
48
  Type.Number({
51
- description:
52
- "Optional extra lines of surrounding context when extracting a symbol (default: 0)",
49
+ description: "Extra surrounding context lines for symbol (default: 0)",
53
50
  }),
54
51
  ),
55
52
  }),
@@ -107,15 +104,37 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
107
104
  );
108
105
 
109
106
  if (!res.found) {
107
+ const suggestions = findSymbolSuggestions(
108
+ ctx.cwd,
109
+ resolvedPath,
110
+ sym,
111
+ );
112
+ let errorText: string;
113
+ if (res.error) {
114
+ errorText = res.error;
115
+ } else if (suggestions.length > 0) {
116
+ const formattedSuggestions = suggestions
117
+ .map(
118
+ (s) =>
119
+ `- ${s.name} (${s.filePath}:${s.line}) [${s.kind}] ${s.signature}`,
120
+ )
121
+ .join("\n");
122
+ errorText = `Symbol '${sym}' not found in ${params.path}.\nDid you mean:\n${formattedSuggestions}`;
123
+ } else {
124
+ errorText = `Symbol '${sym}' not found in ${params.path}. Use 'ast_search' to locate symbols or 'rg' in bash to search text.`;
125
+ }
110
126
  return {
111
- content: [
112
- {
113
- type: "text",
114
- text:
115
- res.error ||
116
- `Symbol '${sym}' not found in ${params.path}. Use 'ast_search' to locate symbols or 'rg' in bash to search text.`,
117
- },
118
- ],
127
+ content: [{ type: "text", text: errorText }],
128
+ details: {
129
+ error: "symbol_not_found",
130
+ query: sym,
131
+ candidates: suggestions.map((s) => ({
132
+ name: s.name,
133
+ filePath: s.filePath,
134
+ line: s.line,
135
+ kind: s.kind,
136
+ })),
137
+ },
119
138
  isError: true,
120
139
  };
121
140
  }
@@ -10,8 +10,7 @@ export function registerRepoMapTool(pi: ExtensionAPI): void {
10
10
  pi.registerTool({
11
11
  name: "get_repo_map",
12
12
  label: "Get Repository Map",
13
- description:
14
- "Get a concise, PageRank-ranked AST map of classes, functions, and symbols across the entire repository (~1k tokens).",
13
+ description: "Get PageRank-ranked AST map of symbols across repository.",
15
14
  promptSnippet: "Inspect repository AST symbol graph and signatures",
16
15
  renderShell: "default",
17
16
  parameters: Type.Object({
@@ -1,278 +1,278 @@
1
- /**
2
- * Zero-Dependency TUI Helper Utilities
3
- * Works across standalone test suites and live Pi TUI environments.
4
- */
5
-
6
- export interface Focusable {
7
- focused: boolean;
8
- handleInput?(data: string): Promise<void> | void;
9
- render(width: number): string[];
10
- invalidate?(): void;
11
- dispose?(): void;
12
- }
13
-
14
- export const ANSI_REGEX =
15
- /(?:\x1B\][^\x07\x1B]*(?:\x07|\x1B\\|\x9C))|(?:\x1B\[[0-9;?]*[ -/]*[@-~])/g;
16
-
17
- export function stripAnsi(text: string): string {
18
- if (!text) return "";
19
- if (!text.includes("\x1b")) return text;
20
- return text.replace(ANSI_REGEX, "");
21
- }
22
-
23
- export function visibleWidth(text: string): number {
24
- if (!text) return 0;
25
- if (!text.includes("\x1b")) return text.length;
26
- return stripAnsi(text).length;
27
- }
28
-
29
- export function truncateToWidth(
30
- text: string,
31
- maxWidth: number,
32
- ellipsis = "...",
33
- ): string {
34
- maxWidth = Math.max(0, Math.floor(maxWidth));
35
- const vis = visibleWidth(text);
36
- if (vis <= maxWidth) return text;
37
- const ellVis = visibleWidth(ellipsis);
38
- if (maxWidth <= ellVis) return ellipsis.slice(0, maxWidth);
39
-
40
- const raw = stripAnsi(text);
41
- return raw.slice(0, maxWidth - ellVis) + ellipsis;
42
- }
43
-
44
- export function wrapTextWithAnsi(text: string, width: number): string[] {
45
- width = Math.max(1, Math.floor(width));
46
- if (!text) return [""];
47
- const inputLines = text.split(/\r\n|\r|\n/);
48
- const result: string[] = [];
49
-
50
- for (const inputLine of inputLines) {
51
- if (visibleWidth(inputLine) <= width) {
52
- result.push(inputLine);
53
- continue;
54
- }
55
-
56
- if (!inputLine.includes("\x1b")) {
57
- for (let i = 0; i < inputLine.length; i += width) {
58
- result.push(inputLine.slice(i, i + width));
59
- }
60
- continue;
61
- }
62
-
63
- // Tokenize into words and ansi escapes
64
- const tokens: string[] = [];
65
- let currentToken = "";
66
- let inWhitespace = false;
67
- let i = 0;
68
-
69
- while (i < inputLine.length) {
70
- ANSI_REGEX.lastIndex = i;
71
- const match = ANSI_REGEX.exec(inputLine);
72
- if (match && match.index === i) {
73
- currentToken += match[0];
74
- i += match[0].length;
75
- continue;
76
- }
77
-
78
- const char = inputLine[i];
79
- const isWs = /\s/.test(char);
80
- if (
81
- currentToken.length > 0 &&
82
- isWs !== inWhitespace &&
83
- !currentToken.endsWith("\x1b")
84
- ) {
85
- tokens.push(currentToken);
86
- currentToken = "";
87
- }
88
- inWhitespace = isWs;
89
- currentToken += char;
90
- i++;
91
- }
92
- if (currentToken.length > 0) tokens.push(currentToken);
93
-
94
- let curLine = "";
95
- let curWidth = 0;
96
-
97
- for (const token of tokens) {
98
- const tokenWidth = visibleWidth(token);
99
- if (tokenWidth === 0) {
100
- curLine += token;
101
- continue;
102
- }
103
-
104
- if (curWidth + tokenWidth <= width) {
105
- curLine += token;
106
- curWidth += tokenWidth;
107
- } else {
108
- if (tokenWidth > width) {
109
- // Break excessively long token character by character
110
- let j = 0;
111
- while (j < token.length) {
112
- ANSI_REGEX.lastIndex = j;
113
- const m = ANSI_REGEX.exec(token);
114
- if (m && m.index === j) {
115
- curLine += m[0];
116
- j += m[0].length;
117
- continue;
118
- }
119
- const ch = token[j];
120
- if (curWidth + 1 > width) {
121
- if (curLine) result.push(curLine);
122
- curLine = ch;
123
- curWidth = 1;
124
- } else {
125
- curLine += ch;
126
- curWidth += 1;
127
- }
128
- j++;
129
- }
130
- } else {
131
- if (curLine) result.push(curLine);
132
- curLine = token;
133
- curWidth = tokenWidth;
134
- }
135
- }
136
- }
137
- if (curLine) result.push(curLine);
138
- }
139
-
140
- return result.length > 0 ? result : [""];
141
- }
142
-
143
- /**
144
- * Get a safe per-line width for tool output rendering.
145
- *
146
- * The pi runtime does not pass the terminal width to a tool's `renderResult`.
147
- * We read `process.stdout.columns` (the Node TTY width, shared with pi's
148
- * `terminal.columns` in the same process) and subtract a safety margin for
149
- * the parent Box's `paddingX=1` on each side plus a small additional buffer.
150
- *
151
- * If `process.stdout.columns` is undefined (non-TTY: pipes, redirects,
152
- * `--print` mode, RPC mode without a TTY), fall back to 200 columns, which
153
- * is narrower than typical interactive terminals but always fits the parent
154
- * Box's wrap.
155
- *
156
- * The safety margin is conservative (4 columns) so a downstream renderer
157
- * that adds an additional paddingX layer or a border will not overflow.
158
- */
159
- export function getSafeLineWidth(): number {
160
- const cols = process.stdout.columns;
161
- const base = typeof cols === "number" && cols > 0 ? cols : 200;
162
- return Math.max(40, base - 4);
163
- }
164
-
165
- /**
166
- * Build a `Text` component suitable for use in a tool's `renderCall` or
167
- * `renderResult` that is guaranteed not to render a line wider than the
168
- * terminal, regardless of the parent's `paddingX`.
169
- *
170
- * Why a fresh `Text` instead of reusing `context.lastComponent`:
171
- * The previous implementation did `context.lastComponent ?? new Text("", 0, 0)`
172
- * and called `setText` on it. The returned component then became a child of
173
- * pi's `contentBox` (a `Box` with `paddingX=1`). When the runtime passed
174
- * back a `lastComponent` that already had `paddingX=1` (pi's `contentText`
175
- * default), the child Text's own `render(width)` reserved `paddingX*2` of
176
- * width on top of the parent's, producing a line that exceeded the available
177
- * width by a few cells. The pi TUI's hard width assertion then crashed the
178
- * process with "Rendered line N exceeds terminal width".
179
- *
180
- * Always creating a fresh `Text` with `paddingX=0` makes the parent's
181
- * `paddingX` the only source of padding, eliminating the double-padding
182
- * path. The per-line truncation in `setText` is a defense-in-depth measure:
183
- * even if a future renderer adds another padding layer, the lines stored
184
- * in the Text are already within bounds.
185
- */
186
- export function makeOutputText(content: string, paddingX = 0): Text {
187
- const safeWidth = getSafeLineWidth();
188
- // Match Pi's native Text renderer: tabs occupy three spaces there.
189
- const normalizedContent = content.replace(/\t/g, " ");
190
- const safeContent = normalizedContent
191
- .split(/\r\n|\r|\n/)
192
- .map((line) => truncateToWidth(line, safeWidth, "…"))
193
- .join("\n");
194
- return new Text(safeContent, paddingX, 0);
195
- }
196
-
197
- export class Text {
198
- private text: string;
199
- public paddingX: number;
200
- public paddingY: number;
201
-
202
- constructor(text = "", paddingX = 0, paddingY = 0) {
203
- this.text = text;
204
- this.paddingX = paddingX;
205
- this.paddingY = paddingY;
206
- }
207
-
208
- setText(text: string) {
209
- this.text = text;
210
- }
211
-
212
- getText(): string {
213
- return this.text;
214
- }
215
-
216
- /** Satisfies the pi-tui `Component` contract (no cached state to invalidate). */
217
- invalidate(): void {}
218
-
219
- render(width: number): string[] {
220
- width = Math.max(1, Math.floor(width));
221
- if (!this.text || this.text.trim() === "") return [];
222
- const paddingX = Math.min(
223
- this.paddingX,
224
- Math.max(0, Math.floor((width - 1) / 2)),
225
- );
226
- const normalizedText = this.text.replace(/\t/g, " ");
227
- const contentWidth = Math.max(1, width - paddingX * 2);
228
- const wrappedLines = wrapTextWithAnsi(normalizedText, contentWidth);
229
- const leftMargin = " ".repeat(paddingX);
230
- const rightMargin = " ".repeat(paddingX);
231
- const contentLines = wrappedLines.map(
232
- (line) => leftMargin + line + rightMargin,
233
- );
234
- // The width argument is authoritative: Pi hard-fails if any returned
235
- // line exceeds it, regardless of the width available during formatting.
236
- const safeContentLines = contentLines.map((line) =>
237
- truncateToWidth(line, width, ""),
238
- );
239
- const emptyLine = " ".repeat(width);
240
- const emptyLines: string[] = [];
241
- for (let i = 0; i < this.paddingY; i++) {
242
- emptyLines.push(emptyLine);
243
- }
244
- return [...emptyLines, ...safeContentLines, ...emptyLines];
245
- }
246
- }
247
-
248
- export function matchesKey(data: string, key: string): boolean {
249
- switch (key.toLowerCase()) {
250
- case "escape":
251
- return data === "\x1b" || data === "\x1b\x1b";
252
- case "q":
253
- return data === "q" || data === "Q";
254
- case "ctrl+c":
255
- return data === "\x03";
256
- case "up":
257
- return data === "\x1b[A" || data === "\x1bOA";
258
- case "down":
259
- return data === "\x1b[B" || data === "\x1bOB";
260
- case "left":
261
- return data === "\x1b[D" || data === "\x1bOD";
262
- case "right":
263
- return data === "\x1b[C" || data === "\x1bOC";
264
- case "k":
265
- return data === "k" || data === "K";
266
- case "j":
267
- return data === "j" || data === "J";
268
- case "return":
269
- case "enter":
270
- return data === "\r" || data === "\n";
271
- case "space":
272
- return data === " ";
273
- case "tab":
274
- return data === "\t";
275
- default:
276
- return data === key;
277
- }
278
- }
1
+ /**
2
+ * Zero-Dependency TUI Helper Utilities
3
+ * Works across standalone test suites and live Pi TUI environments.
4
+ */
5
+
6
+ export interface Focusable {
7
+ focused: boolean;
8
+ handleInput?(data: string): Promise<void> | void;
9
+ render(width: number): string[];
10
+ invalidate?(): void;
11
+ dispose?(): void;
12
+ }
13
+
14
+ export const ANSI_REGEX =
15
+ /(?:\x1B\][^\x07\x1B]*(?:\x07|\x1B\\|\x9C))|(?:\x1B\[[0-9;?]*[ -/]*[@-~])/g;
16
+
17
+ export function stripAnsi(text: string): string {
18
+ if (!text) return "";
19
+ if (!text.includes("\x1b")) return text;
20
+ return text.replace(ANSI_REGEX, "");
21
+ }
22
+
23
+ export function visibleWidth(text: string): number {
24
+ if (!text) return 0;
25
+ if (!text.includes("\x1b")) return text.length;
26
+ return stripAnsi(text).length;
27
+ }
28
+
29
+ export function truncateToWidth(
30
+ text: string,
31
+ maxWidth: number,
32
+ ellipsis = "...",
33
+ ): string {
34
+ maxWidth = Math.max(0, Math.floor(maxWidth));
35
+ const vis = visibleWidth(text);
36
+ if (vis <= maxWidth) return text;
37
+ const ellVis = visibleWidth(ellipsis);
38
+ if (maxWidth <= ellVis) return ellipsis.slice(0, maxWidth);
39
+
40
+ const raw = stripAnsi(text);
41
+ return raw.slice(0, maxWidth - ellVis) + ellipsis;
42
+ }
43
+
44
+ export function wrapTextWithAnsi(text: string, width: number): string[] {
45
+ width = Math.max(1, Math.floor(width));
46
+ if (!text) return [""];
47
+ const inputLines = text.split(/\r\n|\r|\n/);
48
+ const result: string[] = [];
49
+
50
+ for (const inputLine of inputLines) {
51
+ if (visibleWidth(inputLine) <= width) {
52
+ result.push(inputLine);
53
+ continue;
54
+ }
55
+
56
+ if (!inputLine.includes("\x1b")) {
57
+ for (let i = 0; i < inputLine.length; i += width) {
58
+ result.push(inputLine.slice(i, i + width));
59
+ }
60
+ continue;
61
+ }
62
+
63
+ // Tokenize into words and ansi escapes
64
+ const tokens: string[] = [];
65
+ let currentToken = "";
66
+ let inWhitespace = false;
67
+ let i = 0;
68
+
69
+ while (i < inputLine.length) {
70
+ ANSI_REGEX.lastIndex = i;
71
+ const match = ANSI_REGEX.exec(inputLine);
72
+ if (match && match.index === i) {
73
+ currentToken += match[0];
74
+ i += match[0].length;
75
+ continue;
76
+ }
77
+
78
+ const char = inputLine[i];
79
+ const isWs = /\s/.test(char);
80
+ if (
81
+ currentToken.length > 0 &&
82
+ isWs !== inWhitespace &&
83
+ !currentToken.endsWith("\x1b")
84
+ ) {
85
+ tokens.push(currentToken);
86
+ currentToken = "";
87
+ }
88
+ inWhitespace = isWs;
89
+ currentToken += char;
90
+ i++;
91
+ }
92
+ if (currentToken.length > 0) tokens.push(currentToken);
93
+
94
+ let curLine = "";
95
+ let curWidth = 0;
96
+
97
+ for (const token of tokens) {
98
+ const tokenWidth = visibleWidth(token);
99
+ if (tokenWidth === 0) {
100
+ curLine += token;
101
+ continue;
102
+ }
103
+
104
+ if (curWidth + tokenWidth <= width) {
105
+ curLine += token;
106
+ curWidth += tokenWidth;
107
+ } else {
108
+ if (tokenWidth > width) {
109
+ // Break excessively long token character by character
110
+ let j = 0;
111
+ while (j < token.length) {
112
+ ANSI_REGEX.lastIndex = j;
113
+ const m = ANSI_REGEX.exec(token);
114
+ if (m && m.index === j) {
115
+ curLine += m[0];
116
+ j += m[0].length;
117
+ continue;
118
+ }
119
+ const ch = token[j];
120
+ if (curWidth + 1 > width) {
121
+ if (curLine) result.push(curLine);
122
+ curLine = ch;
123
+ curWidth = 1;
124
+ } else {
125
+ curLine += ch;
126
+ curWidth += 1;
127
+ }
128
+ j++;
129
+ }
130
+ } else {
131
+ if (curLine) result.push(curLine);
132
+ curLine = token;
133
+ curWidth = tokenWidth;
134
+ }
135
+ }
136
+ }
137
+ if (curLine) result.push(curLine);
138
+ }
139
+
140
+ return result.length > 0 ? result : [""];
141
+ }
142
+
143
+ /**
144
+ * Get a safe per-line width for tool output rendering.
145
+ *
146
+ * The pi runtime does not pass the terminal width to a tool's `renderResult`.
147
+ * We read `process.stdout.columns` (the Node TTY width, shared with pi's
148
+ * `terminal.columns` in the same process) and subtract a safety margin for
149
+ * the parent Box's `paddingX=1` on each side plus a small additional buffer.
150
+ *
151
+ * If `process.stdout.columns` is undefined (non-TTY: pipes, redirects,
152
+ * `--print` mode, RPC mode without a TTY), fall back to 200 columns, which
153
+ * is narrower than typical interactive terminals but always fits the parent
154
+ * Box's wrap.
155
+ *
156
+ * The safety margin is conservative (4 columns) so a downstream renderer
157
+ * that adds an additional paddingX layer or a border will not overflow.
158
+ */
159
+ export function getSafeLineWidth(): number {
160
+ const cols = process.stdout.columns;
161
+ const base = typeof cols === "number" && cols > 0 ? cols : 200;
162
+ return Math.max(40, base - 4);
163
+ }
164
+
165
+ /**
166
+ * Build a `Text` component suitable for use in a tool's `renderCall` or
167
+ * `renderResult` that is guaranteed not to render a line wider than the
168
+ * terminal, regardless of the parent's `paddingX`.
169
+ *
170
+ * Why a fresh `Text` instead of reusing `context.lastComponent`:
171
+ * The previous implementation did `context.lastComponent ?? new Text("", 0, 0)`
172
+ * and called `setText` on it. The returned component then became a child of
173
+ * pi's `contentBox` (a `Box` with `paddingX=1`). When the runtime passed
174
+ * back a `lastComponent` that already had `paddingX=1` (pi's `contentText`
175
+ * default), the child Text's own `render(width)` reserved `paddingX*2` of
176
+ * width on top of the parent's, producing a line that exceeded the available
177
+ * width by a few cells. The pi TUI's hard width assertion then crashed the
178
+ * process with "Rendered line N exceeds terminal width".
179
+ *
180
+ * Always creating a fresh `Text` with `paddingX=0` makes the parent's
181
+ * `paddingX` the only source of padding, eliminating the double-padding
182
+ * path. The per-line truncation in `setText` is a defense-in-depth measure:
183
+ * even if a future renderer adds another padding layer, the lines stored
184
+ * in the Text are already within bounds.
185
+ */
186
+ export function makeOutputText(content: string, paddingX = 0): Text {
187
+ const safeWidth = getSafeLineWidth();
188
+ // Match Pi's native Text renderer: tabs occupy three spaces there.
189
+ const normalizedContent = content.replace(/\t/g, " ");
190
+ const safeContent = normalizedContent
191
+ .split(/\r\n|\r|\n/)
192
+ .map((line) => truncateToWidth(line, safeWidth, "…"))
193
+ .join("\n");
194
+ return new Text(safeContent, paddingX, 0);
195
+ }
196
+
197
+ export class Text {
198
+ private text: string;
199
+ public paddingX: number;
200
+ public paddingY: number;
201
+
202
+ constructor(text = "", paddingX = 0, paddingY = 0) {
203
+ this.text = text;
204
+ this.paddingX = paddingX;
205
+ this.paddingY = paddingY;
206
+ }
207
+
208
+ setText(text: string) {
209
+ this.text = text;
210
+ }
211
+
212
+ getText(): string {
213
+ return this.text;
214
+ }
215
+
216
+ /** Satisfies the pi-tui `Component` contract (no cached state to invalidate). */
217
+ invalidate(): void {}
218
+
219
+ render(width: number): string[] {
220
+ width = Math.max(1, Math.floor(width));
221
+ if (!this.text || this.text.trim() === "") return [];
222
+ const paddingX = Math.min(
223
+ this.paddingX,
224
+ Math.max(0, Math.floor((width - 1) / 2)),
225
+ );
226
+ const normalizedText = this.text.replace(/\t/g, " ");
227
+ const contentWidth = Math.max(1, width - paddingX * 2);
228
+ const wrappedLines = wrapTextWithAnsi(normalizedText, contentWidth);
229
+ const leftMargin = " ".repeat(paddingX);
230
+ const rightMargin = " ".repeat(paddingX);
231
+ const contentLines = wrappedLines.map(
232
+ (line) => leftMargin + line + rightMargin,
233
+ );
234
+ // The width argument is authoritative: Pi hard-fails if any returned
235
+ // line exceeds it, regardless of the width available during formatting.
236
+ const safeContentLines = contentLines.map((line) =>
237
+ truncateToWidth(line, width, ""),
238
+ );
239
+ const emptyLine = " ".repeat(width);
240
+ const emptyLines: string[] = [];
241
+ for (let i = 0; i < this.paddingY; i++) {
242
+ emptyLines.push(emptyLine);
243
+ }
244
+ return [...emptyLines, ...safeContentLines, ...emptyLines];
245
+ }
246
+ }
247
+
248
+ export function matchesKey(data: string, key: string): boolean {
249
+ switch (key.toLowerCase()) {
250
+ case "escape":
251
+ return data === "\x1b" || data === "\x1b\x1b";
252
+ case "q":
253
+ return data === "q" || data === "Q";
254
+ case "ctrl+c":
255
+ return data === "\x03";
256
+ case "up":
257
+ return data === "\x1b[A" || data === "\x1bOA";
258
+ case "down":
259
+ return data === "\x1b[B" || data === "\x1bOB";
260
+ case "left":
261
+ return data === "\x1b[D" || data === "\x1bOD";
262
+ case "right":
263
+ return data === "\x1b[C" || data === "\x1bOC";
264
+ case "k":
265
+ return data === "k" || data === "K";
266
+ case "j":
267
+ return data === "j" || data === "J";
268
+ case "return":
269
+ case "enter":
270
+ return data === "\r" || data === "\n";
271
+ case "space":
272
+ return data === " ";
273
+ case "tab":
274
+ return data === "\t";
275
+ default:
276
+ return data === key;
277
+ }
278
+ }
Binary file
Binary file
Binary file
Binary file