@pencil-agent/nano-pencil 2.0.0-beta.2 → 2.0.0-beta.4
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/dist/build-meta.json +3 -3
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-continuations.d.ts +17 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-continuations.js +60 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-stream-events.d.ts +19 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-stream-events.js +55 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-results.d.ts +10 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-results.js +137 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-summaries.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-summaries.js +64 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.d.ts +26 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.js +913 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-run-result.d.ts +9 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-run-result.js +32 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent.d.ts +215 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent.js +522 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/errors.d.ts +62 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/errors.js +146 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/index.d.ts +14 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/index.js +19 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/proxy.d.ts +91 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/proxy.js +279 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.d.ts +15 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.js +625 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-streaming-tool-executor.d.ts +33 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-streaming-tool-executor.js +189 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-tool-orchestration.d.ts +35 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-tool-orchestration.js +319 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/types.d.ts +417 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/types.js +13 -0
- package/dist/node_modules/@pencil-agent/agent-core/package.json +28 -0
- package/dist/node_modules/@pencil-agent/ai/dist/api-registry.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/ai/dist/api-registry.js +152 -0
- package/dist/node_modules/@pencil-agent/ai/dist/cli.d.ts +2 -0
- package/dist/node_modules/@pencil-agent/ai/dist/cli.js +121 -0
- package/dist/node_modules/@pencil-agent/ai/dist/config-path.d.ts +1 -0
- package/dist/node_modules/@pencil-agent/ai/dist/config-path.js +17 -0
- package/dist/node_modules/@pencil-agent/ai/dist/debug-logger.d.ts +94 -0
- package/dist/node_modules/@pencil-agent/ai/dist/debug-logger.js +218 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env-api-keys.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env-api-keys.js +107 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env.d.ts +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/events.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/events.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/index.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/ai/dist/index.js +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/json.d.ts +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/json.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.generated.d.ts +15159 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.generated.js +14928 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.js +60 -0
- package/dist/node_modules/@pencil-agent/ai/dist/overflow.d.ts +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/overflow.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/amazon-bedrock.d.ts +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/amazon-bedrock.js +606 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.d.ts +38 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.js +737 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/azure-openai-responses.d.ts +21 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/azure-openai-responses.js +193 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/github-copilot-headers.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/github-copilot-headers.js +34 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-gemini-cli.d.ts +79 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-gemini-cli.js +753 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-shared.d.ts +70 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-shared.js +311 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-vertex.d.ts +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-vertex.js +380 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google.d.ts +18 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google.js +360 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-codex-responses.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-codex-responses.js +704 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.d.ts +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.js +870 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses-shared.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses-shared.js +432 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.d.ts +19 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.js +207 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/register-builtins.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/register-builtins.js +86 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/simple-options.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/simple-options.js +40 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/transform-messages.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/transform-messages.js +175 -0
- package/dist/node_modules/@pencil-agent/ai/dist/registry.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/registry.js +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/schema.d.ts +10 -0
- package/dist/node_modules/@pencil-agent/ai/dist/schema.js +9 -0
- package/dist/node_modules/@pencil-agent/ai/dist/stream.d.ts +25 -0
- package/dist/node_modules/@pencil-agent/ai/dist/stream.js +324 -0
- package/dist/node_modules/@pencil-agent/ai/dist/types.d.ts +306 -0
- package/dist/node_modules/@pencil-agent/ai/dist/types.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream-types.d.ts +12 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream-types.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream.js +98 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/http-proxy.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/http-proxy.js +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/json-parse.d.ts +14 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/json-parse.js +34 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/anthropic.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/anthropic.js +109 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/decode-credential.d.ts +12 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/decode-credential.js +25 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/github-copilot.d.ts +35 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/github-copilot.js +286 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-antigravity.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-antigravity.js +378 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-gemini-cli.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-gemini-cli.js +483 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/index.d.ts +60 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/index.js +131 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/openai-codex.d.ts +39 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/openai-codex.js +385 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/pkce.d.ts +18 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/pkce.js +36 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/types.d.ts +52 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/types.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/overflow.d.ts +57 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/overflow.js +120 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/sanitize-unicode.d.ts +16 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/sanitize-unicode.js +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/typebox-helpers.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/typebox-helpers.js +26 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/validation.d.ts +23 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/validation.js +78 -0
- package/dist/node_modules/@pencil-agent/ai/package.json +106 -0
- package/dist/node_modules/@pencil-agent/tui/dist/autocomplete.d.ts +62 -0
- package/dist/node_modules/@pencil-agent/tui/dist/autocomplete.js +624 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/box.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/box.js +109 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/cancellable-loader.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/cancellable-loader.js +40 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/editor.d.ts +218 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/editor.js +1697 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/image.d.ts +33 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/image.js +74 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/input.d.ts +42 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/input.js +438 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/loader.d.ts +26 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/loader.js +54 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/markdown.d.ts +100 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/markdown.js +634 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/select-list.d.ts +37 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/select-list.js +157 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/settings-list.d.ts +55 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/settings-list.js +190 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/spacer.d.ts +17 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/spacer.js +28 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/text.d.ts +24 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/text.js +94 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/truncated-text.d.ts +18 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/truncated-text.js +56 -0
- package/dist/node_modules/@pencil-agent/tui/dist/editor-component.d.ts +51 -0
- package/dist/node_modules/@pencil-agent/tui/dist/editor-component.js +7 -0
- package/dist/node_modules/@pencil-agent/tui/dist/fuzzy.d.ts +32 -0
- package/dist/node_modules/@pencil-agent/tui/dist/fuzzy.js +152 -0
- package/dist/node_modules/@pencil-agent/tui/dist/index.d.ts +28 -0
- package/dist/node_modules/@pencil-agent/tui/dist/index.js +37 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keybindings.d.ts +44 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keybindings.js +119 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keys.d.ts +149 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keys.js +948 -0
- package/dist/node_modules/@pencil-agent/tui/dist/kill-ring.d.ts +33 -0
- package/dist/node_modules/@pencil-agent/tui/dist/kill-ring.js +49 -0
- package/dist/node_modules/@pencil-agent/tui/dist/stdin-buffer.d.ts +38 -0
- package/dist/node_modules/@pencil-agent/tui/dist/stdin-buffer.js +307 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal-image.d.ts +73 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal-image.js +287 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal.d.ts +86 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal.js +266 -0
- package/dist/node_modules/@pencil-agent/tui/dist/tui.d.ts +219 -0
- package/dist/node_modules/@pencil-agent/tui/dist/tui.js +1001 -0
- package/dist/node_modules/@pencil-agent/tui/dist/undo-stack.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/tui/dist/undo-stack.js +30 -0
- package/dist/node_modules/@pencil-agent/tui/dist/utils.d.ts +83 -0
- package/dist/node_modules/@pencil-agent/tui/dist/utils.js +811 -0
- package/dist/node_modules/@pencil-agent/tui/package.json +37 -0
- package/package.json +3 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: EditorComponent
|
|
3
|
+
* [FROM]: No external dependencies
|
|
4
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts
|
|
5
|
+
* [HERE]: core/lib/tui/src/editor-component.ts -
|
|
6
|
+
*/
|
|
7
|
+
import type { AutocompleteProvider } from "./autocomplete.js";
|
|
8
|
+
import type { Component } from "./tui.js";
|
|
9
|
+
/**
|
|
10
|
+
* Interface for custom editor components.
|
|
11
|
+
*
|
|
12
|
+
* This allows extensions to provide their own editor implementation
|
|
13
|
+
* (e.g., vim mode, emacs mode, custom keybindings) while maintaining
|
|
14
|
+
* compatibility with the core application.
|
|
15
|
+
*/
|
|
16
|
+
export interface EditorComponent extends Component {
|
|
17
|
+
/** Get the current text content */
|
|
18
|
+
getText(): string;
|
|
19
|
+
/** Set the text content */
|
|
20
|
+
setText(text: string): void;
|
|
21
|
+
/** Handle raw terminal input (key presses, paste sequences, etc.) */
|
|
22
|
+
handleInput(data: string): void;
|
|
23
|
+
/** Called when user submits (e.g., Enter key) */
|
|
24
|
+
onSubmit?: (text: string) => void;
|
|
25
|
+
/** Called when text changes */
|
|
26
|
+
onChange?: (text: string) => void;
|
|
27
|
+
/** Add text to history for up/down navigation */
|
|
28
|
+
addToHistory?(text: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the cursor is on the first visual line (accounts for soft wrapping).
|
|
31
|
+
* Used to decide whether ↑ should leave the editor (e.g. into an attachments
|
|
32
|
+
* bar above it) instead of moving the cursor. Optional: callers fall back to a
|
|
33
|
+
* single-line check when an editor implementation does not provide it.
|
|
34
|
+
*/
|
|
35
|
+
isCursorOnFirstVisualLine?(): boolean;
|
|
36
|
+
/** Insert text at current cursor position */
|
|
37
|
+
insertTextAtCursor?(text: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get text with any markers expanded (e.g., paste markers).
|
|
40
|
+
* Falls back to getText() if not implemented.
|
|
41
|
+
*/
|
|
42
|
+
getExpandedText?(): string;
|
|
43
|
+
/** Set the autocomplete provider */
|
|
44
|
+
setAutocompleteProvider?(provider: AutocompleteProvider): void;
|
|
45
|
+
/** Border color function */
|
|
46
|
+
borderColor?: (str: string) => string;
|
|
47
|
+
/** Set horizontal padding */
|
|
48
|
+
setPaddingX?(padding: number): void;
|
|
49
|
+
/** Set max visible items in autocomplete dropdown */
|
|
50
|
+
setAutocompleteMaxVisible?(maxVisible: number): void;
|
|
51
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fuzzy matching utilities.
|
|
3
|
+
* Matches if all query characters appear in order (not necessarily consecutive).
|
|
4
|
+
* Lower score = better match.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* [WHO]: FuzzyMatch, fuzzyMatch, fuzzyFilter
|
|
8
|
+
* [FROM]: No external dependencies
|
|
9
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts
|
|
10
|
+
* [HERE]: core/lib/tui/src/fuzzy.ts -
|
|
11
|
+
*/
|
|
12
|
+
export interface FuzzyMatch {
|
|
13
|
+
matches: boolean;
|
|
14
|
+
score: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function fuzzyMatch(query: string, text: string): FuzzyMatch;
|
|
17
|
+
/**
|
|
18
|
+
* Filter and sort items by fuzzy match quality (best matches first).
|
|
19
|
+
* Supports space-separated tokens: all tokens must match.
|
|
20
|
+
*/
|
|
21
|
+
export declare function fuzzyFilter<T>(items: T[], query: string, getText: (item: T) => string): T[];
|
|
22
|
+
/**
|
|
23
|
+
* Weighted fuzzy filter for command autocomplete.
|
|
24
|
+
* Scores items by multiple fields with different weights.
|
|
25
|
+
* Higher score = better match.
|
|
26
|
+
*/
|
|
27
|
+
export interface WeightedField<T> {
|
|
28
|
+
name: string;
|
|
29
|
+
getText: (item: T) => string;
|
|
30
|
+
weight: number;
|
|
31
|
+
}
|
|
32
|
+
export declare function weightedFuzzyFilter<T>(items: T[], query: string, fields: WeightedField<T>[]): T[];
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fuzzy matching utilities.
|
|
3
|
+
* Matches if all query characters appear in order (not necessarily consecutive).
|
|
4
|
+
* Lower score = better match.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* [WHO]: FuzzyMatch, fuzzyMatch, fuzzyFilter
|
|
8
|
+
* [FROM]: No external dependencies
|
|
9
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts
|
|
10
|
+
* [HERE]: core/lib/tui/src/fuzzy.ts -
|
|
11
|
+
*/
|
|
12
|
+
export function fuzzyMatch(query, text) {
|
|
13
|
+
const queryLower = query.toLowerCase();
|
|
14
|
+
const textLower = text.toLowerCase();
|
|
15
|
+
const matchQuery = (normalizedQuery) => {
|
|
16
|
+
if (normalizedQuery.length === 0) {
|
|
17
|
+
return { matches: true, score: 0 };
|
|
18
|
+
}
|
|
19
|
+
if (normalizedQuery.length > textLower.length) {
|
|
20
|
+
return { matches: false, score: 0 };
|
|
21
|
+
}
|
|
22
|
+
let queryIndex = 0;
|
|
23
|
+
let score = 0;
|
|
24
|
+
let lastMatchIndex = -1;
|
|
25
|
+
let consecutiveMatches = 0;
|
|
26
|
+
for (let i = 0; i < textLower.length && queryIndex < normalizedQuery.length; i++) {
|
|
27
|
+
if (textLower[i] === normalizedQuery[queryIndex]) {
|
|
28
|
+
const isWordBoundary = i === 0 || /[\s\-_./:]/.test(textLower[i - 1]);
|
|
29
|
+
// Reward consecutive matches
|
|
30
|
+
if (lastMatchIndex === i - 1) {
|
|
31
|
+
consecutiveMatches++;
|
|
32
|
+
score -= consecutiveMatches * 5;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
consecutiveMatches = 0;
|
|
36
|
+
// Penalize gaps
|
|
37
|
+
if (lastMatchIndex >= 0) {
|
|
38
|
+
score += (i - lastMatchIndex - 1) * 2;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Reward word boundary matches
|
|
42
|
+
if (isWordBoundary) {
|
|
43
|
+
score -= 10;
|
|
44
|
+
}
|
|
45
|
+
// Slight penalty for later matches
|
|
46
|
+
score += i * 0.1;
|
|
47
|
+
lastMatchIndex = i;
|
|
48
|
+
queryIndex++;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (queryIndex < normalizedQuery.length) {
|
|
52
|
+
return { matches: false, score: 0 };
|
|
53
|
+
}
|
|
54
|
+
return { matches: true, score };
|
|
55
|
+
};
|
|
56
|
+
const primaryMatch = matchQuery(queryLower);
|
|
57
|
+
if (primaryMatch.matches) {
|
|
58
|
+
return primaryMatch;
|
|
59
|
+
}
|
|
60
|
+
const alphaNumericMatch = queryLower.match(/^(?<letters>[a-z]+)(?<digits>[0-9]+)$/);
|
|
61
|
+
const numericAlphaMatch = queryLower.match(/^(?<digits>[0-9]+)(?<letters>[a-z]+)$/);
|
|
62
|
+
const swappedQuery = alphaNumericMatch
|
|
63
|
+
? `${alphaNumericMatch.groups?.digits ?? ""}${alphaNumericMatch.groups?.letters ?? ""}`
|
|
64
|
+
: numericAlphaMatch
|
|
65
|
+
? `${numericAlphaMatch.groups?.letters ?? ""}${numericAlphaMatch.groups?.digits ?? ""}`
|
|
66
|
+
: "";
|
|
67
|
+
if (!swappedQuery) {
|
|
68
|
+
return primaryMatch;
|
|
69
|
+
}
|
|
70
|
+
const swappedMatch = matchQuery(swappedQuery);
|
|
71
|
+
if (!swappedMatch.matches) {
|
|
72
|
+
return primaryMatch;
|
|
73
|
+
}
|
|
74
|
+
return { matches: true, score: swappedMatch.score + 5 };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Filter and sort items by fuzzy match quality (best matches first).
|
|
78
|
+
* Supports space-separated tokens: all tokens must match.
|
|
79
|
+
*/
|
|
80
|
+
export function fuzzyFilter(items, query, getText) {
|
|
81
|
+
if (!query.trim()) {
|
|
82
|
+
return items;
|
|
83
|
+
}
|
|
84
|
+
const tokens = query
|
|
85
|
+
.trim()
|
|
86
|
+
.split(/\s+/)
|
|
87
|
+
.filter((t) => t.length > 0);
|
|
88
|
+
if (tokens.length === 0) {
|
|
89
|
+
return items;
|
|
90
|
+
}
|
|
91
|
+
const results = [];
|
|
92
|
+
for (const item of items) {
|
|
93
|
+
const text = getText(item);
|
|
94
|
+
let totalScore = 0;
|
|
95
|
+
let allMatch = true;
|
|
96
|
+
for (const token of tokens) {
|
|
97
|
+
const match = fuzzyMatch(token, text);
|
|
98
|
+
if (match.matches) {
|
|
99
|
+
totalScore += match.score;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
allMatch = false;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (allMatch) {
|
|
107
|
+
results.push({ item, totalScore });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
results.sort((a, b) => a.totalScore - b.totalScore);
|
|
111
|
+
return results.map((r) => r.item);
|
|
112
|
+
}
|
|
113
|
+
export function weightedFuzzyFilter(items, query, fields) {
|
|
114
|
+
if (!query.trim()) {
|
|
115
|
+
return items;
|
|
116
|
+
}
|
|
117
|
+
const tokens = query
|
|
118
|
+
.trim()
|
|
119
|
+
.split(/\s+/)
|
|
120
|
+
.filter((t) => t.length > 0);
|
|
121
|
+
if (tokens.length === 0) {
|
|
122
|
+
return items;
|
|
123
|
+
}
|
|
124
|
+
const results = [];
|
|
125
|
+
for (const item of items) {
|
|
126
|
+
let totalWeightedScore = 0;
|
|
127
|
+
let hasMatch = false;
|
|
128
|
+
for (const field of fields) {
|
|
129
|
+
const text = field.getText(item);
|
|
130
|
+
let fieldScore = 0;
|
|
131
|
+
for (const token of tokens) {
|
|
132
|
+
const match = fuzzyMatch(token, text);
|
|
133
|
+
if (match.matches) {
|
|
134
|
+
fieldScore += match.score;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
fieldScore = Infinity; // Token didn't match this field
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (fieldScore !== Infinity) {
|
|
142
|
+
totalWeightedScore += fieldScore * field.weight;
|
|
143
|
+
hasMatch = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (hasMatch) {
|
|
147
|
+
results.push({ item, totalScore: totalWeightedScore });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
results.sort((a, b) => a.totalScore - b.totalScore);
|
|
151
|
+
return results.map((r) => r.item);
|
|
152
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: TUI barrel exports
|
|
3
|
+
* [FROM]: Depends on all tui components
|
|
4
|
+
* [TO]: Consumed by @pencil-agent/tui package consumers (modes, core/extensions-host, cli)
|
|
5
|
+
* [HERE]: core/lib/tui/src/index.ts - TUI package entry point
|
|
6
|
+
*/
|
|
7
|
+
export { type ArgumentCompletionContext, type AutocompleteItem, type AutocompleteProvider, CombinedAutocompleteProvider, type SlashCommand, } from "./autocomplete.js";
|
|
8
|
+
export { Box } from "./components/box.js";
|
|
9
|
+
export { CancellableLoader } from "./components/cancellable-loader.js";
|
|
10
|
+
export { Editor, type EditorOptions, type EditorTheme } from "./components/editor.js";
|
|
11
|
+
export { Image, type ImageOptions, type ImageTheme } from "./components/image.js";
|
|
12
|
+
export { Input } from "./components/input.js";
|
|
13
|
+
export { Loader } from "./components/loader.js";
|
|
14
|
+
export { type DefaultTextStyle, Markdown, type MarkdownTheme } from "./components/markdown.js";
|
|
15
|
+
export { type SelectItem, SelectList, type SelectListTheme } from "./components/select-list.js";
|
|
16
|
+
export { type SettingItem, SettingsList, type SettingsListTheme } from "./components/settings-list.js";
|
|
17
|
+
export { Spacer } from "./components/spacer.js";
|
|
18
|
+
export { Text } from "./components/text.js";
|
|
19
|
+
export { TruncatedText } from "./components/truncated-text.js";
|
|
20
|
+
export type { EditorComponent } from "./editor-component.js";
|
|
21
|
+
export { type FuzzyMatch, type WeightedField, fuzzyFilter, fuzzyMatch, weightedFuzzyFilter } from "./fuzzy.js";
|
|
22
|
+
export { DEFAULT_EDITOR_KEYBINDINGS, type EditorAction, type EditorKeybindingsConfig, EditorKeybindingsManager, getEditorKeybindings, setEditorKeybindings, } from "./keybindings.js";
|
|
23
|
+
export { isKeyRelease, isKeyRepeat, isKittyProtocolActive, Key, type KeyEventType, type KeyId, matchesKey, parseKey, setKittyProtocolActive, } from "./keys.js";
|
|
24
|
+
export { StdinBuffer, type StdinBufferEventMap, type StdinBufferOptions } from "./stdin-buffer.js";
|
|
25
|
+
export { ProcessTerminal, type Terminal } from "./terminal.js";
|
|
26
|
+
export { allocateImageId, type CellDimensions, calculateImageRows, deleteAllKittyImages, deleteKittyImage, detectCapabilities, encodeITerm2, encodeKitty, getCapabilities, getCellDimensions, getGifDimensions, getImageDimensions, getJpegDimensions, getPngDimensions, getWebpDimensions, type ImageDimensions, type ImageProtocol, type ImageRenderOptions, imageFallback, renderImage, resetCapabilitiesCache, setCellDimensions, type TerminalCapabilities, } from "./terminal-image.js";
|
|
27
|
+
export { type Component, Container, CURSOR_MARKER, type Focusable, isFocusable, type OverlayAnchor, type OverlayHandle, type OverlayMargin, type OverlayOptions, type SizeValue, TUI, } from "./tui.js";
|
|
28
|
+
export { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "./utils.js";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: TUI barrel exports
|
|
3
|
+
* [FROM]: Depends on all tui components
|
|
4
|
+
* [TO]: Consumed by @pencil-agent/tui package consumers (modes, core/extensions-host, cli)
|
|
5
|
+
* [HERE]: core/lib/tui/src/index.ts - TUI package entry point
|
|
6
|
+
*/
|
|
7
|
+
// Core TUI interfaces and classes
|
|
8
|
+
// Autocomplete support
|
|
9
|
+
export { CombinedAutocompleteProvider, } from "./autocomplete.js";
|
|
10
|
+
// Components
|
|
11
|
+
export { Box } from "./components/box.js";
|
|
12
|
+
export { CancellableLoader } from "./components/cancellable-loader.js";
|
|
13
|
+
export { Editor } from "./components/editor.js";
|
|
14
|
+
export { Image } from "./components/image.js";
|
|
15
|
+
export { Input } from "./components/input.js";
|
|
16
|
+
export { Loader } from "./components/loader.js";
|
|
17
|
+
export { Markdown } from "./components/markdown.js";
|
|
18
|
+
export { SelectList } from "./components/select-list.js";
|
|
19
|
+
export { SettingsList } from "./components/settings-list.js";
|
|
20
|
+
export { Spacer } from "./components/spacer.js";
|
|
21
|
+
export { Text } from "./components/text.js";
|
|
22
|
+
export { TruncatedText } from "./components/truncated-text.js";
|
|
23
|
+
// Fuzzy matching
|
|
24
|
+
export { fuzzyFilter, fuzzyMatch, weightedFuzzyFilter } from "./fuzzy.js";
|
|
25
|
+
// Keybindings
|
|
26
|
+
export { DEFAULT_EDITOR_KEYBINDINGS, EditorKeybindingsManager, getEditorKeybindings, setEditorKeybindings, } from "./keybindings.js";
|
|
27
|
+
// Keyboard input handling
|
|
28
|
+
export { isKeyRelease, isKeyRepeat, isKittyProtocolActive, Key, matchesKey, parseKey, setKittyProtocolActive, } from "./keys.js";
|
|
29
|
+
// Input buffering for batch splitting
|
|
30
|
+
export { StdinBuffer } from "./stdin-buffer.js";
|
|
31
|
+
// Terminal interface and implementations
|
|
32
|
+
export { ProcessTerminal } from "./terminal.js";
|
|
33
|
+
// Terminal image support
|
|
34
|
+
export { allocateImageId, calculateImageRows, deleteAllKittyImages, deleteKittyImage, detectCapabilities, encodeITerm2, encodeKitty, getCapabilities, getCellDimensions, getGifDimensions, getImageDimensions, getJpegDimensions, getPngDimensions, getWebpDimensions, imageFallback, renderImage, resetCapabilitiesCache, setCellDimensions, } from "./terminal-image.js";
|
|
35
|
+
export { Container, CURSOR_MARKER, isFocusable, TUI, } from "./tui.js";
|
|
36
|
+
// Utilities
|
|
37
|
+
export { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "./utils.js";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: DEFAULT_EDITOR_KEYBINDINGS, EditorKeybindingsManager, getEditorKeybindings, setEditorKeybindings
|
|
3
|
+
* [FROM]: Depends on ./keys.js
|
|
4
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts
|
|
5
|
+
* [HERE]: core/lib/tui/src/keybindings.ts -
|
|
6
|
+
*/
|
|
7
|
+
import { type KeyId } from "./keys.js";
|
|
8
|
+
/**
|
|
9
|
+
* Editor actions that can be bound to keys.
|
|
10
|
+
*/
|
|
11
|
+
export type EditorAction = "cursorUp" | "cursorDown" | "cursorLeft" | "cursorRight" | "cursorWordLeft" | "cursorWordRight" | "cursorLineStart" | "cursorLineEnd" | "jumpForward" | "jumpBackward" | "pageUp" | "pageDown" | "deleteCharBackward" | "deleteCharForward" | "deleteWordBackward" | "deleteWordForward" | "deleteToLineStart" | "deleteToLineEnd" | "newLine" | "submit" | "tab" | "selectUp" | "selectDown" | "selectPageUp" | "selectPageDown" | "selectConfirm" | "selectCancel" | "copy" | "yank" | "yankPop" | "undo" | "expandTools" | "toggleSessionPath" | "toggleSessionSort" | "renameSession" | "deleteSession" | "deleteSessionNoninvasive";
|
|
12
|
+
export type { KeyId };
|
|
13
|
+
/**
|
|
14
|
+
* Editor keybindings configuration.
|
|
15
|
+
*/
|
|
16
|
+
export type EditorKeybindingsConfig = {
|
|
17
|
+
[K in EditorAction]?: KeyId | KeyId[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Default editor keybindings.
|
|
21
|
+
*/
|
|
22
|
+
export declare const DEFAULT_EDITOR_KEYBINDINGS: Required<EditorKeybindingsConfig>;
|
|
23
|
+
/**
|
|
24
|
+
* Manages keybindings for the editor.
|
|
25
|
+
*/
|
|
26
|
+
export declare class EditorKeybindingsManager {
|
|
27
|
+
private actionToKeys;
|
|
28
|
+
constructor(config?: EditorKeybindingsConfig);
|
|
29
|
+
private buildMaps;
|
|
30
|
+
/**
|
|
31
|
+
* Check if input matches a specific action.
|
|
32
|
+
*/
|
|
33
|
+
matches(data: string, action: EditorAction): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Get keys bound to an action.
|
|
36
|
+
*/
|
|
37
|
+
getKeys(action: EditorAction): KeyId[];
|
|
38
|
+
/**
|
|
39
|
+
* Update configuration.
|
|
40
|
+
*/
|
|
41
|
+
setConfig(config: EditorKeybindingsConfig): void;
|
|
42
|
+
}
|
|
43
|
+
export declare function getEditorKeybindings(): EditorKeybindingsManager;
|
|
44
|
+
export declare function setEditorKeybindings(manager: EditorKeybindingsManager): void;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: DEFAULT_EDITOR_KEYBINDINGS, EditorKeybindingsManager, getEditorKeybindings, setEditorKeybindings
|
|
3
|
+
* [FROM]: Depends on ./keys.js
|
|
4
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts
|
|
5
|
+
* [HERE]: core/lib/tui/src/keybindings.ts -
|
|
6
|
+
*/
|
|
7
|
+
import { matchesKey } from "./keys.js";
|
|
8
|
+
/**
|
|
9
|
+
* Default editor keybindings.
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_EDITOR_KEYBINDINGS = {
|
|
12
|
+
// Cursor movement
|
|
13
|
+
cursorUp: "up",
|
|
14
|
+
cursorDown: "down",
|
|
15
|
+
cursorLeft: ["left", "ctrl+b"],
|
|
16
|
+
cursorRight: ["right", "ctrl+f"],
|
|
17
|
+
cursorWordLeft: ["alt+left", "ctrl+left", "alt+b"],
|
|
18
|
+
cursorWordRight: ["alt+right", "ctrl+right", "alt+f"],
|
|
19
|
+
cursorLineStart: ["home", "ctrl+a"],
|
|
20
|
+
cursorLineEnd: ["end", "ctrl+e"],
|
|
21
|
+
jumpForward: "ctrl+]",
|
|
22
|
+
jumpBackward: "ctrl+alt+]",
|
|
23
|
+
pageUp: "pageUp",
|
|
24
|
+
pageDown: "pageDown",
|
|
25
|
+
// Deletion
|
|
26
|
+
deleteCharBackward: "backspace",
|
|
27
|
+
deleteCharForward: ["delete", "ctrl+d"],
|
|
28
|
+
deleteWordBackward: ["ctrl+w", "alt+backspace"],
|
|
29
|
+
deleteWordForward: ["alt+d", "alt+delete"],
|
|
30
|
+
deleteToLineStart: "ctrl+u",
|
|
31
|
+
deleteToLineEnd: "ctrl+k",
|
|
32
|
+
// Text input
|
|
33
|
+
newLine: "shift+enter",
|
|
34
|
+
submit: "enter",
|
|
35
|
+
tab: "tab",
|
|
36
|
+
// Selection/autocomplete
|
|
37
|
+
selectUp: "up",
|
|
38
|
+
selectDown: "down",
|
|
39
|
+
selectPageUp: "pageUp",
|
|
40
|
+
selectPageDown: "pageDown",
|
|
41
|
+
selectConfirm: "enter",
|
|
42
|
+
selectCancel: ["escape", "ctrl+c"],
|
|
43
|
+
// Clipboard
|
|
44
|
+
copy: "ctrl+c",
|
|
45
|
+
// Kill ring
|
|
46
|
+
yank: "ctrl+y",
|
|
47
|
+
yankPop: "alt+y",
|
|
48
|
+
// Undo
|
|
49
|
+
undo: "ctrl+-",
|
|
50
|
+
// Tool output
|
|
51
|
+
expandTools: "ctrl+o",
|
|
52
|
+
// Session
|
|
53
|
+
toggleSessionPath: "ctrl+p",
|
|
54
|
+
toggleSessionSort: "ctrl+s",
|
|
55
|
+
renameSession: "ctrl+r",
|
|
56
|
+
deleteSession: "ctrl+d",
|
|
57
|
+
deleteSessionNoninvasive: "ctrl+backspace",
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Manages keybindings for the editor.
|
|
61
|
+
*/
|
|
62
|
+
export class EditorKeybindingsManager {
|
|
63
|
+
actionToKeys;
|
|
64
|
+
constructor(config = {}) {
|
|
65
|
+
this.actionToKeys = new Map();
|
|
66
|
+
this.buildMaps(config);
|
|
67
|
+
}
|
|
68
|
+
buildMaps(config) {
|
|
69
|
+
this.actionToKeys.clear();
|
|
70
|
+
// Start with defaults
|
|
71
|
+
for (const [action, keys] of Object.entries(DEFAULT_EDITOR_KEYBINDINGS)) {
|
|
72
|
+
const keyArray = Array.isArray(keys) ? keys : [keys];
|
|
73
|
+
this.actionToKeys.set(action, [...keyArray]);
|
|
74
|
+
}
|
|
75
|
+
// Override with user config
|
|
76
|
+
for (const [action, keys] of Object.entries(config)) {
|
|
77
|
+
if (keys === undefined)
|
|
78
|
+
continue;
|
|
79
|
+
const keyArray = Array.isArray(keys) ? keys : [keys];
|
|
80
|
+
this.actionToKeys.set(action, keyArray);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check if input matches a specific action.
|
|
85
|
+
*/
|
|
86
|
+
matches(data, action) {
|
|
87
|
+
const keys = this.actionToKeys.get(action);
|
|
88
|
+
if (!keys)
|
|
89
|
+
return false;
|
|
90
|
+
for (const key of keys) {
|
|
91
|
+
if (matchesKey(data, key))
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get keys bound to an action.
|
|
98
|
+
*/
|
|
99
|
+
getKeys(action) {
|
|
100
|
+
return this.actionToKeys.get(action) ?? [];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Update configuration.
|
|
104
|
+
*/
|
|
105
|
+
setConfig(config) {
|
|
106
|
+
this.buildMaps(config);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Global instance
|
|
110
|
+
let globalEditorKeybindings = null;
|
|
111
|
+
export function getEditorKeybindings() {
|
|
112
|
+
if (!globalEditorKeybindings) {
|
|
113
|
+
globalEditorKeybindings = new EditorKeybindingsManager();
|
|
114
|
+
}
|
|
115
|
+
return globalEditorKeybindings;
|
|
116
|
+
}
|
|
117
|
+
export function setEditorKeybindings(manager) {
|
|
118
|
+
globalEditorKeybindings = manager;
|
|
119
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: Keyboard input handling - setKittyProtocolActive, isKittyProtocolActive, Key, matchesKey, parseKey
|
|
3
|
+
* [FROM]: No external dependencies
|
|
4
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts, TUI components
|
|
5
|
+
* [HERE]: core/lib/tui/src/keys.ts - keyboard input handling for terminal applications
|
|
6
|
+
*
|
|
7
|
+
* Supports both legacy terminal sequences and Kitty keyboard protocol.
|
|
8
|
+
* See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Set the global Kitty keyboard protocol state.
|
|
12
|
+
* Called by ProcessTerminal after detecting protocol support.
|
|
13
|
+
*/
|
|
14
|
+
export declare function setKittyProtocolActive(active: boolean): void;
|
|
15
|
+
/**
|
|
16
|
+
* Query whether Kitty keyboard protocol is currently active.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isKittyProtocolActive(): boolean;
|
|
19
|
+
type Letter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
|
|
20
|
+
type SymbolKey = "`" | "-" | "=" | "[" | "]" | "\\" | ";" | "'" | "," | "." | "/" | "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "_" | "+" | "|" | "~" | "{" | "}" | ":" | "<" | ">" | "?";
|
|
21
|
+
type SpecialKey = "escape" | "esc" | "enter" | "return" | "tab" | "space" | "backspace" | "delete" | "insert" | "clear" | "home" | "end" | "pageUp" | "pageDown" | "up" | "down" | "left" | "right" | "f1" | "f2" | "f3" | "f4" | "f5" | "f6" | "f7" | "f8" | "f9" | "f10" | "f11" | "f12";
|
|
22
|
+
type BaseKey = Letter | SymbolKey | SpecialKey;
|
|
23
|
+
/**
|
|
24
|
+
* Union type of all valid key identifiers.
|
|
25
|
+
* Provides autocomplete and catches typos at compile time.
|
|
26
|
+
*/
|
|
27
|
+
export type KeyId = BaseKey | `ctrl+${BaseKey}` | `shift+${BaseKey}` | `alt+${BaseKey}` | `ctrl+shift+${BaseKey}` | `shift+ctrl+${BaseKey}` | `ctrl+alt+${BaseKey}` | `alt+ctrl+${BaseKey}` | `shift+alt+${BaseKey}` | `alt+shift+${BaseKey}` | `ctrl+shift+alt+${BaseKey}` | `ctrl+alt+shift+${BaseKey}` | `shift+ctrl+alt+${BaseKey}` | `shift+alt+ctrl+${BaseKey}` | `alt+ctrl+shift+${BaseKey}` | `alt+shift+ctrl+${BaseKey}`;
|
|
28
|
+
/**
|
|
29
|
+
* Helper object for creating typed key identifiers with autocomplete.
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* - Key.escape, Key.enter, Key.tab, etc. for special keys
|
|
33
|
+
* - Key.backtick, Key.comma, Key.period, etc. for symbol keys
|
|
34
|
+
* - Key.ctrl("c"), Key.alt("x") for single modifier
|
|
35
|
+
* - Key.ctrlShift("p"), Key.ctrlAlt("x") for combined modifiers
|
|
36
|
+
*/
|
|
37
|
+
export declare const Key: {
|
|
38
|
+
readonly escape: "escape";
|
|
39
|
+
readonly esc: "esc";
|
|
40
|
+
readonly enter: "enter";
|
|
41
|
+
readonly return: "return";
|
|
42
|
+
readonly tab: "tab";
|
|
43
|
+
readonly space: "space";
|
|
44
|
+
readonly backspace: "backspace";
|
|
45
|
+
readonly delete: "delete";
|
|
46
|
+
readonly insert: "insert";
|
|
47
|
+
readonly clear: "clear";
|
|
48
|
+
readonly home: "home";
|
|
49
|
+
readonly end: "end";
|
|
50
|
+
readonly pageUp: "pageUp";
|
|
51
|
+
readonly pageDown: "pageDown";
|
|
52
|
+
readonly up: "up";
|
|
53
|
+
readonly down: "down";
|
|
54
|
+
readonly left: "left";
|
|
55
|
+
readonly right: "right";
|
|
56
|
+
readonly f1: "f1";
|
|
57
|
+
readonly f2: "f2";
|
|
58
|
+
readonly f3: "f3";
|
|
59
|
+
readonly f4: "f4";
|
|
60
|
+
readonly f5: "f5";
|
|
61
|
+
readonly f6: "f6";
|
|
62
|
+
readonly f7: "f7";
|
|
63
|
+
readonly f8: "f8";
|
|
64
|
+
readonly f9: "f9";
|
|
65
|
+
readonly f10: "f10";
|
|
66
|
+
readonly f11: "f11";
|
|
67
|
+
readonly f12: "f12";
|
|
68
|
+
readonly backtick: "`";
|
|
69
|
+
readonly hyphen: "-";
|
|
70
|
+
readonly equals: "=";
|
|
71
|
+
readonly leftbracket: "[";
|
|
72
|
+
readonly rightbracket: "]";
|
|
73
|
+
readonly backslash: "\\";
|
|
74
|
+
readonly semicolon: ";";
|
|
75
|
+
readonly quote: "'";
|
|
76
|
+
readonly comma: ",";
|
|
77
|
+
readonly period: ".";
|
|
78
|
+
readonly slash: "/";
|
|
79
|
+
readonly exclamation: "!";
|
|
80
|
+
readonly at: "@";
|
|
81
|
+
readonly hash: "#";
|
|
82
|
+
readonly dollar: "$";
|
|
83
|
+
readonly percent: "%";
|
|
84
|
+
readonly caret: "^";
|
|
85
|
+
readonly ampersand: "&";
|
|
86
|
+
readonly asterisk: "*";
|
|
87
|
+
readonly leftparen: "(";
|
|
88
|
+
readonly rightparen: ")";
|
|
89
|
+
readonly underscore: "_";
|
|
90
|
+
readonly plus: "+";
|
|
91
|
+
readonly pipe: "|";
|
|
92
|
+
readonly tilde: "~";
|
|
93
|
+
readonly leftbrace: "{";
|
|
94
|
+
readonly rightbrace: "}";
|
|
95
|
+
readonly colon: ":";
|
|
96
|
+
readonly lessthan: "<";
|
|
97
|
+
readonly greaterthan: ">";
|
|
98
|
+
readonly question: "?";
|
|
99
|
+
readonly ctrl: <K extends BaseKey>(key: K) => `ctrl+${K}`;
|
|
100
|
+
readonly shift: <K extends BaseKey>(key: K) => `shift+${K}`;
|
|
101
|
+
readonly alt: <K extends BaseKey>(key: K) => `alt+${K}`;
|
|
102
|
+
readonly ctrlShift: <K extends BaseKey>(key: K) => `ctrl+shift+${K}`;
|
|
103
|
+
readonly shiftCtrl: <K extends BaseKey>(key: K) => `shift+ctrl+${K}`;
|
|
104
|
+
readonly ctrlAlt: <K extends BaseKey>(key: K) => `ctrl+alt+${K}`;
|
|
105
|
+
readonly altCtrl: <K extends BaseKey>(key: K) => `alt+ctrl+${K}`;
|
|
106
|
+
readonly shiftAlt: <K extends BaseKey>(key: K) => `shift+alt+${K}`;
|
|
107
|
+
readonly altShift: <K extends BaseKey>(key: K) => `alt+shift+${K}`;
|
|
108
|
+
readonly ctrlShiftAlt: <K extends BaseKey>(key: K) => `ctrl+shift+alt+${K}`;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Event types from Kitty keyboard protocol (flag 2)
|
|
112
|
+
* 1 = key press, 2 = key repeat, 3 = key release
|
|
113
|
+
*/
|
|
114
|
+
export type KeyEventType = "press" | "repeat" | "release";
|
|
115
|
+
/**
|
|
116
|
+
* Check if the last parsed key event was a key release.
|
|
117
|
+
* Only meaningful when Kitty keyboard protocol with flag 2 is active.
|
|
118
|
+
*/
|
|
119
|
+
export declare function isKeyRelease(data: string): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Check if the last parsed key event was a key repeat.
|
|
122
|
+
* Only meaningful when Kitty keyboard protocol with flag 2 is active.
|
|
123
|
+
*/
|
|
124
|
+
export declare function isKeyRepeat(data: string): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Match input data against a key identifier string.
|
|
127
|
+
*
|
|
128
|
+
* Supported key identifiers:
|
|
129
|
+
* - Single keys: "escape", "tab", "enter", "backspace", "delete", "home", "end", "space"
|
|
130
|
+
* - Arrow keys: "up", "down", "left", "right"
|
|
131
|
+
* - Ctrl combinations: "ctrl+c", "ctrl+z", etc.
|
|
132
|
+
* - Shift combinations: "shift+tab", "shift+enter"
|
|
133
|
+
* - Alt combinations: "alt+enter", "alt+backspace"
|
|
134
|
+
* - Combined modifiers: "shift+ctrl+p", "ctrl+alt+x"
|
|
135
|
+
*
|
|
136
|
+
* Use the Key helper for autocomplete: Key.ctrl("c"), Key.escape, Key.ctrlShift("p")
|
|
137
|
+
*
|
|
138
|
+
* @param data - Raw input data from terminal
|
|
139
|
+
* @param keyId - Key identifier (e.g., "ctrl+c", "escape", Key.ctrl("c"))
|
|
140
|
+
*/
|
|
141
|
+
export declare function matchesKey(data: string, keyId: KeyId): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Parse input data and return the key identifier if recognized.
|
|
144
|
+
*
|
|
145
|
+
* @param data - Raw input data from terminal
|
|
146
|
+
* @returns Key identifier string (e.g., "ctrl+c") or undefined
|
|
147
|
+
*/
|
|
148
|
+
export declare function parseKey(data: string): string | undefined;
|
|
149
|
+
export {};
|