phi-code-tui 0.56.3
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/README.md +761 -0
- package/dist/autocomplete.d.ts +50 -0
- package/dist/autocomplete.d.ts.map +1 -0
- package/dist/autocomplete.js +593 -0
- package/dist/autocomplete.js.map +1 -0
- package/dist/components/box.d.ts +22 -0
- package/dist/components/box.d.ts.map +1 -0
- package/dist/components/box.js +99 -0
- package/dist/components/box.js.map +1 -0
- package/dist/components/cancellable-loader.d.ts +22 -0
- package/dist/components/cancellable-loader.d.ts.map +1 -0
- package/dist/components/cancellable-loader.js +36 -0
- package/dist/components/cancellable-loader.js.map +1 -0
- package/dist/components/editor.d.ts +205 -0
- package/dist/components/editor.d.ts.map +1 -0
- package/dist/components/editor.js +1632 -0
- package/dist/components/editor.js.map +1 -0
- package/dist/components/image.d.ts +28 -0
- package/dist/components/image.d.ts.map +1 -0
- package/dist/components/image.js +61 -0
- package/dist/components/image.js.map +1 -0
- package/dist/components/input.d.ts +37 -0
- package/dist/components/input.d.ts.map +1 -0
- package/dist/components/input.js +443 -0
- package/dist/components/input.js.map +1 -0
- package/dist/components/loader.d.ts +21 -0
- package/dist/components/loader.d.ts.map +1 -0
- package/dist/components/loader.js +46 -0
- package/dist/components/loader.js.map +1 -0
- package/dist/components/markdown.d.ts +95 -0
- package/dist/components/markdown.d.ts.map +1 -0
- package/dist/components/markdown.js +641 -0
- package/dist/components/markdown.js.map +1 -0
- package/dist/components/select-list.d.ts +32 -0
- package/dist/components/select-list.d.ts.map +1 -0
- package/dist/components/select-list.js +148 -0
- package/dist/components/select-list.js.map +1 -0
- package/dist/components/settings-list.d.ts +50 -0
- package/dist/components/settings-list.d.ts.map +1 -0
- package/dist/components/settings-list.js +177 -0
- package/dist/components/settings-list.js.map +1 -0
- package/dist/components/spacer.d.ts +12 -0
- package/dist/components/spacer.d.ts.map +1 -0
- package/dist/components/spacer.js +22 -0
- package/dist/components/spacer.js.map +1 -0
- package/dist/components/text.d.ts +19 -0
- package/dist/components/text.d.ts.map +1 -0
- package/dist/components/text.js +81 -0
- package/dist/components/text.js.map +1 -0
- package/dist/components/truncated-text.d.ts +13 -0
- package/dist/components/truncated-text.d.ts.map +1 -0
- package/dist/components/truncated-text.js +48 -0
- package/dist/components/truncated-text.js.map +1 -0
- package/dist/editor-component.d.ts +39 -0
- package/dist/editor-component.d.ts.map +1 -0
- package/dist/editor-component.js +2 -0
- package/dist/editor-component.js.map +1 -0
- package/dist/fuzzy.d.ts +16 -0
- package/dist/fuzzy.d.ts.map +1 -0
- package/dist/fuzzy.js +107 -0
- package/dist/fuzzy.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/keybindings.d.ts +39 -0
- package/dist/keybindings.d.ts.map +1 -0
- package/dist/keybindings.js +113 -0
- package/dist/keybindings.js.map +1 -0
- package/dist/keys.d.ts +175 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +1015 -0
- package/dist/keys.js.map +1 -0
- package/dist/kill-ring.d.ts +28 -0
- package/dist/kill-ring.d.ts.map +1 -0
- package/dist/kill-ring.js +46 -0
- package/dist/kill-ring.js.map +1 -0
- package/dist/stdin-buffer.d.ts +48 -0
- package/dist/stdin-buffer.d.ts.map +1 -0
- package/dist/stdin-buffer.js +316 -0
- package/dist/stdin-buffer.js.map +1 -0
- package/dist/terminal-image.d.ts +68 -0
- package/dist/terminal-image.d.ts.map +1 -0
- package/dist/terminal-image.js +288 -0
- package/dist/terminal-image.js.map +1 -0
- package/dist/terminal.d.ts +84 -0
- package/dist/terminal.d.ts.map +1 -0
- package/dist/terminal.js +267 -0
- package/dist/terminal.js.map +1 -0
- package/dist/tui.d.ts +211 -0
- package/dist/tui.d.ts.map +1 -0
- package/dist/tui.js +961 -0
- package/dist/tui.js.map +1 -0
- package/dist/undo-stack.d.ts +17 -0
- package/dist/undo-stack.d.ts.map +1 -0
- package/dist/undo-stack.js +27 -0
- package/dist/undo-stack.js.map +1 -0
- package/dist/utils.d.ts +78 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +817 -0
- package/dist/utils.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { matchesKey } from "./keys.js";
|
|
2
|
+
/**
|
|
3
|
+
* Default editor keybindings.
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_EDITOR_KEYBINDINGS = {
|
|
6
|
+
// Cursor movement
|
|
7
|
+
cursorUp: "up",
|
|
8
|
+
cursorDown: "down",
|
|
9
|
+
cursorLeft: ["left", "ctrl+b"],
|
|
10
|
+
cursorRight: ["right", "ctrl+f"],
|
|
11
|
+
cursorWordLeft: ["alt+left", "ctrl+left", "alt+b"],
|
|
12
|
+
cursorWordRight: ["alt+right", "ctrl+right", "alt+f"],
|
|
13
|
+
cursorLineStart: ["home", "ctrl+a"],
|
|
14
|
+
cursorLineEnd: ["end", "ctrl+e"],
|
|
15
|
+
jumpForward: "ctrl+]",
|
|
16
|
+
jumpBackward: "ctrl+alt+]",
|
|
17
|
+
pageUp: "pageUp",
|
|
18
|
+
pageDown: "pageDown",
|
|
19
|
+
// Deletion
|
|
20
|
+
deleteCharBackward: "backspace",
|
|
21
|
+
deleteCharForward: ["delete", "ctrl+d"],
|
|
22
|
+
deleteWordBackward: ["ctrl+w", "alt+backspace"],
|
|
23
|
+
deleteWordForward: ["alt+d", "alt+delete"],
|
|
24
|
+
deleteToLineStart: "ctrl+u",
|
|
25
|
+
deleteToLineEnd: "ctrl+k",
|
|
26
|
+
// Text input
|
|
27
|
+
newLine: "shift+enter",
|
|
28
|
+
submit: "enter",
|
|
29
|
+
tab: "tab",
|
|
30
|
+
// Selection/autocomplete
|
|
31
|
+
selectUp: "up",
|
|
32
|
+
selectDown: "down",
|
|
33
|
+
selectPageUp: "pageUp",
|
|
34
|
+
selectPageDown: "pageDown",
|
|
35
|
+
selectConfirm: "enter",
|
|
36
|
+
selectCancel: ["escape", "ctrl+c"],
|
|
37
|
+
// Clipboard
|
|
38
|
+
copy: "ctrl+c",
|
|
39
|
+
// Kill ring
|
|
40
|
+
yank: "ctrl+y",
|
|
41
|
+
yankPop: "alt+y",
|
|
42
|
+
// Undo
|
|
43
|
+
undo: "ctrl+-",
|
|
44
|
+
// Tool output
|
|
45
|
+
expandTools: "ctrl+o",
|
|
46
|
+
// Session
|
|
47
|
+
toggleSessionPath: "ctrl+p",
|
|
48
|
+
toggleSessionSort: "ctrl+s",
|
|
49
|
+
renameSession: "ctrl+r",
|
|
50
|
+
deleteSession: "ctrl+d",
|
|
51
|
+
deleteSessionNoninvasive: "ctrl+backspace",
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Manages keybindings for the editor.
|
|
55
|
+
*/
|
|
56
|
+
export class EditorKeybindingsManager {
|
|
57
|
+
constructor(config = {}) {
|
|
58
|
+
this.actionToKeys = new Map();
|
|
59
|
+
this.buildMaps(config);
|
|
60
|
+
}
|
|
61
|
+
buildMaps(config) {
|
|
62
|
+
this.actionToKeys.clear();
|
|
63
|
+
// Start with defaults
|
|
64
|
+
for (const [action, keys] of Object.entries(DEFAULT_EDITOR_KEYBINDINGS)) {
|
|
65
|
+
const keyArray = Array.isArray(keys) ? keys : [keys];
|
|
66
|
+
this.actionToKeys.set(action, [...keyArray]);
|
|
67
|
+
}
|
|
68
|
+
// Override with user config
|
|
69
|
+
for (const [action, keys] of Object.entries(config)) {
|
|
70
|
+
if (keys === undefined)
|
|
71
|
+
continue;
|
|
72
|
+
const keyArray = Array.isArray(keys) ? keys : [keys];
|
|
73
|
+
this.actionToKeys.set(action, keyArray);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Check if input matches a specific action.
|
|
78
|
+
*/
|
|
79
|
+
matches(data, action) {
|
|
80
|
+
const keys = this.actionToKeys.get(action);
|
|
81
|
+
if (!keys)
|
|
82
|
+
return false;
|
|
83
|
+
for (const key of keys) {
|
|
84
|
+
if (matchesKey(data, key))
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get keys bound to an action.
|
|
91
|
+
*/
|
|
92
|
+
getKeys(action) {
|
|
93
|
+
return this.actionToKeys.get(action) ?? [];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Update configuration.
|
|
97
|
+
*/
|
|
98
|
+
setConfig(config) {
|
|
99
|
+
this.buildMaps(config);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Global instance
|
|
103
|
+
let globalEditorKeybindings = null;
|
|
104
|
+
export function getEditorKeybindings() {
|
|
105
|
+
if (!globalEditorKeybindings) {
|
|
106
|
+
globalEditorKeybindings = new EditorKeybindingsManager();
|
|
107
|
+
}
|
|
108
|
+
return globalEditorKeybindings;
|
|
109
|
+
}
|
|
110
|
+
export function setEditorKeybindings(manager) {
|
|
111
|
+
globalEditorKeybindings = manager;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=keybindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keybindings.js","sourceRoot":"","sources":["../src/keybindings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,WAAW,CAAC;AA+DnD;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAsC;IAC5E,kBAAkB;IAClB,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,MAAM;IAClB,UAAU,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC9B,WAAW,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;IAChC,cAAc,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,OAAO,CAAC;IAClD,eAAe,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,OAAO,CAAC;IACrD,eAAe,EAAE,CAAC,MAAM,EAAE,QA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5C,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,MAA+B;QACxC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;CACD;AAED,kBAAkB;AAClB,IAAI,uBAAuB,GAAoC,IAAI,CAAC;AAEpE,MAAM,UAAU,oBAAoB;IACnC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC9B,uBAAuB,GAAG,IAAI,wBAAwB,EAAE,CAAC;IAC1D,CAAC;IACD,OAAO,uBAAuB,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAiC;IACrE,uBAAuB,GAAG,OAAO,CAAC;AACnC,CAAC","sourcesContent":["import { type KeyId, matchesKey } from \"./keys.js\";\n\n/**\n * Editor actions that can be bound to keys.\n */\nexport type EditorAction =\n\t// Cursor movement\n\t| \"cursorUp\"\n\t| \"cursorDown\"\n\t| \"cursorLeft\"\n\t| \"cursorRight\"\n\t| \"cursorWordLeft\"\n\t| \"cursorWordRight\"\n\t| \"cursorLineStart\"\n\t| \"cursorLineEnd\"\n\t| \"jumpForward\"\n\t| \"jumpBackward\"\n\t| \"pageUp\"\n\t| \"pageDown\"\n\t// Deletion\n\t| \"deleteCharBackward\"\n\t| \"deleteCharForward\"\n\t| \"deleteWordBackward\"\n\t| \"deleteWordForward\"\n\t| \"deleteToLineStart\"\n\t| \"deleteToLineEnd\"\n\t// Text input\n\t| \"newLine\"\n\t| \"submit\"\n\t| \"tab\"\n\t// Selection/autocomplete\n\t| \"selectUp\"\n\t| \"selectDown\"\n\t| \"selectPageUp\"\n\t| \"selectPageDown\"\n\t| \"selectConfirm\"\n\t| \"selectCancel\"\n\t// Clipboard\n\t| \"copy\"\n\t// Kill ring\n\t| \"yank\"\n\t| \"yankPop\"\n\t// Undo\n\t| \"undo\"\n\t// Tool output\n\t| \"expandTools\"\n\t// Session\n\t| \"toggleSessionPath\"\n\t| \"toggleSessionSort\"\n\t| \"renameSession\"\n\t| \"deleteSession\"\n\t| \"deleteSessionNoninvasive\";\n\n// Re-export KeyId from keys.ts\nexport type { KeyId };\n\n/**\n * Editor keybindings configuration.\n */\nexport type EditorKeybindingsConfig = {\n\t[K in EditorAction]?: KeyId | KeyId[];\n};\n\n/**\n * Default editor keybindings.\n */\nexport const DEFAULT_EDITOR_KEYBINDINGS: Required<EditorKeybindingsConfig> = {\n\t// Cursor movement\n\tcursorUp: \"up\",\n\tcursorDown: \"down\",\n\tcursorLeft: [\"left\", \"ctrl+b\"],\n\tcursorRight: [\"right\", \"ctrl+f\"],\n\tcursorWordLeft: [\"alt+left\", \"ctrl+left\", \"alt+b\"],\n\tcursorWordRight: [\"alt+right\", \"ctrl+right\", \"alt+f\"],\n\tcursorLineStart: [\"home\", \"ctrl+a\"],\n\tcursorLineEnd: [\"end\", \"ctrl+e\"],\n\tjumpForward: \"ctrl+]\",\n\tjumpBackward: \"ctrl+alt+]\",\n\tpageUp: \"pageUp\",\n\tpageDown: \"pageDown\",\n\t// Deletion\n\tdeleteCharBackward: \"backspace\",\n\tdeleteCharForward: [\"delete\", \"ctrl+d\"],\n\tdeleteWordBackward: [\"ctrl+w\", \"alt+backspace\"],\n\tdeleteWordForward: [\"alt+d\", \"alt+delete\"],\n\tdeleteToLineStart: \"ctrl+u\",\n\tdeleteToLineEnd: \"ctrl+k\",\n\t// Text input\n\tnewLine: \"shift+enter\",\n\tsubmit: \"enter\",\n\ttab: \"tab\",\n\t// Selection/autocomplete\n\tselectUp: \"up\",\n\tselectDown: \"down\",\n\tselectPageUp: \"pageUp\",\n\tselectPageDown: \"pageDown\",\n\tselectConfirm: \"enter\",\n\tselectCancel: [\"escape\", \"ctrl+c\"],\n\t// Clipboard\n\tcopy: \"ctrl+c\",\n\t// Kill ring\n\tyank: \"ctrl+y\",\n\tyankPop: \"alt+y\",\n\t// Undo\n\tundo: \"ctrl+-\",\n\t// Tool output\n\texpandTools: \"ctrl+o\",\n\t// Session\n\ttoggleSessionPath: \"ctrl+p\",\n\ttoggleSessionSort: \"ctrl+s\",\n\trenameSession: \"ctrl+r\",\n\tdeleteSession: \"ctrl+d\",\n\tdeleteSessionNoninvasive: \"ctrl+backspace\",\n};\n\n/**\n * Manages keybindings for the editor.\n */\nexport class EditorKeybindingsManager {\n\tprivate actionToKeys: Map<EditorAction, KeyId[]>;\n\n\tconstructor(config: EditorKeybindingsConfig = {}) {\n\t\tthis.actionToKeys = new Map();\n\t\tthis.buildMaps(config);\n\t}\n\n\tprivate buildMaps(config: EditorKeybindingsConfig): void {\n\t\tthis.actionToKeys.clear();\n\n\t\t// Start with defaults\n\t\tfor (const [action, keys] of Object.entries(DEFAULT_EDITOR_KEYBINDINGS)) {\n\t\t\tconst keyArray = Array.isArray(keys) ? keys : [keys];\n\t\t\tthis.actionToKeys.set(action as EditorAction, [...keyArray]);\n\t\t}\n\n\t\t// Override with user config\n\t\tfor (const [action, keys] of Object.entries(config)) {\n\t\t\tif (keys === undefined) continue;\n\t\t\tconst keyArray = Array.isArray(keys) ? keys : [keys];\n\t\t\tthis.actionToKeys.set(action as EditorAction, keyArray);\n\t\t}\n\t}\n\n\t/**\n\t * Check if input matches a specific action.\n\t */\n\tmatches(data: string, action: EditorAction): boolean {\n\t\tconst keys = this.actionToKeys.get(action);\n\t\tif (!keys) return false;\n\t\tfor (const key of keys) {\n\t\t\tif (matchesKey(data, key)) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Get keys bound to an action.\n\t */\n\tgetKeys(action: EditorAction): KeyId[] {\n\t\treturn this.actionToKeys.get(action) ?? [];\n\t}\n\n\t/**\n\t * Update configuration.\n\t */\n\tsetConfig(config: EditorKeybindingsConfig): void {\n\t\tthis.buildMaps(config);\n\t}\n}\n\n// Global instance\nlet globalEditorKeybindings: EditorKeybindingsManager | null = null;\n\nexport function getEditorKeybindings(): EditorKeybindingsManager {\n\tif (!globalEditorKeybindings) {\n\t\tglobalEditorKeybindings = new EditorKeybindingsManager();\n\t}\n\treturn globalEditorKeybindings;\n}\n\nexport function setEditorKeybindings(manager: EditorKeybindingsManager): void {\n\tglobalEditorKeybindings = manager;\n}\n"]}
|
package/dist/keys.d.ts
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard input handling for terminal applications.
|
|
3
|
+
*
|
|
4
|
+
* Supports both legacy terminal sequences and Kitty keyboard protocol.
|
|
5
|
+
* See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
|
|
6
|
+
* Reference: https://github.com/sst/opentui/blob/7da92b4088aebfe27b9f691c04163a48821e49fd/packages/core/src/lib/parse.keypress.ts
|
|
7
|
+
*
|
|
8
|
+
* Symbol keys are also supported, however some ctrl+symbol combos
|
|
9
|
+
* overlap with ASCII codes, e.g. ctrl+[ = ESC.
|
|
10
|
+
* See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#legacy-ctrl-mapping-of-ascii-keys
|
|
11
|
+
* Those can still be * used for ctrl+shift combos
|
|
12
|
+
*
|
|
13
|
+
* API:
|
|
14
|
+
* - matchesKey(data, keyId) - Check if input matches a key identifier
|
|
15
|
+
* - parseKey(data) - Parse input and return the key identifier
|
|
16
|
+
* - Key - Helper object for creating typed key identifiers
|
|
17
|
+
* - setKittyProtocolActive(active) - Set global Kitty protocol state
|
|
18
|
+
* - isKittyProtocolActive() - Query global Kitty protocol state
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Set the global Kitty keyboard protocol state.
|
|
22
|
+
* Called by ProcessTerminal after detecting protocol support.
|
|
23
|
+
*/
|
|
24
|
+
export declare function setKittyProtocolActive(active: boolean): void;
|
|
25
|
+
/**
|
|
26
|
+
* Query whether Kitty keyboard protocol is currently active.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isKittyProtocolActive(): boolean;
|
|
29
|
+
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";
|
|
30
|
+
type SymbolKey = "`" | "-" | "=" | "[" | "]" | "\\" | ";" | "'" | "," | "." | "/" | "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "_" | "+" | "|" | "~" | "{" | "}" | ":" | "<" | ">" | "?";
|
|
31
|
+
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";
|
|
32
|
+
type BaseKey = Letter | SymbolKey | SpecialKey;
|
|
33
|
+
/**
|
|
34
|
+
* Union type of all valid key identifiers.
|
|
35
|
+
* Provides autocomplete and catches typos at compile time.
|
|
36
|
+
*/
|
|
37
|
+
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}`;
|
|
38
|
+
/**
|
|
39
|
+
* Helper object for creating typed key identifiers with autocomplete.
|
|
40
|
+
*
|
|
41
|
+
* Usage:
|
|
42
|
+
* - Key.escape, Key.enter, Key.tab, etc. for special keys
|
|
43
|
+
* - Key.backtick, Key.comma, Key.period, etc. for symbol keys
|
|
44
|
+
* - Key.ctrl("c"), Key.alt("x") for single modifier
|
|
45
|
+
* - Key.ctrlShift("p"), Key.ctrlAlt("x") for combined modifiers
|
|
46
|
+
*/
|
|
47
|
+
export declare const Key: {
|
|
48
|
+
readonly escape: "escape";
|
|
49
|
+
readonly esc: "esc";
|
|
50
|
+
readonly enter: "enter";
|
|
51
|
+
readonly return: "return";
|
|
52
|
+
readonly tab: "tab";
|
|
53
|
+
readonly space: "space";
|
|
54
|
+
readonly backspace: "backspace";
|
|
55
|
+
readonly delete: "delete";
|
|
56
|
+
readonly insert: "insert";
|
|
57
|
+
readonly clear: "clear";
|
|
58
|
+
readonly home: "home";
|
|
59
|
+
readonly end: "end";
|
|
60
|
+
readonly pageUp: "pageUp";
|
|
61
|
+
readonly pageDown: "pageDown";
|
|
62
|
+
readonly up: "up";
|
|
63
|
+
readonly down: "down";
|
|
64
|
+
readonly left: "left";
|
|
65
|
+
readonly right: "right";
|
|
66
|
+
readonly f1: "f1";
|
|
67
|
+
readonly f2: "f2";
|
|
68
|
+
readonly f3: "f3";
|
|
69
|
+
readonly f4: "f4";
|
|
70
|
+
readonly f5: "f5";
|
|
71
|
+
readonly f6: "f6";
|
|
72
|
+
readonly f7: "f7";
|
|
73
|
+
readonly f8: "f8";
|
|
74
|
+
readonly f9: "f9";
|
|
75
|
+
readonly f10: "f10";
|
|
76
|
+
readonly f11: "f11";
|
|
77
|
+
readonly f12: "f12";
|
|
78
|
+
readonly backtick: "`";
|
|
79
|
+
readonly hyphen: "-";
|
|
80
|
+
readonly equals: "=";
|
|
81
|
+
readonly leftbracket: "[";
|
|
82
|
+
readonly rightbracket: "]";
|
|
83
|
+
readonly backslash: "\\";
|
|
84
|
+
readonly semicolon: ";";
|
|
85
|
+
readonly quote: "'";
|
|
86
|
+
readonly comma: ",";
|
|
87
|
+
readonly period: ".";
|
|
88
|
+
readonly slash: "/";
|
|
89
|
+
readonly exclamation: "!";
|
|
90
|
+
readonly at: "@";
|
|
91
|
+
readonly hash: "#";
|
|
92
|
+
readonly dollar: "$";
|
|
93
|
+
readonly percent: "%";
|
|
94
|
+
readonly caret: "^";
|
|
95
|
+
readonly ampersand: "&";
|
|
96
|
+
readonly asterisk: "*";
|
|
97
|
+
readonly leftparen: "(";
|
|
98
|
+
readonly rightparen: ")";
|
|
99
|
+
readonly underscore: "_";
|
|
100
|
+
readonly plus: "+";
|
|
101
|
+
readonly pipe: "|";
|
|
102
|
+
readonly tilde: "~";
|
|
103
|
+
readonly leftbrace: "{";
|
|
104
|
+
readonly rightbrace: "}";
|
|
105
|
+
readonly colon: ":";
|
|
106
|
+
readonly lessthan: "<";
|
|
107
|
+
readonly greaterthan: ">";
|
|
108
|
+
readonly question: "?";
|
|
109
|
+
readonly ctrl: <K extends BaseKey>(key: K) => `ctrl+${K}`;
|
|
110
|
+
readonly shift: <K extends BaseKey>(key: K) => `shift+${K}`;
|
|
111
|
+
readonly alt: <K extends BaseKey>(key: K) => `alt+${K}`;
|
|
112
|
+
readonly ctrlShift: <K extends BaseKey>(key: K) => `ctrl+shift+${K}`;
|
|
113
|
+
readonly shiftCtrl: <K extends BaseKey>(key: K) => `shift+ctrl+${K}`;
|
|
114
|
+
readonly ctrlAlt: <K extends BaseKey>(key: K) => `ctrl+alt+${K}`;
|
|
115
|
+
readonly altCtrl: <K extends BaseKey>(key: K) => `alt+ctrl+${K}`;
|
|
116
|
+
readonly shiftAlt: <K extends BaseKey>(key: K) => `shift+alt+${K}`;
|
|
117
|
+
readonly altShift: <K extends BaseKey>(key: K) => `alt+shift+${K}`;
|
|
118
|
+
readonly ctrlShiftAlt: <K extends BaseKey>(key: K) => `ctrl+shift+alt+${K}`;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Event types from Kitty keyboard protocol (flag 2)
|
|
122
|
+
* 1 = key press, 2 = key repeat, 3 = key release
|
|
123
|
+
*/
|
|
124
|
+
export type KeyEventType = "press" | "repeat" | "release";
|
|
125
|
+
/**
|
|
126
|
+
* Check if the last parsed key event was a key release.
|
|
127
|
+
* Only meaningful when Kitty keyboard protocol with flag 2 is active.
|
|
128
|
+
*/
|
|
129
|
+
export declare function isKeyRelease(data: string): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Check if the last parsed key event was a key repeat.
|
|
132
|
+
* Only meaningful when Kitty keyboard protocol with flag 2 is active.
|
|
133
|
+
*/
|
|
134
|
+
export declare function isKeyRepeat(data: string): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Match input data against a key identifier string.
|
|
137
|
+
*
|
|
138
|
+
* Supported key identifiers:
|
|
139
|
+
* - Single keys: "escape", "tab", "enter", "backspace", "delete", "home", "end", "space"
|
|
140
|
+
* - Arrow keys: "up", "down", "left", "right"
|
|
141
|
+
* - Ctrl combinations: "ctrl+c", "ctrl+z", etc.
|
|
142
|
+
* - Shift combinations: "shift+tab", "shift+enter"
|
|
143
|
+
* - Alt combinations: "alt+enter", "alt+backspace"
|
|
144
|
+
* - Combined modifiers: "shift+ctrl+p", "ctrl+alt+x"
|
|
145
|
+
*
|
|
146
|
+
* Use the Key helper for autocomplete: Key.ctrl("c"), Key.escape, Key.ctrlShift("p")
|
|
147
|
+
*
|
|
148
|
+
* @param data - Raw input data from terminal
|
|
149
|
+
* @param keyId - Key identifier (e.g., "ctrl+c", "escape", Key.ctrl("c"))
|
|
150
|
+
*/
|
|
151
|
+
export declare function matchesKey(data: string, keyId: KeyId): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Parse input data and return the key identifier if recognized.
|
|
154
|
+
*
|
|
155
|
+
* @param data - Raw input data from terminal
|
|
156
|
+
* @returns Key identifier string (e.g., "ctrl+c") or undefined
|
|
157
|
+
*/
|
|
158
|
+
export declare function parseKey(data: string): string | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* Decode a Kitty CSI-u sequence into a printable character, if applicable.
|
|
161
|
+
*
|
|
162
|
+
* When Kitty keyboard protocol flag 1 (disambiguate) is active, terminals send
|
|
163
|
+
* CSI-u sequences for all keys, including plain printable characters. This
|
|
164
|
+
* function extracts the printable character from such sequences.
|
|
165
|
+
*
|
|
166
|
+
* Only accepts plain or Shift-modified keys. Rejects Ctrl, Alt, and unsupported
|
|
167
|
+
* modifier combinations (those are handled by keybinding matching instead).
|
|
168
|
+
* Prefers the shifted keycode when Shift is held and a shifted key is reported.
|
|
169
|
+
*
|
|
170
|
+
* @param data - Raw input data from terminal
|
|
171
|
+
* @returns The printable character, or undefined if not a printable CSI-u sequence
|
|
172
|
+
*/
|
|
173
|
+
export declare function decodeKittyPrintable(data: string): string | undefined;
|
|
174
|
+
export {};
|
|
175
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAQH;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAE5D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C;AAMD,KAAK,MAAM,GACR,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,CAAC;AAEP,KAAK,SAAS,GACX,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,IAAI,GACJ,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,CAAC;AAEP,KAAK,UAAU,GACZ,QAAQ,GACR,KAAK,GACL,OAAO,GACP,QAAQ,GACR,KAAK,GACL,OAAO,GAC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