@code-yeongyu/senpi-tui 2026.7.25-2

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.
Files changed (130) hide show
  1. package/README.md +790 -0
  2. package/dist/autocomplete.d.ts +57 -0
  3. package/dist/autocomplete.d.ts.map +1 -0
  4. package/dist/autocomplete.js +646 -0
  5. package/dist/autocomplete.js.map +1 -0
  6. package/dist/components/box.d.ts +25 -0
  7. package/dist/components/box.d.ts.map +1 -0
  8. package/dist/components/box.js +117 -0
  9. package/dist/components/box.js.map +1 -0
  10. package/dist/components/cancellable-loader.d.ts +22 -0
  11. package/dist/components/cancellable-loader.d.ts.map +1 -0
  12. package/dist/components/cancellable-loader.js +36 -0
  13. package/dist/components/cancellable-loader.js.map +1 -0
  14. package/dist/components/editor.d.ts +257 -0
  15. package/dist/components/editor.d.ts.map +1 -0
  16. package/dist/components/editor.js +2014 -0
  17. package/dist/components/editor.js.map +1 -0
  18. package/dist/components/image.d.ts +28 -0
  19. package/dist/components/image.d.ts.map +1 -0
  20. package/dist/components/image.js +82 -0
  21. package/dist/components/image.js.map +1 -0
  22. package/dist/components/input.d.ts +37 -0
  23. package/dist/components/input.d.ts.map +1 -0
  24. package/dist/components/input.js +378 -0
  25. package/dist/components/input.js.map +1 -0
  26. package/dist/components/loader.d.ts +46 -0
  27. package/dist/components/loader.d.ts.map +1 -0
  28. package/dist/components/loader.js +110 -0
  29. package/dist/components/loader.js.map +1 -0
  30. package/dist/components/markdown.d.ts +105 -0
  31. package/dist/components/markdown.d.ts.map +1 -0
  32. package/dist/components/markdown.js +789 -0
  33. package/dist/components/markdown.js.map +1 -0
  34. package/dist/components/select-list.d.ts +50 -0
  35. package/dist/components/select-list.d.ts.map +1 -0
  36. package/dist/components/select-list.js +154 -0
  37. package/dist/components/select-list.js.map +1 -0
  38. package/dist/components/settings-list.d.ts +50 -0
  39. package/dist/components/settings-list.d.ts.map +1 -0
  40. package/dist/components/settings-list.js +177 -0
  41. package/dist/components/settings-list.js.map +1 -0
  42. package/dist/components/spacer.d.ts +12 -0
  43. package/dist/components/spacer.d.ts.map +1 -0
  44. package/dist/components/spacer.js +22 -0
  45. package/dist/components/spacer.js.map +1 -0
  46. package/dist/components/text.d.ts +19 -0
  47. package/dist/components/text.d.ts.map +1 -0
  48. package/dist/components/text.js +81 -0
  49. package/dist/components/text.js.map +1 -0
  50. package/dist/components/truncated-text.d.ts +13 -0
  51. package/dist/components/truncated-text.d.ts.map +1 -0
  52. package/dist/components/truncated-text.js +48 -0
  53. package/dist/components/truncated-text.js.map +1 -0
  54. package/dist/editor-component.d.ts +39 -0
  55. package/dist/editor-component.d.ts.map +1 -0
  56. package/dist/editor-component.js +2 -0
  57. package/dist/editor-component.js.map +1 -0
  58. package/dist/fuzzy.d.ts +16 -0
  59. package/dist/fuzzy.d.ts.map +1 -0
  60. package/dist/fuzzy.js +180 -0
  61. package/dist/fuzzy.js.map +1 -0
  62. package/dist/index.d.ts +25 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +35 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/keybindings.d.ts +193 -0
  67. package/dist/keybindings.d.ts.map +1 -0
  68. package/dist/keybindings.js +172 -0
  69. package/dist/keybindings.js.map +1 -0
  70. package/dist/keys.d.ts +184 -0
  71. package/dist/keys.d.ts.map +1 -0
  72. package/dist/keys.js +1174 -0
  73. package/dist/keys.js.map +1 -0
  74. package/dist/kill-ring.d.ts +28 -0
  75. package/dist/kill-ring.d.ts.map +1 -0
  76. package/dist/kill-ring.js +46 -0
  77. package/dist/kill-ring.js.map +1 -0
  78. package/dist/mux.d.ts +4 -0
  79. package/dist/mux.d.ts.map +1 -0
  80. package/dist/mux.js +10 -0
  81. package/dist/mux.js.map +1 -0
  82. package/dist/native-modifiers.d.ts +3 -0
  83. package/dist/native-modifiers.d.ts.map +1 -0
  84. package/dist/native-modifiers.js +53 -0
  85. package/dist/native-modifiers.js.map +1 -0
  86. package/dist/slash-command-autocomplete.d.ts +3 -0
  87. package/dist/slash-command-autocomplete.d.ts.map +1 -0
  88. package/dist/slash-command-autocomplete.js +38 -0
  89. package/dist/slash-command-autocomplete.js.map +1 -0
  90. package/dist/stdin-buffer.d.ts +51 -0
  91. package/dist/stdin-buffer.d.ts.map +1 -0
  92. package/dist/stdin-buffer.js +366 -0
  93. package/dist/stdin-buffer.js.map +1 -0
  94. package/dist/terminal-colors.d.ts +10 -0
  95. package/dist/terminal-colors.d.ts.map +1 -0
  96. package/dist/terminal-colors.js +59 -0
  97. package/dist/terminal-colors.js.map +1 -0
  98. package/dist/terminal-image.d.ts +88 -0
  99. package/dist/terminal-image.d.ts.map +1 -0
  100. package/dist/terminal-image.js +358 -0
  101. package/dist/terminal-image.js.map +1 -0
  102. package/dist/terminal-text.d.ts +4 -0
  103. package/dist/terminal-text.d.ts.map +1 -0
  104. package/dist/terminal-text.js +18 -0
  105. package/dist/terminal-text.js.map +1 -0
  106. package/dist/terminal.d.ts +128 -0
  107. package/dist/terminal.d.ts.map +1 -0
  108. package/dist/terminal.js +493 -0
  109. package/dist/terminal.js.map +1 -0
  110. package/dist/tui.d.ts +325 -0
  111. package/dist/tui.d.ts.map +1 -0
  112. package/dist/tui.js +1955 -0
  113. package/dist/tui.js.map +1 -0
  114. package/dist/undo-stack.d.ts +17 -0
  115. package/dist/undo-stack.d.ts.map +1 -0
  116. package/dist/undo-stack.js +27 -0
  117. package/dist/undo-stack.js.map +1 -0
  118. package/dist/utils.d.ts +91 -0
  119. package/dist/utils.d.ts.map +1 -0
  120. package/dist/utils.js +1173 -0
  121. package/dist/utils.js.map +1 -0
  122. package/dist/word-navigation.d.ts +25 -0
  123. package/dist/word-navigation.d.ts.map +1 -0
  124. package/dist/word-navigation.js +96 -0
  125. package/dist/word-navigation.js.map +1 -0
  126. package/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
  127. package/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  128. package/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  129. package/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  130. package/package.json +48 -0
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ // Core TUI interfaces and classes
2
+ // Autocomplete support
3
+ export { CombinedAutocompleteProvider, } from "./autocomplete.js";
4
+ // Components
5
+ export { Box } from "./components/box.js";
6
+ export { CancellableLoader } from "./components/cancellable-loader.js";
7
+ export { Editor } from "./components/editor.js";
8
+ export { Image } from "./components/image.js";
9
+ export { Input } from "./components/input.js";
10
+ export { Loader } from "./components/loader.js";
11
+ export { clearRenderCache, getMarkdownHighlightCallCount, Markdown, resetMarkdownHighlightCallCount, } from "./components/markdown.js";
12
+ export { SelectList, } from "./components/select-list.js";
13
+ export { SettingsList } from "./components/settings-list.js";
14
+ export { Spacer } from "./components/spacer.js";
15
+ export { Text } from "./components/text.js";
16
+ export { TruncatedText } from "./components/truncated-text.js";
17
+ // Fuzzy matching
18
+ export { fuzzyFilter, fuzzyMatch } from "./fuzzy.js";
19
+ // Keybindings
20
+ export { getKeybindings, KeybindingsManager, setKeybindings, TUI_KEYBINDINGS, } from "./keybindings.js";
21
+ // Keyboard input handling
22
+ export { decodeKittyPrintable, isKeyRelease, isKeyRepeat, isKittyProtocolActive, Key, matchesKey, parseKey, setKittyProtocolActive, } from "./keys.js";
23
+ // Input buffering for batch splitting
24
+ export { StdinBuffer } from "./stdin-buffer.js";
25
+ // Terminal interface and implementations
26
+ export { ProcessTerminal } from "./terminal.js";
27
+ // Terminal colors
28
+ export { parseOsc11BackgroundColor, parseTerminalColorSchemeReport, } from "./terminal-colors.js";
29
+ // Terminal image support
30
+ export { allocateImageId, deleteAllKittyImages, deleteKittyImage, detectCapabilities, encodeITerm2, encodeKitty, getCapabilities, getCellDimensions, getGifDimensions, getImageDimensions, getJpegDimensions, getPngDimensions, getWebpDimensions, hyperlink, renderImage, resetCapabilitiesCache, setCapabilities, setCellDimensions, } from "./terminal-image.js";
31
+ export { imageFallback, sanitizeTerminalLabel } from "./terminal-text.js";
32
+ export { Container, CURSOR_MARKER, isFocusable, TUI, } from "./tui.js";
33
+ // Utilities
34
+ export { getGraphemeSegmenter, getWordSegmenter, sliceByColumn, truncateToWidth, visibleWidth, wrapTextWithAnsi, } from "./utils.js";
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAElC,uBAAuB;AACvB,OAAO,EAIN,4BAA4B,GAE5B,MAAM,mBAAmB,CAAC;AAC3B,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAwC,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,KAAK,EAAsC,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAA+B,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EACN,gBAAgB,EAEhB,6BAA6B,EAC7B,QAAQ,EAGR,+BAA+B,GAC/B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAEN,UAAU,GAIV,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAoB,YAAY,EAA0B,MAAM,+BAA+B,CAAC;AACvG,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAG/D,iBAAiB;AACjB,OAAO,EAAmB,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACtE,cAAc;AACd,OAAO,EACN,cAAc,EAOd,kBAAkB,EAClB,cAAc,EACd,eAAe,GACf,MAAM,kBAAkB,CAAC;AAC1B,0BAA0B;AAC1B,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,GAAG,EAGH,UAAU,EACV,QAAQ,EACR,sBAAsB,GACtB,MAAM,WAAW,CAAC;AACnB,sCAAsC;AACtC,OAAO,EAAE,WAAW,EAAqD,MAAM,mBAAmB,CAAC;AACnG,yCAAyC;AACzC,OAAO,EAAE,eAAe,EAA8C,MAAM,eAAe,CAAC;AAC5F,kBAAkB;AAClB,OAAO,EACN,yBAAyB,EACzB,8BAA8B,GAG9B,MAAM,sBAAsB,CAAC;AAC9B,yBAAyB;AACzB,OAAO,EACN,eAAe,EAEf,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EAIT,WAAW,EACX,sBAAsB,EACtB,eAAe,EACf,iBAAiB,GAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAEN,SAAS,EACT,aAAa,EAEb,WAAW,EAOX,GAAG,GACH,MAAM,UAAU,CAAC;AAClB,YAAY;AACZ,OAAO,EACN,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,gBAAgB,GAChB,MAAM,YAAY,CAAC","sourcesContent":["// Core TUI interfaces and classes\n\n// Autocomplete support\nexport {\n\ttype AutocompleteItem,\n\ttype AutocompleteProvider,\n\ttype AutocompleteSuggestions,\n\tCombinedAutocompleteProvider,\n\ttype SlashCommand,\n} from \"./autocomplete.ts\";\n// Components\nexport { Box } from \"./components/box.ts\";\nexport { CancellableLoader } from \"./components/cancellable-loader.ts\";\nexport { Editor, type EditorOptions, type EditorTheme } from \"./components/editor.ts\";\nexport { Image, type ImageOptions, type ImageTheme } from \"./components/image.ts\";\nexport { Input } from \"./components/input.ts\";\nexport { Loader, type LoaderIndicatorOptions } from \"./components/loader.ts\";\nexport {\n\tclearRenderCache,\n\ttype DefaultTextStyle,\n\tgetMarkdownHighlightCallCount,\n\tMarkdown,\n\ttype MarkdownOptions,\n\ttype MarkdownTheme,\n\tresetMarkdownHighlightCallCount,\n} from \"./components/markdown.ts\";\nexport {\n\ttype SelectItem,\n\tSelectList,\n\ttype SelectListLayoutOptions,\n\ttype SelectListTheme,\n\ttype SelectListTruncatePrimaryContext,\n} from \"./components/select-list.ts\";\nexport { type SettingItem, SettingsList, type SettingsListTheme } from \"./components/settings-list.ts\";\nexport { Spacer } from \"./components/spacer.ts\";\nexport { Text } from \"./components/text.ts\";\nexport { TruncatedText } from \"./components/truncated-text.ts\";\n// Editor component interface (for custom editors)\nexport type { EditorComponent } from \"./editor-component.ts\";\n// Fuzzy matching\nexport { type FuzzyMatch, fuzzyFilter, fuzzyMatch } from \"./fuzzy.ts\";\n// Keybindings\nexport {\n\tgetKeybindings,\n\ttype Keybinding,\n\ttype KeybindingConflict,\n\ttype KeybindingDefinition,\n\ttype KeybindingDefinitions,\n\ttype Keybindings,\n\ttype KeybindingsConfig,\n\tKeybindingsManager,\n\tsetKeybindings,\n\tTUI_KEYBINDINGS,\n} from \"./keybindings.ts\";\n// Keyboard input handling\nexport {\n\tdecodeKittyPrintable,\n\tisKeyRelease,\n\tisKeyRepeat,\n\tisKittyProtocolActive,\n\tKey,\n\ttype KeyEventType,\n\ttype KeyId,\n\tmatchesKey,\n\tparseKey,\n\tsetKittyProtocolActive,\n} from \"./keys.ts\";\n// Input buffering for batch splitting\nexport { StdinBuffer, type StdinBufferEventMap, type StdinBufferOptions } from \"./stdin-buffer.ts\";\n// Terminal interface and implementations\nexport { ProcessTerminal, type ProcessTerminalOptions, type Terminal } from \"./terminal.ts\";\n// Terminal colors\nexport {\n\tparseOsc11BackgroundColor,\n\tparseTerminalColorSchemeReport,\n\ttype RgbColor,\n\ttype TerminalColorScheme,\n} from \"./terminal-colors.ts\";\n// Terminal image support\nexport {\n\tallocateImageId,\n\ttype CellDimensions,\n\tdeleteAllKittyImages,\n\tdeleteKittyImage,\n\tdetectCapabilities,\n\tencodeITerm2,\n\tencodeKitty,\n\tgetCapabilities,\n\tgetCellDimensions,\n\tgetGifDimensions,\n\tgetImageDimensions,\n\tgetJpegDimensions,\n\tgetPngDimensions,\n\tgetWebpDimensions,\n\thyperlink,\n\ttype ImageDimensions,\n\ttype ImageProtocol,\n\ttype ImageRenderOptions,\n\trenderImage,\n\tresetCapabilitiesCache,\n\tsetCapabilities,\n\tsetCellDimensions,\n\ttype TerminalCapabilities,\n} from \"./terminal-image.ts\";\nexport { imageFallback, sanitizeTerminalLabel } from \"./terminal-text.ts\";\nexport {\n\ttype Component,\n\tContainer,\n\tCURSOR_MARKER,\n\ttype Focusable,\n\tisFocusable,\n\ttype OverlayAnchor,\n\ttype OverlayHandle,\n\ttype OverlayMargin,\n\ttype OverlayOptions,\n\ttype OverlayUnfocusOptions,\n\ttype SizeValue,\n\tTUI,\n} from \"./tui.ts\";\n// Utilities\nexport {\n\tgetGraphemeSegmenter,\n\tgetWordSegmenter,\n\tsliceByColumn,\n\ttruncateToWidth,\n\tvisibleWidth,\n\twrapTextWithAnsi,\n} from \"./utils.ts\";\n"]}
@@ -0,0 +1,193 @@
1
+ import { type KeyId } from "./keys.ts";
2
+ /**
3
+ * Global keybinding registry.
4
+ * Downstream packages can add keybindings via declaration merging.
5
+ */
6
+ export interface Keybindings {
7
+ "tui.editor.cursorUp": true;
8
+ "tui.editor.cursorDown": true;
9
+ "tui.editor.cursorLeft": true;
10
+ "tui.editor.cursorRight": true;
11
+ "tui.editor.cursorWordLeft": true;
12
+ "tui.editor.cursorWordRight": true;
13
+ "tui.editor.cursorLineStart": true;
14
+ "tui.editor.cursorLineEnd": true;
15
+ "tui.editor.jumpForward": true;
16
+ "tui.editor.jumpBackward": true;
17
+ "tui.editor.pageUp": true;
18
+ "tui.editor.pageDown": true;
19
+ "tui.editor.deleteCharBackward": true;
20
+ "tui.editor.deleteCharForward": true;
21
+ "tui.editor.deleteWordBackward": true;
22
+ "tui.editor.deleteWordForward": true;
23
+ "tui.editor.deleteToLineStart": true;
24
+ "tui.editor.deleteToLineEnd": true;
25
+ "tui.editor.yank": true;
26
+ "tui.editor.yankPop": true;
27
+ "tui.editor.undo": true;
28
+ "tui.input.newLine": true;
29
+ "tui.input.submit": true;
30
+ "tui.input.tab": true;
31
+ "tui.input.copy": true;
32
+ "tui.select.up": true;
33
+ "tui.select.down": true;
34
+ "tui.select.pageUp": true;
35
+ "tui.select.pageDown": true;
36
+ "tui.select.confirm": true;
37
+ "tui.select.cancel": true;
38
+ }
39
+ export type Keybinding = keyof Keybindings;
40
+ export interface KeybindingDefinition {
41
+ defaultKeys: KeyId | KeyId[];
42
+ description?: string;
43
+ }
44
+ export type KeybindingDefinitions = Record<string, KeybindingDefinition>;
45
+ export type KeybindingsConfig = Record<string, KeyId | KeyId[] | undefined>;
46
+ export declare const TUI_KEYBINDINGS: {
47
+ readonly "tui.editor.cursorUp": {
48
+ readonly defaultKeys: "up";
49
+ readonly description: "Move cursor up";
50
+ };
51
+ readonly "tui.editor.cursorDown": {
52
+ readonly defaultKeys: "down";
53
+ readonly description: "Move cursor down";
54
+ };
55
+ readonly "tui.editor.cursorLeft": {
56
+ readonly defaultKeys: ["left", "ctrl+b"];
57
+ readonly description: "Move cursor left";
58
+ };
59
+ readonly "tui.editor.cursorRight": {
60
+ readonly defaultKeys: ["right", "ctrl+f"];
61
+ readonly description: "Move cursor right";
62
+ };
63
+ readonly "tui.editor.cursorWordLeft": {
64
+ readonly defaultKeys: ["alt+left", "ctrl+left", "alt+b"];
65
+ readonly description: "Move cursor word left";
66
+ };
67
+ readonly "tui.editor.cursorWordRight": {
68
+ readonly defaultKeys: ["alt+right", "ctrl+right", "alt+f"];
69
+ readonly description: "Move cursor word right";
70
+ };
71
+ readonly "tui.editor.cursorLineStart": {
72
+ readonly defaultKeys: ["home", "ctrl+a"];
73
+ readonly description: "Move to line start";
74
+ };
75
+ readonly "tui.editor.cursorLineEnd": {
76
+ readonly defaultKeys: ["end", "ctrl+e"];
77
+ readonly description: "Move to line end";
78
+ };
79
+ readonly "tui.editor.jumpForward": {
80
+ readonly defaultKeys: "ctrl+]";
81
+ readonly description: "Jump forward to character";
82
+ };
83
+ readonly "tui.editor.jumpBackward": {
84
+ readonly defaultKeys: "ctrl+alt+]";
85
+ readonly description: "Jump backward to character";
86
+ };
87
+ readonly "tui.editor.pageUp": {
88
+ readonly defaultKeys: "pageUp";
89
+ readonly description: "Page up";
90
+ };
91
+ readonly "tui.editor.pageDown": {
92
+ readonly defaultKeys: "pageDown";
93
+ readonly description: "Page down";
94
+ };
95
+ readonly "tui.editor.deleteCharBackward": {
96
+ readonly defaultKeys: "backspace";
97
+ readonly description: "Delete character backward";
98
+ };
99
+ readonly "tui.editor.deleteCharForward": {
100
+ readonly defaultKeys: ["delete", "ctrl+d"];
101
+ readonly description: "Delete character forward";
102
+ };
103
+ readonly "tui.editor.deleteWordBackward": {
104
+ readonly defaultKeys: ["ctrl+w", "alt+backspace"];
105
+ readonly description: "Delete word backward";
106
+ };
107
+ readonly "tui.editor.deleteWordForward": {
108
+ readonly defaultKeys: ["alt+d", "alt+delete"];
109
+ readonly description: "Delete word forward";
110
+ };
111
+ readonly "tui.editor.deleteToLineStart": {
112
+ readonly defaultKeys: "ctrl+u";
113
+ readonly description: "Delete to line start";
114
+ };
115
+ readonly "tui.editor.deleteToLineEnd": {
116
+ readonly defaultKeys: "ctrl+k";
117
+ readonly description: "Delete to line end";
118
+ };
119
+ readonly "tui.editor.yank": {
120
+ readonly defaultKeys: "ctrl+y";
121
+ readonly description: "Yank";
122
+ };
123
+ readonly "tui.editor.yankPop": {
124
+ readonly defaultKeys: "alt+y";
125
+ readonly description: "Yank pop";
126
+ };
127
+ readonly "tui.editor.undo": {
128
+ readonly defaultKeys: "ctrl+-";
129
+ readonly description: "Undo";
130
+ };
131
+ readonly "tui.input.newLine": {
132
+ readonly defaultKeys: ["shift+enter", "ctrl+j"];
133
+ readonly description: "Insert newline";
134
+ };
135
+ readonly "tui.input.submit": {
136
+ readonly defaultKeys: "enter";
137
+ readonly description: "Submit input";
138
+ };
139
+ readonly "tui.input.tab": {
140
+ readonly defaultKeys: "tab";
141
+ readonly description: "Tab / autocomplete";
142
+ };
143
+ readonly "tui.input.copy": {
144
+ readonly defaultKeys: "ctrl+c";
145
+ readonly description: "Copy selection";
146
+ };
147
+ readonly "tui.select.up": {
148
+ readonly defaultKeys: "up";
149
+ readonly description: "Move selection up";
150
+ };
151
+ readonly "tui.select.down": {
152
+ readonly defaultKeys: "down";
153
+ readonly description: "Move selection down";
154
+ };
155
+ readonly "tui.select.pageUp": {
156
+ readonly defaultKeys: "pageUp";
157
+ readonly description: "Selection page up";
158
+ };
159
+ readonly "tui.select.pageDown": {
160
+ readonly defaultKeys: "pageDown";
161
+ readonly description: "Selection page down";
162
+ };
163
+ readonly "tui.select.confirm": {
164
+ readonly defaultKeys: "enter";
165
+ readonly description: "Confirm selection";
166
+ };
167
+ readonly "tui.select.cancel": {
168
+ readonly defaultKeys: ["escape", "ctrl+c"];
169
+ readonly description: "Cancel selection";
170
+ };
171
+ };
172
+ export interface KeybindingConflict {
173
+ key: KeyId;
174
+ keybindings: string[];
175
+ }
176
+ export declare class KeybindingsManager {
177
+ private definitions;
178
+ private userBindings;
179
+ private keysById;
180
+ private conflicts;
181
+ constructor(definitions: KeybindingDefinitions, userBindings?: KeybindingsConfig);
182
+ private rebuild;
183
+ matches(data: string, keybinding: Keybinding): boolean;
184
+ getKeys(keybinding: Keybinding): KeyId[];
185
+ getDefinition(keybinding: Keybinding): KeybindingDefinition;
186
+ getConflicts(): KeybindingConflict[];
187
+ setUserBindings(userBindings: KeybindingsConfig): void;
188
+ getUserBindings(): KeybindingsConfig;
189
+ getResolvedBindings(): KeybindingsConfig;
190
+ }
191
+ export declare function setKeybindings(keybindings: KeybindingsManager): void;
192
+ export declare function getKeybindings(): KeybindingsManager;
193
+ //# sourceMappingURL=keybindings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keybindings.d.ts","sourceRoot":"","sources":["../src/keybindings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAc,MAAM,WAAW,CAAC;AAEnD;;;GAGG;AACH,MAAM,WAAW,WAAW;IAE3B,qBAAqB,EAAE,IAAI,CAAC;IAC5B,uBAAuB,EAAE,IAAI,CAAC;IAC9B,uBAAuB,EAAE,IAAI,CAAC;IAC9B,wBAAwB,EAAE,IAAI,CAAC;IAC/B,2BAA2B,EAAE,IAAI,CAAC;IAClC,4BAA4B,EAAE,IAAI,CAAC;IACnC,4BAA4B,EAAE,IAAI,CAAC;IACnC,0BAA0B,EAAE,IAAI,CAAC;IACjC,wBAAwB,EAAE,IAAI,CAAC;IAC/B,yBAAyB,EAAE,IAAI,CAAC;IAChC,mBAAmB,EAAE,IAAI,CAAC;IAC1B,qBAAqB,EAAE,IAAI,CAAC;IAC5B,+BAA+B,EAAE,IAAI,CAAC;IACtC,8BAA8B,EAAE,IAAI,CAAC;IACrC,+BAA+B,EAAE,IAAI,CAAC;IACtC,8BAA8B,EAAE,IAAI,CAAC;IACrC,8BAA8B,EAAE,IAAI,CAAC;IACrC,4BAA4B,EAAE,IAAI,CAAC;IACnC,iBAAiB,EAAE,IAAI,CAAC;IACxB,oBAAoB,EAAE,IAAI,CAAC;IAC3B,iBAAiB,EAAE,IAAI,CAAC;IAExB,mBAAmB,EAAE,IAAI,CAAC;IAC1B,kBAAkB,EAAE,IAAI,CAAC;IACzB,eAAe,EAAE,IAAI,CAAC;IACtB,gBAAgB,EAAE,IAAI,CAAC;IAEvB,eAAe,EAAE,IAAI,CAAC;IACtB,iBAAiB,EAAE,IAAI,CAAC;IACxB,mBAAmB,EAAE,IAAI,CAAC;IAC1B,qBAAqB,EAAE,IAAI,CAAC;IAC5B,oB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AAO,CAAC,UAAU,EAAE,UAAU,GAAG,KAAK,EAAE,CAEvC;IAED,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,oBAAoB,CAE1D;IAED,YAAY,IAAI,kBAAkB,EAAE,CAEnC;IAED,eAAe,CAAC,YAAY,EAAE,iBAAiB,GAAG,IAAI,CAGrD;IAED,eAAe,IAAI,iBAAiB,CAEnC;IAED,mBAAmB,IAAI,iBAAiB,CAOvC;CACD;AAID,wBAAgB,cAAc,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI,CAEpE;AAED,wBAAgB,cAAc,IAAI,kBAAkB,CAKnD"}
@@ -0,0 +1,172 @@
1
+ import { matchesKey } from "./keys.js";
2
+ export const TUI_KEYBINDINGS = {
3
+ "tui.editor.cursorUp": { defaultKeys: "up", description: "Move cursor up" },
4
+ "tui.editor.cursorDown": { defaultKeys: "down", description: "Move cursor down" },
5
+ "tui.editor.cursorLeft": {
6
+ defaultKeys: ["left", "ctrl+b"],
7
+ description: "Move cursor left",
8
+ },
9
+ "tui.editor.cursorRight": {
10
+ defaultKeys: ["right", "ctrl+f"],
11
+ description: "Move cursor right",
12
+ },
13
+ "tui.editor.cursorWordLeft": {
14
+ defaultKeys: ["alt+left", "ctrl+left", "alt+b"],
15
+ description: "Move cursor word left",
16
+ },
17
+ "tui.editor.cursorWordRight": {
18
+ defaultKeys: ["alt+right", "ctrl+right", "alt+f"],
19
+ description: "Move cursor word right",
20
+ },
21
+ "tui.editor.cursorLineStart": {
22
+ defaultKeys: ["home", "ctrl+a"],
23
+ description: "Move to line start",
24
+ },
25
+ "tui.editor.cursorLineEnd": {
26
+ defaultKeys: ["end", "ctrl+e"],
27
+ description: "Move to line end",
28
+ },
29
+ "tui.editor.jumpForward": {
30
+ defaultKeys: "ctrl+]",
31
+ description: "Jump forward to character",
32
+ },
33
+ "tui.editor.jumpBackward": {
34
+ defaultKeys: "ctrl+alt+]",
35
+ description: "Jump backward to character",
36
+ },
37
+ "tui.editor.pageUp": { defaultKeys: "pageUp", description: "Page up" },
38
+ "tui.editor.pageDown": { defaultKeys: "pageDown", description: "Page down" },
39
+ "tui.editor.deleteCharBackward": {
40
+ defaultKeys: "backspace",
41
+ description: "Delete character backward",
42
+ },
43
+ "tui.editor.deleteCharForward": {
44
+ defaultKeys: ["delete", "ctrl+d"],
45
+ description: "Delete character forward",
46
+ },
47
+ "tui.editor.deleteWordBackward": {
48
+ defaultKeys: ["ctrl+w", "alt+backspace"],
49
+ description: "Delete word backward",
50
+ },
51
+ "tui.editor.deleteWordForward": {
52
+ defaultKeys: ["alt+d", "alt+delete"],
53
+ description: "Delete word forward",
54
+ },
55
+ "tui.editor.deleteToLineStart": {
56
+ defaultKeys: "ctrl+u",
57
+ description: "Delete to line start",
58
+ },
59
+ "tui.editor.deleteToLineEnd": {
60
+ defaultKeys: "ctrl+k",
61
+ description: "Delete to line end",
62
+ },
63
+ "tui.editor.yank": { defaultKeys: "ctrl+y", description: "Yank" },
64
+ "tui.editor.yankPop": { defaultKeys: "alt+y", description: "Yank pop" },
65
+ "tui.editor.undo": { defaultKeys: "ctrl+-", description: "Undo" },
66
+ "tui.input.newLine": { defaultKeys: ["shift+enter", "ctrl+j"], description: "Insert newline" },
67
+ "tui.input.submit": { defaultKeys: "enter", description: "Submit input" },
68
+ "tui.input.tab": { defaultKeys: "tab", description: "Tab / autocomplete" },
69
+ "tui.input.copy": { defaultKeys: "ctrl+c", description: "Copy selection" },
70
+ "tui.select.up": { defaultKeys: "up", description: "Move selection up" },
71
+ "tui.select.down": { defaultKeys: "down", description: "Move selection down" },
72
+ "tui.select.pageUp": { defaultKeys: "pageUp", description: "Selection page up" },
73
+ "tui.select.pageDown": {
74
+ defaultKeys: "pageDown",
75
+ description: "Selection page down",
76
+ },
77
+ "tui.select.confirm": { defaultKeys: "enter", description: "Confirm selection" },
78
+ "tui.select.cancel": {
79
+ defaultKeys: ["escape", "ctrl+c"],
80
+ description: "Cancel selection",
81
+ },
82
+ };
83
+ function normalizeKeys(keys) {
84
+ if (keys === undefined)
85
+ return [];
86
+ const keyList = Array.isArray(keys) ? keys : [keys];
87
+ const seen = new Set();
88
+ const result = [];
89
+ for (const key of keyList) {
90
+ if (!seen.has(key)) {
91
+ seen.add(key);
92
+ result.push(key);
93
+ }
94
+ }
95
+ return result;
96
+ }
97
+ export class KeybindingsManager {
98
+ constructor(definitions, userBindings = {}) {
99
+ this.keysById = new Map();
100
+ this.conflicts = [];
101
+ this.definitions = definitions;
102
+ this.userBindings = userBindings;
103
+ this.rebuild();
104
+ }
105
+ rebuild() {
106
+ this.keysById.clear();
107
+ this.conflicts = [];
108
+ const userClaims = new Map();
109
+ for (const [keybinding, keys] of Object.entries(this.userBindings)) {
110
+ if (!(keybinding in this.definitions))
111
+ continue;
112
+ for (const key of normalizeKeys(keys)) {
113
+ const claimants = userClaims.get(key) ?? new Set();
114
+ claimants.add(keybinding);
115
+ userClaims.set(key, claimants);
116
+ }
117
+ }
118
+ for (const [key, keybindings] of userClaims) {
119
+ if (keybindings.size > 1) {
120
+ this.conflicts.push({ key, keybindings: [...keybindings] });
121
+ }
122
+ }
123
+ for (const [id, definition] of Object.entries(this.definitions)) {
124
+ const userKeys = this.userBindings[id];
125
+ const keys = userKeys === undefined ? normalizeKeys(definition.defaultKeys) : normalizeKeys(userKeys);
126
+ this.keysById.set(id, keys);
127
+ }
128
+ }
129
+ matches(data, keybinding) {
130
+ const keys = this.keysById.get(keybinding) ?? [];
131
+ for (const key of keys) {
132
+ if (matchesKey(data, key))
133
+ return true;
134
+ }
135
+ return false;
136
+ }
137
+ getKeys(keybinding) {
138
+ return [...(this.keysById.get(keybinding) ?? [])];
139
+ }
140
+ getDefinition(keybinding) {
141
+ return this.definitions[keybinding];
142
+ }
143
+ getConflicts() {
144
+ return this.conflicts.map((conflict) => ({ ...conflict, keybindings: [...conflict.keybindings] }));
145
+ }
146
+ setUserBindings(userBindings) {
147
+ this.userBindings = userBindings;
148
+ this.rebuild();
149
+ }
150
+ getUserBindings() {
151
+ return { ...this.userBindings };
152
+ }
153
+ getResolvedBindings() {
154
+ const resolved = {};
155
+ for (const id of Object.keys(this.definitions)) {
156
+ const keys = this.keysById.get(id) ?? [];
157
+ resolved[id] = keys.length === 1 ? keys[0] : [...keys];
158
+ }
159
+ return resolved;
160
+ }
161
+ }
162
+ let globalKeybindings = null;
163
+ export function setKeybindings(keybindings) {
164
+ globalKeybindings = keybindings;
165
+ }
166
+ export function getKeybindings() {
167
+ if (!globalKeybindings) {
168
+ globalKeybindings = new KeybindingsManager(TUI_KEYBINDINGS);
169
+ }
170
+ return globalKeybindings;
171
+ }
172
+ //# 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;AAqDnD,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B,qBAAqB,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,gBAAgB,EAAE;IAC3E,uBAAuB,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE;IACjF,uBAAuB,EAAE;QACxB,WAAW,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;QAC/B,WAAW,EAAE,kBAAkB;KAC/B;IACD,wBAAwB,EAAE;QACzB,WAAW,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;QAChC,WAAW,EAAE,mBAAmB;KAChC;IACD,2BAA2B,EAAE;QAC5B,WAAW,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,OAAO,CAAC;QAC/C,WAAW,EAAE,uBAAuB;KACpC;IACD,4BAA4B,EAAE;QAC7B,WAAW,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,OAAO,CAAC;QACjD,WAAW,EAAE,wBAAwB;KACrC;IACD,4BAA4B,EAAE;QAC7B,WAAW,EAAE,CAAC,MAAM,EAAE,QAAQ,CAA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,CAAC,CAAC,CAAC;IACpG,CAAC;IAED,eAAe,CAAC,YAA+B;QAC9C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,OAAO,EAAE,CAAC;IAChB,CAAC;IAED,eAAe;QACd,OAAO,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;IACjC,CAAC;IAED,mBAAmB;QAClB,MAAM,QAAQ,GAAsB,EAAE,CAAC;QACvC,KAAK,MAAM,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YAChD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAgB,CAAC,IAAI,EAAE,CAAC;YACvD,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD;AAED,IAAI,iBAAiB,GAA8B,IAAI,CAAC;AAExD,MAAM,UAAU,cAAc,CAAC,WAA+B;IAC7D,iBAAiB,GAAG,WAAW,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,cAAc;IAC7B,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACxB,iBAAiB,GAAG,IAAI,kBAAkB,CAAC,eAAe,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC1B,CAAC","sourcesContent":["import { type KeyId, matchesKey } from \"./keys.ts\";\n\n/**\n * Global keybinding registry.\n * Downstream packages can add keybindings via declaration merging.\n */\nexport interface Keybindings {\n\t// Editor navigation and editing\n\t\"tui.editor.cursorUp\": true;\n\t\"tui.editor.cursorDown\": true;\n\t\"tui.editor.cursorLeft\": true;\n\t\"tui.editor.cursorRight\": true;\n\t\"tui.editor.cursorWordLeft\": true;\n\t\"tui.editor.cursorWordRight\": true;\n\t\"tui.editor.cursorLineStart\": true;\n\t\"tui.editor.cursorLineEnd\": true;\n\t\"tui.editor.jumpForward\": true;\n\t\"tui.editor.jumpBackward\": true;\n\t\"tui.editor.pageUp\": true;\n\t\"tui.editor.pageDown\": true;\n\t\"tui.editor.deleteCharBackward\": true;\n\t\"tui.editor.deleteCharForward\": true;\n\t\"tui.editor.deleteWordBackward\": true;\n\t\"tui.editor.deleteWordForward\": true;\n\t\"tui.editor.deleteToLineStart\": true;\n\t\"tui.editor.deleteToLineEnd\": true;\n\t\"tui.editor.yank\": true;\n\t\"tui.editor.yankPop\": true;\n\t\"tui.editor.undo\": true;\n\t// Generic input actions\n\t\"tui.input.newLine\": true;\n\t\"tui.input.submit\": true;\n\t\"tui.input.tab\": true;\n\t\"tui.input.copy\": true;\n\t// Generic selection actions\n\t\"tui.select.up\": true;\n\t\"tui.select.down\": true;\n\t\"tui.select.pageUp\": true;\n\t\"tui.select.pageDown\": true;\n\t\"tui.select.confirm\": true;\n\t\"tui.select.cancel\": true;\n}\n\nexport type Keybinding = keyof Keybindings;\n\nexport interface KeybindingDefinition {\n\tdefaultKeys: KeyId | KeyId[];\n\tdescription?: string;\n}\n\nexport type KeybindingDefinitions = Record<string, KeybindingDefinition>;\nexport type KeybindingsConfig = Record<string, KeyId | KeyId[] | undefined>;\n\nexport const TUI_KEYBINDINGS = {\n\t\"tui.editor.cursorUp\": { defaultKeys: \"up\", description: \"Move cursor up\" },\n\t\"tui.editor.cursorDown\": { defaultKeys: \"down\", description: \"Move cursor down\" },\n\t\"tui.editor.cursorLeft\": {\n\t\tdefaultKeys: [\"left\", \"ctrl+b\"],\n\t\tdescription: \"Move cursor left\",\n\t},\n\t\"tui.editor.cursorRight\": {\n\t\tdefaultKeys: [\"right\", \"ctrl+f\"],\n\t\tdescription: \"Move cursor right\",\n\t},\n\t\"tui.editor.cursorWordLeft\": {\n\t\tdefaultKeys: [\"alt+left\", \"ctrl+left\", \"alt+b\"],\n\t\tdescription: \"Move cursor word left\",\n\t},\n\t\"tui.editor.cursorWordRight\": {\n\t\tdefaultKeys: [\"alt+right\", \"ctrl+right\", \"alt+f\"],\n\t\tdescription: \"Move cursor word right\",\n\t},\n\t\"tui.editor.cursorLineStart\": {\n\t\tdefaultKeys: [\"home\", \"ctrl+a\"],\n\t\tdescription: \"Move to line start\",\n\t},\n\t\"tui.editor.cursorLineEnd\": {\n\t\tdefaultKeys: [\"end\", \"ctrl+e\"],\n\t\tdescription: \"Move to line end\",\n\t},\n\t\"tui.editor.jumpForward\": {\n\t\tdefaultKeys: \"ctrl+]\",\n\t\tdescription: \"Jump forward to character\",\n\t},\n\t\"tui.editor.jumpBackward\": {\n\t\tdefaultKeys: \"ctrl+alt+]\",\n\t\tdescription: \"Jump backward to character\",\n\t},\n\t\"tui.editor.pageUp\": { defaultKeys: \"pageUp\", description: \"Page up\" },\n\t\"tui.editor.pageDown\": { defaultKeys: \"pageDown\", description: \"Page down\" },\n\t\"tui.editor.deleteCharBackward\": {\n\t\tdefaultKeys: \"backspace\",\n\t\tdescription: \"Delete character backward\",\n\t},\n\t\"tui.editor.deleteCharForward\": {\n\t\tdefaultKeys: [\"delete\", \"ctrl+d\"],\n\t\tdescription: \"Delete character forward\",\n\t},\n\t\"tui.editor.deleteWordBackward\": {\n\t\tdefaultKeys: [\"ctrl+w\", \"alt+backspace\"],\n\t\tdescription: \"Delete word backward\",\n\t},\n\t\"tui.editor.deleteWordForward\": {\n\t\tdefaultKeys: [\"alt+d\", \"alt+delete\"],\n\t\tdescription: \"Delete word forward\",\n\t},\n\t\"tui.editor.deleteToLineStart\": {\n\t\tdefaultKeys: \"ctrl+u\",\n\t\tdescription: \"Delete to line start\",\n\t},\n\t\"tui.editor.deleteToLineEnd\": {\n\t\tdefaultKeys: \"ctrl+k\",\n\t\tdescription: \"Delete to line end\",\n\t},\n\t\"tui.editor.yank\": { defaultKeys: \"ctrl+y\", description: \"Yank\" },\n\t\"tui.editor.yankPop\": { defaultKeys: \"alt+y\", description: \"Yank pop\" },\n\t\"tui.editor.undo\": { defaultKeys: \"ctrl+-\", description: \"Undo\" },\n\t\"tui.input.newLine\": { defaultKeys: [\"shift+enter\", \"ctrl+j\"], description: \"Insert newline\" },\n\t\"tui.input.submit\": { defaultKeys: \"enter\", description: \"Submit input\" },\n\t\"tui.input.tab\": { defaultKeys: \"tab\", description: \"Tab / autocomplete\" },\n\t\"tui.input.copy\": { defaultKeys: \"ctrl+c\", description: \"Copy selection\" },\n\t\"tui.select.up\": { defaultKeys: \"up\", description: \"Move selection up\" },\n\t\"tui.select.down\": { defaultKeys: \"down\", description: \"Move selection down\" },\n\t\"tui.select.pageUp\": { defaultKeys: \"pageUp\", description: \"Selection page up\" },\n\t\"tui.select.pageDown\": {\n\t\tdefaultKeys: \"pageDown\",\n\t\tdescription: \"Selection page down\",\n\t},\n\t\"tui.select.confirm\": { defaultKeys: \"enter\", description: \"Confirm selection\" },\n\t\"tui.select.cancel\": {\n\t\tdefaultKeys: [\"escape\", \"ctrl+c\"],\n\t\tdescription: \"Cancel selection\",\n\t},\n} as const satisfies KeybindingDefinitions;\n\nexport interface KeybindingConflict {\n\tkey: KeyId;\n\tkeybindings: string[];\n}\n\nfunction normalizeKeys(keys: KeyId | KeyId[] | undefined): KeyId[] {\n\tif (keys === undefined) return [];\n\tconst keyList = Array.isArray(keys) ? keys : [keys];\n\tconst seen = new Set<KeyId>();\n\tconst result: KeyId[] = [];\n\tfor (const key of keyList) {\n\t\tif (!seen.has(key)) {\n\t\t\tseen.add(key);\n\t\t\tresult.push(key);\n\t\t}\n\t}\n\treturn result;\n}\n\nexport class KeybindingsManager {\n\tprivate definitions: KeybindingDefinitions;\n\tprivate userBindings: KeybindingsConfig;\n\tprivate keysById = new Map<Keybinding, KeyId[]>();\n\tprivate conflicts: KeybindingConflict[] = [];\n\n\tconstructor(definitions: KeybindingDefinitions, userBindings: KeybindingsConfig = {}) {\n\t\tthis.definitions = definitions;\n\t\tthis.userBindings = userBindings;\n\t\tthis.rebuild();\n\t}\n\n\tprivate rebuild(): void {\n\t\tthis.keysById.clear();\n\t\tthis.conflicts = [];\n\n\t\tconst userClaims = new Map<KeyId, Set<Keybinding>>();\n\t\tfor (const [keybinding, keys] of Object.entries(this.userBindings)) {\n\t\t\tif (!(keybinding in this.definitions)) continue;\n\t\t\tfor (const key of normalizeKeys(keys)) {\n\t\t\t\tconst claimants = userClaims.get(key) ?? new Set<Keybinding>();\n\t\t\t\tclaimants.add(keybinding as Keybinding);\n\t\t\t\tuserClaims.set(key, claimants);\n\t\t\t}\n\t\t}\n\n\t\tfor (const [key, keybindings] of userClaims) {\n\t\t\tif (keybindings.size > 1) {\n\t\t\t\tthis.conflicts.push({ key, keybindings: [...keybindings] });\n\t\t\t}\n\t\t}\n\n\t\tfor (const [id, definition] of Object.entries(this.definitions)) {\n\t\t\tconst userKeys = this.userBindings[id];\n\t\t\tconst keys = userKeys === undefined ? normalizeKeys(definition.defaultKeys) : normalizeKeys(userKeys);\n\t\t\tthis.keysById.set(id as Keybinding, keys);\n\t\t}\n\t}\n\n\tmatches(data: string, keybinding: Keybinding): boolean {\n\t\tconst keys = this.keysById.get(keybinding) ?? [];\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\tgetKeys(keybinding: Keybinding): KeyId[] {\n\t\treturn [...(this.keysById.get(keybinding) ?? [])];\n\t}\n\n\tgetDefinition(keybinding: Keybinding): KeybindingDefinition {\n\t\treturn this.definitions[keybinding];\n\t}\n\n\tgetConflicts(): KeybindingConflict[] {\n\t\treturn this.conflicts.map((conflict) => ({ ...conflict, keybindings: [...conflict.keybindings] }));\n\t}\n\n\tsetUserBindings(userBindings: KeybindingsConfig): void {\n\t\tthis.userBindings = userBindings;\n\t\tthis.rebuild();\n\t}\n\n\tgetUserBindings(): KeybindingsConfig {\n\t\treturn { ...this.userBindings };\n\t}\n\n\tgetResolvedBindings(): KeybindingsConfig {\n\t\tconst resolved: KeybindingsConfig = {};\n\t\tfor (const id of Object.keys(this.definitions)) {\n\t\t\tconst keys = this.keysById.get(id as Keybinding) ?? [];\n\t\t\tresolved[id] = keys.length === 1 ? keys[0]! : [...keys];\n\t\t}\n\t\treturn resolved;\n\t}\n}\n\nlet globalKeybindings: KeybindingsManager | null = null;\n\nexport function setKeybindings(keybindings: KeybindingsManager): void {\n\tglobalKeybindings = keybindings;\n}\n\nexport function getKeybindings(): KeybindingsManager {\n\tif (!globalKeybindings) {\n\t\tglobalKeybindings = new KeybindingsManager(TUI_KEYBINDINGS);\n\t}\n\treturn globalKeybindings;\n}\n"]}
package/dist/keys.d.ts ADDED
@@ -0,0 +1,184 @@
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 Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
31
+ type SymbolKey = "`" | "-" | "=" | "[" | "]" | "\\" | ";" | "'" | "," | "." | "/" | "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "_" | "+" | "|" | "~" | "{" | "}" | ":" | "<" | ">" | "?";
32
+ 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";
33
+ type BaseKey = Letter | Digit | SymbolKey | SpecialKey;
34
+ type ModifierName = "ctrl" | "shift" | "alt" | "super";
35
+ type ModifiedKeyId<Key extends string, RemainingModifiers extends ModifierName = ModifierName> = {
36
+ [M in RemainingModifiers]: `${M}+${Key}` | `${M}+${ModifiedKeyId<Key, Exclude<RemainingModifiers, M>>}`;
37
+ }[RemainingModifiers];
38
+ /**
39
+ * Union type of all valid key identifiers.
40
+ * Provides autocomplete and catches typos at compile time.
41
+ */
42
+ export type KeyId = BaseKey | ModifiedKeyId<BaseKey>;
43
+ /**
44
+ * Helper object for creating typed key identifiers with autocomplete.
45
+ *
46
+ * Usage:
47
+ * - Key.escape, Key.enter, Key.tab, etc. for special keys
48
+ * - Key.backtick, Key.comma, Key.period, etc. for symbol keys
49
+ * - Key.ctrl("c"), Key.alt("x"), Key.super("k") for single modifiers
50
+ * - Key.ctrlShift("p"), Key.ctrlAlt("x"), Key.ctrlSuper("k") for combined modifiers
51
+ */
52
+ export declare const Key: {
53
+ readonly escape: "escape";
54
+ readonly esc: "esc";
55
+ readonly enter: "enter";
56
+ readonly return: "return";
57
+ readonly tab: "tab";
58
+ readonly space: "space";
59
+ readonly backspace: "backspace";
60
+ readonly delete: "delete";
61
+ readonly insert: "insert";
62
+ readonly clear: "clear";
63
+ readonly home: "home";
64
+ readonly end: "end";
65
+ readonly pageUp: "pageUp";
66
+ readonly pageDown: "pageDown";
67
+ readonly up: "up";
68
+ readonly down: "down";
69
+ readonly left: "left";
70
+ readonly right: "right";
71
+ readonly f1: "f1";
72
+ readonly f2: "f2";
73
+ readonly f3: "f3";
74
+ readonly f4: "f4";
75
+ readonly f5: "f5";
76
+ readonly f6: "f6";
77
+ readonly f7: "f7";
78
+ readonly f8: "f8";
79
+ readonly f9: "f9";
80
+ readonly f10: "f10";
81
+ readonly f11: "f11";
82
+ readonly f12: "f12";
83
+ readonly backtick: "`";
84
+ readonly hyphen: "-";
85
+ readonly equals: "=";
86
+ readonly leftbracket: "[";
87
+ readonly rightbracket: "]";
88
+ readonly backslash: "\\";
89
+ readonly semicolon: ";";
90
+ readonly quote: "'";
91
+ readonly comma: ",";
92
+ readonly period: ".";
93
+ readonly slash: "/";
94
+ readonly exclamation: "!";
95
+ readonly at: "@";
96
+ readonly hash: "#";
97
+ readonly dollar: "$";
98
+ readonly percent: "%";
99
+ readonly caret: "^";
100
+ readonly ampersand: "&";
101
+ readonly asterisk: "*";
102
+ readonly leftparen: "(";
103
+ readonly rightparen: ")";
104
+ readonly underscore: "_";
105
+ readonly plus: "+";
106
+ readonly pipe: "|";
107
+ readonly tilde: "~";
108
+ readonly leftbrace: "{";
109
+ readonly rightbrace: "}";
110
+ readonly colon: ":";
111
+ readonly lessthan: "<";
112
+ readonly greaterthan: ">";
113
+ readonly question: "?";
114
+ readonly ctrl: <K extends BaseKey>(key: K) => `ctrl+${K}`;
115
+ readonly shift: <K extends BaseKey>(key: K) => `shift+${K}`;
116
+ readonly alt: <K extends BaseKey>(key: K) => `alt+${K}`;
117
+ readonly super: <K extends BaseKey>(key: K) => `super+${K}`;
118
+ readonly ctrlShift: <K extends BaseKey>(key: K) => `ctrl+shift+${K}`;
119
+ readonly shiftCtrl: <K extends BaseKey>(key: K) => `shift+ctrl+${K}`;
120
+ readonly ctrlAlt: <K extends BaseKey>(key: K) => `ctrl+alt+${K}`;
121
+ readonly altCtrl: <K extends BaseKey>(key: K) => `alt+ctrl+${K}`;
122
+ readonly shiftAlt: <K extends BaseKey>(key: K) => `shift+alt+${K}`;
123
+ readonly altShift: <K extends BaseKey>(key: K) => `alt+shift+${K}`;
124
+ readonly ctrlSuper: <K extends BaseKey>(key: K) => `ctrl+super+${K}`;
125
+ readonly superCtrl: <K extends BaseKey>(key: K) => `super+ctrl+${K}`;
126
+ readonly shiftSuper: <K extends BaseKey>(key: K) => `shift+super+${K}`;
127
+ readonly superShift: <K extends BaseKey>(key: K) => `super+shift+${K}`;
128
+ readonly altSuper: <K extends BaseKey>(key: K) => `alt+super+${K}`;
129
+ readonly superAlt: <K extends BaseKey>(key: K) => `super+alt+${K}`;
130
+ readonly ctrlShiftAlt: <K extends BaseKey>(key: K) => `ctrl+shift+alt+${K}`;
131
+ readonly ctrlShiftSuper: <K extends BaseKey>(key: K) => `ctrl+shift+super+${K}`;
132
+ };
133
+ /**
134
+ * Event types from Kitty keyboard protocol (flag 2)
135
+ * 1 = key press, 2 = key repeat, 3 = key release
136
+ */
137
+ export type KeyEventType = "press" | "repeat" | "release";
138
+ /**
139
+ * Check if the last parsed key event was a key release.
140
+ * Only meaningful when Kitty keyboard protocol with flag 2 is active.
141
+ */
142
+ export declare function isKeyRelease(data: string): boolean;
143
+ /**
144
+ * Check if the last parsed key event was a key repeat.
145
+ * Only meaningful when Kitty keyboard protocol with flag 2 is active.
146
+ */
147
+ export declare function isKeyRepeat(data: string): boolean;
148
+ /**
149
+ * Match input data against a key identifier string.
150
+ *
151
+ * Supported key identifiers:
152
+ * - Single keys: "escape", "tab", "enter", "backspace", "delete", "home", "end", "space"
153
+ * - Arrow keys: "up", "down", "left", "right"
154
+ * - Ctrl combinations: "ctrl+c", "ctrl+z", etc.
155
+ * - Shift combinations: "shift+tab", "shift+enter"
156
+ * - Alt combinations: "alt+enter", "alt+backspace"
157
+ * - Super combinations: "super+k", "super+enter"
158
+ * - Combined modifiers: "shift+ctrl+p", "ctrl+alt+x", "ctrl+super+k"
159
+ *
160
+ * Use the Key helper for autocomplete: Key.ctrl("c"), Key.escape, Key.ctrlShift("p"), Key.super("k")
161
+ *
162
+ * @param data - Raw input data from terminal
163
+ * @param keyId - Key identifier (e.g., "ctrl+c", "escape", Key.ctrl("c"))
164
+ */
165
+ export declare function matchesKey(data: string, keyId: KeyId): boolean;
166
+ export declare function parseKey(data: string): string | undefined;
167
+ /**
168
+ * Decode a Kitty CSI-u sequence into a printable character, if applicable.
169
+ *
170
+ * When Kitty keyboard protocol flag 1 (disambiguate) is active, terminals send
171
+ * CSI-u sequences for all keys, including plain printable characters. This
172
+ * function extracts the printable character from such sequences.
173
+ *
174
+ * Only accepts plain or Shift-modified keys. Rejects Ctrl, Alt, and unsupported
175
+ * modifier combinations (those are handled by keybinding matching instead).
176
+ * Prefers the shifted keycode when Shift is held and a shifted key is reported.
177
+ *
178
+ * @param data - Raw input data from terminal
179
+ * @returns The printable character, or undefined if not a printable CSI-u sequence
180
+ */
181
+ export declare function decodeKittyPrintable(data: string): string | undefined;
182
+ export declare function decodePrintableKey(data: string): string | undefined;
183
+ export {};
184
+ //# 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,GAC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