@sunub/obsidian-mcp-server 0.3.6 → 0.3.9

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 (334) hide show
  1. package/build/config.d.ts +1 -27
  2. package/build/config.js +4 -31
  3. package/build/config.js.map +1 -1
  4. package/build/db.js +3 -0
  5. package/build/db.js.map +1 -1
  6. package/build/index.js +3 -0
  7. package/build/index.js.map +1 -1
  8. package/build/server.js +1 -1
  9. package/build/server.js.map +1 -1
  10. package/build/setup.d.ts +1 -0
  11. package/build/setup.js +4 -2
  12. package/build/setup.js.map +1 -1
  13. package/build/tools/create_document_with_properties/index.d.ts +5 -5
  14. package/build/tools/create_document_with_properties/index.js +2 -2
  15. package/build/tools/create_document_with_properties/index.js.map +1 -1
  16. package/build/tools/create_document_with_properties/params.d.ts +8 -8
  17. package/build/tools/create_document_with_properties/params.js +1 -1
  18. package/build/tools/create_document_with_properties/params.js.map +1 -1
  19. package/build/tools/generate_property/index.d.ts +1 -1
  20. package/build/tools/generate_property/index.js +1 -1
  21. package/build/tools/generate_property/index.js.map +1 -1
  22. package/build/tools/generate_property/params.d.ts +4 -4
  23. package/build/tools/index.d.ts +8 -8
  24. package/build/tools/index.js +5 -5
  25. package/build/tools/index.js.map +1 -1
  26. package/build/tools/organize_attachments/index.d.ts +1 -1
  27. package/build/tools/organize_attachments/index.js +2 -2
  28. package/build/tools/organize_attachments/index.js.map +1 -1
  29. package/build/tools/vault/index.d.ts +1 -1
  30. package/build/tools/vault/index.js +3 -3
  31. package/build/tools/vault/index.js.map +1 -1
  32. package/build/tools/vault/params.d.ts +2 -2
  33. package/build/tools/vault/types/collect_context.d.ts +32 -32
  34. package/build/tools/vault/types/collect_context.js +1 -1
  35. package/build/tools/vault/types/collect_context.js.map +1 -1
  36. package/build/tools/vault/types/list_all.d.ts +12 -12
  37. package/build/tools/vault/types/list_all.js +2 -2
  38. package/build/tools/vault/types/list_all.js.map +1 -1
  39. package/build/tools/vault/types/read_specific.d.ts +6 -6
  40. package/build/tools/vault/types/read_specific.js +1 -1
  41. package/build/tools/vault/types/read_specific.js.map +1 -1
  42. package/build/tools/vault/types/search.d.ts +10 -10
  43. package/build/tools/vault/utils/actions/collect_context.d.ts +1 -1
  44. package/build/tools/vault/utils/actions/collect_context.js +4 -4
  45. package/build/tools/vault/utils/actions/collect_context.js.map +1 -1
  46. package/build/tools/vault/utils/actions/list_all.d.ts +1 -1
  47. package/build/tools/vault/utils/actions/list_all.js +1 -1
  48. package/build/tools/vault/utils/actions/list_all.js.map +1 -1
  49. package/build/tools/vault/utils/actions/load_memory.d.ts +1 -1
  50. package/build/tools/vault/utils/actions/load_memory.js +3 -3
  51. package/build/tools/vault/utils/actions/load_memory.js.map +1 -1
  52. package/build/tools/vault/utils/actions/read.d.ts +1 -1
  53. package/build/tools/vault/utils/actions/read.js +1 -1
  54. package/build/tools/vault/utils/actions/read.js.map +1 -1
  55. package/build/tools/vault/utils/actions/search.d.ts +1 -1
  56. package/build/tools/vault/utils/actions/search.js +2 -2
  57. package/build/tools/vault/utils/actions/search.js.map +1 -1
  58. package/build/tools/vault/utils/shared.d.ts +1 -1
  59. package/build/tools/vault/utils.d.ts +7 -7
  60. package/build/tools/vault/utils.js +7 -7
  61. package/build/tools/vault/utils.js.map +1 -1
  62. package/build/tools/write_property/index.d.ts +5 -5
  63. package/build/tools/write_property/index.js +1 -1
  64. package/build/tools/write_property/index.js.map +1 -1
  65. package/build/tools/write_property/params.d.ts +8 -8
  66. package/build/utils/DirectoryWalker.d.ts +1 -1
  67. package/build/utils/Embedder.js +1 -1
  68. package/build/utils/Embedder.js.map +1 -1
  69. package/build/utils/Indexer.d.ts +2 -2
  70. package/build/utils/Indexer.js +2 -2
  71. package/build/utils/Indexer.js.map +1 -1
  72. package/build/utils/LLMClient.js +16 -0
  73. package/build/utils/LLMClient.js.map +1 -1
  74. package/build/utils/LocalReranker.js +1 -1
  75. package/build/utils/LocalReranker.js.map +1 -1
  76. package/build/utils/RAGIndexer.d.ts +1 -1
  77. package/build/utils/RAGIndexer.js +6 -6
  78. package/build/utils/RAGIndexer.js.map +1 -1
  79. package/build/utils/RerankerClient.js +20 -1
  80. package/build/utils/RerankerClient.js.map +1 -1
  81. package/build/utils/VaultManger/VaultManager.d.ts +3 -3
  82. package/build/utils/VaultManger/VaultManager.js +9 -9
  83. package/build/utils/VaultManger/VaultManager.js.map +1 -1
  84. package/build/utils/VaultManger/index.d.ts +3 -3
  85. package/build/utils/VaultManger/index.js +2 -2
  86. package/build/utils/VaultManger/index.js.map +1 -1
  87. package/build/utils/VaultManger/types.d.ts +1 -1
  88. package/build/utils/VaultWatcher.js +1 -1
  89. package/build/utils/VaultWatcher.js.map +1 -1
  90. package/build/utils/VectorDB.js +31 -6
  91. package/build/utils/VectorDB.js.map +1 -1
  92. package/build/utils/getVaultManager.d.ts +1 -1
  93. package/build/utils/getVaultManager.js +1 -1
  94. package/build/utils/getVaultManager.js.map +1 -1
  95. package/build/utils/processor/MatterParser.d.ts +1 -1
  96. package/build/utils/processor/MatterParser.js +1 -1
  97. package/build/utils/processor/MatterParser.js.map +1 -1
  98. package/package.json +13 -49
  99. package/LICENSE +0 -15
  100. package/README.md +0 -512
  101. package/build/cli/App.d.ts +0 -1
  102. package/build/cli/App.js +0 -194
  103. package/build/cli/App.js.map +0 -1
  104. package/build/cli/AppContainer.d.ts +0 -1
  105. package/build/cli/AppContainer.js +0 -18
  106. package/build/cli/AppContainer.js.map +0 -1
  107. package/build/cli/colors.d.ts +0 -15
  108. package/build/cli/colors.js +0 -15
  109. package/build/cli/colors.js.map +0 -1
  110. package/build/cli/commands/types.d.ts +0 -19
  111. package/build/cli/commands/types.js +0 -11
  112. package/build/cli/commands/types.js.map +0 -1
  113. package/build/cli/config/SettingContext.d.ts +0 -1
  114. package/build/cli/config/SettingContext.js +0 -2
  115. package/build/cli/config/SettingContext.js.map +0 -1
  116. package/build/cli/config/mcpServersConfig.d.ts +0 -30
  117. package/build/cli/config/mcpServersConfig.js +0 -119
  118. package/build/cli/config/mcpServersConfig.js.map +0 -1
  119. package/build/cli/config/settingSchema.d.ts +0 -180
  120. package/build/cli/config/settingSchema.js +0 -128
  121. package/build/cli/config/settingSchema.js.map +0 -1
  122. package/build/cli/constants.d.ts +0 -47
  123. package/build/cli/constants.js +0 -101
  124. package/build/cli/constants.js.map +0 -1
  125. package/build/cli/context/InputContext.d.ts +0 -12
  126. package/build/cli/context/InputContext.js +0 -10
  127. package/build/cli/context/InputContext.js.map +0 -1
  128. package/build/cli/context/KeypressContext.d.ts +0 -30
  129. package/build/cli/context/KeypressContext.js +0 -200
  130. package/build/cli/context/KeypressContext.js.map +0 -1
  131. package/build/cli/context/KeypressContext.util.d.ts +0 -7
  132. package/build/cli/context/KeypressContext.util.js +0 -476
  133. package/build/cli/context/KeypressContext.util.js.map +0 -1
  134. package/build/cli/hooks/useAtCompletion.d.ts +0 -12
  135. package/build/cli/hooks/useAtCompletion.js +0 -5
  136. package/build/cli/hooks/useAtCompletion.js.map +0 -1
  137. package/build/cli/hooks/useCommandCompletion.d.ts +0 -59
  138. package/build/cli/hooks/useCommandCompletion.js +0 -344
  139. package/build/cli/hooks/useCommandCompletion.js.map +0 -1
  140. package/build/cli/hooks/useCompletion.d.ts +0 -22
  141. package/build/cli/hooks/useCompletion.js +0 -84
  142. package/build/cli/hooks/useCompletion.js.map +0 -1
  143. package/build/cli/hooks/useDispatcher.d.ts +0 -6
  144. package/build/cli/hooks/useDispatcher.js +0 -286
  145. package/build/cli/hooks/useDispatcher.js.map +0 -1
  146. package/build/cli/hooks/useFocus.d.ts +0 -2
  147. package/build/cli/hooks/useFocus.js +0 -3
  148. package/build/cli/hooks/useFocus.js.map +0 -1
  149. package/build/cli/hooks/useInputHistory.d.ts +0 -24
  150. package/build/cli/hooks/useInputHistory.js +0 -159
  151. package/build/cli/hooks/useInputHistory.js.map +0 -1
  152. package/build/cli/hooks/useKeyMatchers.d.ts +0 -17
  153. package/build/cli/hooks/useKeyMatchers.js +0 -13
  154. package/build/cli/hooks/useKeyMatchers.js.map +0 -1
  155. package/build/cli/hooks/useKeypress.d.ts +0 -19
  156. package/build/cli/hooks/useKeypress.js +0 -28
  157. package/build/cli/hooks/useKeypress.js.map +0 -1
  158. package/build/cli/hooks/useLlmStream/constants.d.ts +0 -4
  159. package/build/cli/hooks/useLlmStream/constants.js +0 -5
  160. package/build/cli/hooks/useLlmStream/constants.js.map +0 -1
  161. package/build/cli/hooks/useLlmStream/index.d.ts +0 -2
  162. package/build/cli/hooks/useLlmStream/index.js +0 -2
  163. package/build/cli/hooks/useLlmStream/index.js.map +0 -1
  164. package/build/cli/hooks/useLlmStream/llmService.d.ts +0 -2
  165. package/build/cli/hooks/useLlmStream/llmService.js +0 -110
  166. package/build/cli/hooks/useLlmStream/llmService.js.map +0 -1
  167. package/build/cli/hooks/useLlmStream/types.d.ts +0 -38
  168. package/build/cli/hooks/useLlmStream/types.js +0 -2
  169. package/build/cli/hooks/useLlmStream/types.js.map +0 -1
  170. package/build/cli/hooks/useLlmStream/useLlmStream.d.ts +0 -12
  171. package/build/cli/hooks/useLlmStream/useLlmStream.js +0 -162
  172. package/build/cli/hooks/useLlmStream/useLlmStream.js.map +0 -1
  173. package/build/cli/hooks/useLlmStream/utils.d.ts +0 -15
  174. package/build/cli/hooks/useLlmStream/utils.js +0 -108
  175. package/build/cli/hooks/useLlmStream/utils.js.map +0 -1
  176. package/build/cli/hooks/useMcpClient.d.ts +0 -10
  177. package/build/cli/hooks/useMcpClient.js +0 -100
  178. package/build/cli/hooks/useMcpClient.js.map +0 -1
  179. package/build/cli/hooks/useMcpManager.d.ts +0 -26
  180. package/build/cli/hooks/useMcpManager.js +0 -89
  181. package/build/cli/hooks/useMcpManager.js.map +0 -1
  182. package/build/cli/hooks/usePromptCompletion.d.ts +0 -19
  183. package/build/cli/hooks/usePromptCompletion.js +0 -13
  184. package/build/cli/hooks/usePromptCompletion.js.map +0 -1
  185. package/build/cli/hooks/useRagContext.d.ts +0 -6
  186. package/build/cli/hooks/useRagContext.js +0 -83
  187. package/build/cli/hooks/useRagContext.js.map +0 -1
  188. package/build/cli/hooks/useShellCompletion.d.ts +0 -18
  189. package/build/cli/hooks/useShellCompletion.js +0 -10
  190. package/build/cli/hooks/useShellCompletion.js.map +0 -1
  191. package/build/cli/hooks/useSlashCompletion.d.ts +0 -21
  192. package/build/cli/hooks/useSlashCompletion.js +0 -11
  193. package/build/cli/hooks/useSlashCompletion.js.map +0 -1
  194. package/build/cli/hooks/useTerminalSize.d.ts +0 -4
  195. package/build/cli/hooks/useTerminalSize.js +0 -21
  196. package/build/cli/hooks/useTerminalSize.js.map +0 -1
  197. package/build/cli/index.d.ts +0 -1
  198. package/build/cli/index.js +0 -10
  199. package/build/cli/index.js.map +0 -1
  200. package/build/cli/key/input.d.ts +0 -5
  201. package/build/cli/key/input.js +0 -9
  202. package/build/cli/key/input.js.map +0 -1
  203. package/build/cli/key/keyBindings.d.ts +0 -152
  204. package/build/cli/key/keyBindings.js +0 -630
  205. package/build/cli/key/keyBindings.js.map +0 -1
  206. package/build/cli/key/keyMatchers.d.ts +0 -19
  207. package/build/cli/key/keyMatchers.js +0 -25
  208. package/build/cli/key/keyMatchers.js.map +0 -1
  209. package/build/cli/key/mouse.d.ts +0 -23
  210. package/build/cli/key/mouse.js +0 -155
  211. package/build/cli/key/mouse.js.map +0 -1
  212. package/build/cli/key/text-buffer-bestcase.d.ts +0 -867
  213. package/build/cli/key/text-buffer-bestcase.js +0 -2754
  214. package/build/cli/key/text-buffer-bestcase.js.map +0 -1
  215. package/build/cli/key/text-buffer.d.ts +0 -506
  216. package/build/cli/key/text-buffer.js +0 -919
  217. package/build/cli/key/text-buffer.js.map +0 -1
  218. package/build/cli/main.d.ts +0 -1
  219. package/build/cli/main.js +0 -20
  220. package/build/cli/main.js.map +0 -1
  221. package/build/cli/reference/HistoryItemDisplay.d.ts +0 -23
  222. package/build/cli/reference/HistoryItemDisplay.js +0 -63
  223. package/build/cli/reference/HistoryItemDisplay.js.map +0 -1
  224. package/build/cli/reference/InputContext.d.ts +0 -17
  225. package/build/cli/reference/InputContext.js +0 -16
  226. package/build/cli/reference/InputContext.js.map +0 -1
  227. package/build/cli/reference/KerypressContext.d.ts +0 -37
  228. package/build/cli/reference/KerypressContext.js +0 -791
  229. package/build/cli/reference/KerypressContext.js.map +0 -1
  230. package/build/cli/reference/MainContent.d.ts +0 -6
  231. package/build/cli/reference/MainContent.js +0 -207
  232. package/build/cli/reference/MainContent.js.map +0 -1
  233. package/build/cli/reference/UIStateContext.d.ts +0 -188
  234. package/build/cli/reference/UIStateContext.js +0 -16
  235. package/build/cli/reference/UIStateContext.js.map +0 -1
  236. package/build/cli/reference/text-buffer.d.ts +0 -867
  237. package/build/cli/reference/text-buffer.js +0 -2754
  238. package/build/cli/reference/text-buffer.js.map +0 -1
  239. package/build/cli/reference/useGeminiStream.d.ts +0 -42
  240. package/build/cli/reference/useGeminiStream.js +0 -1404
  241. package/build/cli/reference/useGeminiStream.js.map +0 -1
  242. package/build/cli/services/McpClientService.d.ts +0 -32
  243. package/build/cli/services/McpClientService.js +0 -123
  244. package/build/cli/services/McpClientService.js.map +0 -1
  245. package/build/cli/services/McpManager.d.ts +0 -28
  246. package/build/cli/services/McpManager.js +0 -146
  247. package/build/cli/services/McpManager.js.map +0 -1
  248. package/build/cli/theme/builtin/default-dark.d.ts +0 -7
  249. package/build/cli/theme/builtin/default-dark.js +0 -143
  250. package/build/cli/theme/builtin/default-dark.js.map +0 -1
  251. package/build/cli/theme/builtin/no-color.d.ts +0 -7
  252. package/build/cli/theme/builtin/no-color.js +0 -125
  253. package/build/cli/theme/builtin/no-color.js.map +0 -1
  254. package/build/cli/theme/builtin/tokyonight-dark.d.ts +0 -7
  255. package/build/cli/theme/builtin/tokyonight-dark.js +0 -146
  256. package/build/cli/theme/builtin/tokyonight-dark.js.map +0 -1
  257. package/build/cli/theme/semantic-colors.d.ts +0 -2
  258. package/build/cli/theme/semantic-colors.js +0 -19
  259. package/build/cli/theme/semantic-colors.js.map +0 -1
  260. package/build/cli/theme/semantic-tokens.d.ts +0 -42
  261. package/build/cli/theme/semantic-tokens.js +0 -77
  262. package/build/cli/theme/semantic-tokens.js.map +0 -1
  263. package/build/cli/theme/theme-manager.d.ts +0 -32
  264. package/build/cli/theme/theme-manager.js +0 -150
  265. package/build/cli/theme/theme-manager.js.map +0 -1
  266. package/build/cli/theme/theme.d.ts +0 -107
  267. package/build/cli/theme/theme.js +0 -333
  268. package/build/cli/theme/theme.js.map +0 -1
  269. package/build/cli/tmp.d.ts +0 -1
  270. package/build/cli/tmp.js +0 -27
  271. package/build/cli/tmp.js.map +0 -1
  272. package/build/cli/types.d.ts +0 -74
  273. package/build/cli/types.js +0 -8
  274. package/build/cli/types.js.map +0 -1
  275. package/build/cli/ui/ConnectionStatus.d.ts +0 -13
  276. package/build/cli/ui/ConnectionStatus.js +0 -24
  277. package/build/cli/ui/ConnectionStatus.js.map +0 -1
  278. package/build/cli/ui/HelpCommands.d.ts +0 -5
  279. package/build/cli/ui/HelpCommands.js +0 -11
  280. package/build/cli/ui/HelpCommands.js.map +0 -1
  281. package/build/cli/ui/HistoryItemDisplay.d.ts +0 -9
  282. package/build/cli/ui/HistoryItemDisplay.js +0 -38
  283. package/build/cli/ui/HistoryItemDisplay.js.map +0 -1
  284. package/build/cli/ui/InputPrompt-bestcase.d.ts +0 -63
  285. package/build/cli/ui/InputPrompt-bestcase.js +0 -1301
  286. package/build/cli/ui/InputPrompt-bestcase.js.map +0 -1
  287. package/build/cli/ui/InputPrompt.d.ts +0 -13
  288. package/build/cli/ui/InputPrompt.js +0 -145
  289. package/build/cli/ui/InputPrompt.js.map +0 -1
  290. package/build/cli/ui/InputPrompt.tmp.d.ts +0 -7
  291. package/build/cli/ui/InputPrompt.tmp.js +0 -215
  292. package/build/cli/ui/InputPrompt.tmp.js.map +0 -1
  293. package/build/cli/ui/LLMErrorComponent.d.ts +0 -6
  294. package/build/cli/ui/LLMErrorComponent.js +0 -14
  295. package/build/cli/ui/LLMErrorComponent.js.map +0 -1
  296. package/build/cli/ui/LLMHealthChecker.d.ts +0 -8
  297. package/build/cli/ui/LLMHealthChecker.js +0 -22
  298. package/build/cli/ui/LLMHealthChecker.js.map +0 -1
  299. package/build/cli/ui/MCPServers.d.ts +0 -11
  300. package/build/cli/ui/MCPServers.js +0 -18
  301. package/build/cli/ui/MCPServers.js.map +0 -1
  302. package/build/cli/ui/MainContent.d.ts +0 -10
  303. package/build/cli/ui/MainContent.js +0 -24
  304. package/build/cli/ui/MainContent.js.map +0 -1
  305. package/build/cli/ui/MouseContext.d.ts +0 -1
  306. package/build/cli/ui/MouseContext.js +0 -2
  307. package/build/cli/ui/MouseContext.js.map +0 -1
  308. package/build/cli/ui/SuggestionsDisplay.d.ts +0 -25
  309. package/build/cli/ui/SuggestionsDisplay.js +0 -45
  310. package/build/cli/ui/SuggestionsDisplay.js.map +0 -1
  311. package/build/cli/ui/ThinkingIndicator.d.ts +0 -2
  312. package/build/cli/ui/ThinkingIndicator.js +0 -16
  313. package/build/cli/ui/ThinkingIndicator.js.map +0 -1
  314. package/build/cli/ui/layout/DefaultAppLayout.d.ts +0 -2
  315. package/build/cli/ui/layout/DefaultAppLayout.js +0 -6
  316. package/build/cli/ui/layout/DefaultAppLayout.js.map +0 -1
  317. package/build/cli/ui/shared/ExpandableText.d.ts +0 -14
  318. package/build/cli/ui/shared/ExpandableText.js +0 -19
  319. package/build/cli/ui/shared/ExpandableText.js.map +0 -1
  320. package/build/cli/utils/cache.d.ts +0 -21
  321. package/build/cli/utils/cache.js +0 -56
  322. package/build/cli/utils/cache.js.map +0 -1
  323. package/build/cli/utils/commandUtils.d.ts +0 -11
  324. package/build/cli/utils/commandUtils.js +0 -16
  325. package/build/cli/utils/commandUtils.js.map +0 -1
  326. package/build/cli/utils/debugLogger.d.ts +0 -12
  327. package/build/cli/utils/debugLogger.js +0 -54
  328. package/build/cli/utils/debugLogger.js.map +0 -1
  329. package/build/cli/utils/historyStorage.d.ts +0 -13
  330. package/build/cli/utils/historyStorage.js +0 -64
  331. package/build/cli/utils/historyStorage.js.map +0 -1
  332. package/build/cli/utils/textUtil.d.ts +0 -68
  333. package/build/cli/utils/textUtil.js +0 -236
  334. package/build/cli/utils/textUtil.js.map +0 -1
@@ -1,791 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- // @ts-nocheck
3
- /**
4
- * @license
5
- * Copyright 2025 Google LLC
6
- * SPDX-License-Identifier: Apache-2.0
7
- */
8
- import { debugLogger } from "@google/gemini-cli-core";
9
- import { useStdin } from "ink";
10
- import { MultiMap } from "mnemonist";
11
- import { createContext, useCallback, useContext, useEffect, useMemo, useRef, } from "react";
12
- import { AppEvent, appEvents } from "../../utils/events.js";
13
- import { FOCUS_IN, FOCUS_OUT } from "../hooks/useFocus.js";
14
- import { ESC } from "../utils/input.js";
15
- import { parseMouseEvent } from "../utils/mouse.js";
16
- import { terminalCapabilityManager } from "../utils/terminalCapabilityManager.js";
17
- import { useSettingsStore } from "./SettingsContext.js";
18
- export const BACKSLASH_ENTER_TIMEOUT = 5;
19
- export const ESC_TIMEOUT = 50;
20
- export const PASTE_TIMEOUT = 30_000;
21
- export const FAST_RETURN_TIMEOUT = 30;
22
- export var KeypressPriority;
23
- (function (KeypressPriority) {
24
- KeypressPriority[KeypressPriority["Low"] = -100] = "Low";
25
- KeypressPriority[KeypressPriority["Normal"] = 0] = "Normal";
26
- KeypressPriority[KeypressPriority["High"] = 100] = "High";
27
- KeypressPriority[KeypressPriority["Critical"] = 200] = "Critical";
28
- })(KeypressPriority || (KeypressPriority = {}));
29
- // Parse the key itself
30
- const KEY_INFO_MAP = {
31
- "[200~": { name: "paste-start" },
32
- "[201~": { name: "paste-end" },
33
- "[[A": { name: "f1" },
34
- "[[B": { name: "f2" },
35
- "[[C": { name: "f3" },
36
- "[[D": { name: "f4" },
37
- "[[E": { name: "f5" },
38
- "[1~": { name: "home" },
39
- "[2~": { name: "insert" },
40
- "[3~": { name: "delete" },
41
- "[4~": { name: "end" },
42
- "[5~": { name: "pageup" },
43
- "[6~": { name: "pagedown" },
44
- "[7~": { name: "home" },
45
- "[8~": { name: "end" },
46
- "[11~": { name: "f1" },
47
- "[12~": { name: "f2" },
48
- "[13~": { name: "f3" },
49
- "[14~": { name: "f4" },
50
- "[15~": { name: "f5" },
51
- "[17~": { name: "f6" },
52
- "[18~": { name: "f7" },
53
- "[19~": { name: "f8" },
54
- "[20~": { name: "f9" },
55
- "[21~": { name: "f10" },
56
- "[23~": { name: "f11" },
57
- "[24~": { name: "f12" },
58
- "[25~": { name: "f13" },
59
- "[26~": { name: "f14" },
60
- "[28~": { name: "f15" },
61
- "[29~": { name: "f16" },
62
- "[31~": { name: "f17" },
63
- "[32~": { name: "f18" },
64
- "[33~": { name: "f19" },
65
- "[34~": { name: "f20" },
66
- "[A": { name: "up" },
67
- "[B": { name: "down" },
68
- "[C": { name: "right" },
69
- "[D": { name: "left" },
70
- "[E": { name: "clear" },
71
- "[F": { name: "end" },
72
- "[H": { name: "home" },
73
- "[P": { name: "f1" },
74
- "[Q": { name: "f2" },
75
- "[R": { name: "f3" },
76
- "[S": { name: "f4" },
77
- OA: { name: "up" },
78
- OB: { name: "down" },
79
- OC: { name: "right" },
80
- OD: { name: "left" },
81
- OE: { name: "clear" },
82
- OF: { name: "end" },
83
- OH: { name: "home" },
84
- OP: { name: "f1" },
85
- OQ: { name: "f2" },
86
- OR: { name: "f3" },
87
- OS: { name: "f4" },
88
- OZ: { name: "tab", shift: true }, // SS3 Shift+Tab variant for Windows terminals
89
- "[[5~": { name: "pageup" },
90
- "[[6~": { name: "pagedown" },
91
- "[a": { name: "up", shift: true },
92
- "[b": { name: "down", shift: true },
93
- "[c": { name: "right", shift: true },
94
- "[d": { name: "left", shift: true },
95
- "[e": { name: "clear", shift: true },
96
- "[2$": { name: "insert", shift: true },
97
- "[3$": { name: "delete", shift: true },
98
- "[5$": { name: "pageup", shift: true },
99
- "[6$": { name: "pagedown", shift: true },
100
- "[7$": { name: "home", shift: true },
101
- "[8$": { name: "end", shift: true },
102
- "[Z": { name: "tab", shift: true },
103
- Oa: { name: "up", ctrl: true },
104
- Ob: { name: "down", ctrl: true },
105
- Oc: { name: "right", ctrl: true },
106
- Od: { name: "left", ctrl: true },
107
- Oe: { name: "clear", ctrl: true },
108
- "[2^": { name: "insert", ctrl: true },
109
- "[3^": { name: "delete", ctrl: true },
110
- "[5^": { name: "pageup", ctrl: true },
111
- "[6^": { name: "pagedown", ctrl: true },
112
- "[7^": { name: "home", ctrl: true },
113
- "[8^": { name: "end", ctrl: true },
114
- };
115
- // Kitty Keyboard Protocol (CSI u) code mappings
116
- const KITTY_CODE_MAP = {
117
- 2: { name: "insert" },
118
- 3: { name: "delete" },
119
- 5: { name: "pageup" },
120
- 6: { name: "pagedown" },
121
- 9: { name: "tab" },
122
- 13: { name: "enter" },
123
- 14: { name: "up" },
124
- 15: { name: "down" },
125
- 16: { name: "right" },
126
- 17: { name: "left" },
127
- 27: { name: "escape" },
128
- 32: { name: "space", sequence: " " },
129
- 127: { name: "backspace" },
130
- 57358: { name: "capslock" },
131
- 57359: { name: "scrolllock" },
132
- 57360: { name: "numlock" },
133
- 57361: { name: "printscreen" },
134
- 57362: { name: "pausebreak" },
135
- 57409: { name: "numpad_decimal", sequence: "." },
136
- 57410: { name: "numpad_divide", sequence: "/" },
137
- 57411: { name: "numpad_multiply", sequence: "*" },
138
- 57412: { name: "numpad_subtract", sequence: "-" },
139
- 57413: { name: "numpad_add", sequence: "+" },
140
- 57414: { name: "enter" },
141
- 57416: { name: "numpad_separator", sequence: "," },
142
- // Function keys F13-F35, not standard, but supported by Kitty
143
- ...Object.fromEntries(Array.from({ length: 23 }, (_, i) => [302 + i, { name: `f${13 + i}` }])),
144
- // Numpad keys in Numeric Keypad Mode (CSI u codes 57399-57408)
145
- ...Object.fromEntries(Array.from({ length: 10 }, (_, i) => [
146
- 57399 + i,
147
- { name: `numpad${i}`, sequence: String(i) },
148
- ])),
149
- };
150
- // Numpad keys in Application Keypad Mode (SS3 sequences)
151
- const NUMPAD_MAP = {
152
- Oj: "*",
153
- Ok: "+",
154
- Om: "-",
155
- Oo: "/",
156
- Op: "0",
157
- Oq: "1",
158
- Or: "2",
159
- Os: "3",
160
- Ot: "4",
161
- Ou: "5",
162
- Ov: "6",
163
- Ow: "7",
164
- Ox: "8",
165
- Oy: "9",
166
- On: ".",
167
- };
168
- const kUTF16SurrogateThreshold = 0x10000; // 2 ** 16
169
- function charLengthAt(str, i) {
170
- if (str.length <= i) {
171
- // Pretend to move to the right. This is necessary to autocomplete while
172
- // moving to the right.
173
- return 1;
174
- }
175
- const code = str.codePointAt(i);
176
- return code !== undefined && code >= kUTF16SurrogateThreshold ? 2 : 1;
177
- }
178
- // Note: we do not convert alt+z, alt+shift+z, or alt+v here
179
- // because mac users have alternative hotkeys.
180
- const MAC_ALT_KEY_CHARACTER_MAP = {
181
- "\u222B": "b", // "∫" back one word
182
- "\u0192": "f", // "ƒ" forward one word
183
- "\u00B5": "m", // "µ" toggle markup view
184
- "\u03A9": "z", // "Ω" Option+z
185
- "\u00B8": "Z", // "¸" Option+Shift+z
186
- "\u2202": "d", // "∂" delete word forward
187
- };
188
- function nonKeyboardEventFilter(keypressHandler) {
189
- return (key) => {
190
- if (!parseMouseEvent(key.sequence) &&
191
- key.sequence !== FOCUS_IN &&
192
- key.sequence !== FOCUS_OUT) {
193
- keypressHandler(key);
194
- }
195
- };
196
- }
197
- /**
198
- * Converts return keys pressed quickly after insertable keys into a shift+return
199
- *
200
- * This is to accommodate older terminals that paste text without bracketing.
201
- */
202
- function bufferFastReturn(keypressHandler) {
203
- let lastKeyTime = 0;
204
- return (key) => {
205
- const now = Date.now();
206
- if (key.name === "enter" && now - lastKeyTime <= FAST_RETURN_TIMEOUT) {
207
- keypressHandler({
208
- ...key,
209
- name: "enter",
210
- shift: true, // to make it a newline, not a submission
211
- alt: false,
212
- ctrl: false,
213
- cmd: false,
214
- sequence: "\r",
215
- insertable: true,
216
- });
217
- }
218
- else {
219
- keypressHandler(key);
220
- }
221
- lastKeyTime = key.insertable ? now : 0;
222
- };
223
- }
224
- /**
225
- * Buffers "/" keys to see if they are followed return.
226
- * Will flush the buffer if no data is received for DRAG_COMPLETION_TIMEOUT_MS
227
- * or when a null key is received.
228
- */
229
- function bufferBackslashEnter(keypressHandler) {
230
- const bufferer = (function* () {
231
- while (true) {
232
- const key = yield;
233
- if (key == null) {
234
- continue;
235
- }
236
- else if (key.sequence !== "\\") {
237
- keypressHandler(key);
238
- continue;
239
- }
240
- const timeoutId = setTimeout(() => bufferer.next(null), BACKSLASH_ENTER_TIMEOUT);
241
- const nextKey = yield;
242
- clearTimeout(timeoutId);
243
- if (nextKey === null) {
244
- keypressHandler(key);
245
- }
246
- else if (nextKey.name === "enter") {
247
- keypressHandler({
248
- ...nextKey,
249
- shift: true,
250
- sequence: "\r", // Corrected escaping for newline
251
- });
252
- }
253
- else {
254
- keypressHandler(key);
255
- keypressHandler(nextKey);
256
- }
257
- }
258
- })();
259
- bufferer.next(); // prime the generator so it starts listening.
260
- return (key) => {
261
- bufferer.next(key);
262
- };
263
- }
264
- /**
265
- * Buffers paste events between paste-start and paste-end sequences.
266
- * Will flush the buffer if no data is received for PASTE_TIMEOUT ms or
267
- * when a null key is received.
268
- */
269
- function bufferPaste(keypressHandler) {
270
- const bufferer = (function* () {
271
- while (true) {
272
- let key = yield;
273
- if (key === null) {
274
- continue;
275
- }
276
- else if (key.name !== "paste-start") {
277
- keypressHandler(key);
278
- continue;
279
- }
280
- let buffer = "";
281
- while (true) {
282
- const timeoutId = setTimeout(() => bufferer.next(null), PASTE_TIMEOUT);
283
- key = yield;
284
- clearTimeout(timeoutId);
285
- if (key === null) {
286
- appEvents.emit(AppEvent.PasteTimeout);
287
- break;
288
- }
289
- if (key.name === "paste-end") {
290
- break;
291
- }
292
- buffer += key.sequence;
293
- }
294
- if (buffer.length > 0) {
295
- keypressHandler({
296
- name: "paste",
297
- shift: false,
298
- alt: false,
299
- ctrl: false,
300
- cmd: false,
301
- insertable: true,
302
- sequence: buffer,
303
- });
304
- }
305
- }
306
- })();
307
- bufferer.next(); // prime the generator so it starts listening.
308
- return (key) => {
309
- bufferer.next(key);
310
- };
311
- }
312
- /**
313
- * Turns raw data strings into keypress events sent to the provided handler.
314
- * Buffers escape sequences until a full sequence is received or
315
- * until a timeout occurs.
316
- */
317
- function createDataListener(keypressHandler) {
318
- const parser = emitKeys(keypressHandler);
319
- parser.next(); // prime the generator so it starts listening.
320
- let timeoutId;
321
- return (data) => {
322
- clearTimeout(timeoutId);
323
- for (const char of data) {
324
- parser.next(char);
325
- }
326
- if (data.length !== 0) {
327
- timeoutId = setTimeout(() => parser.next(""), ESC_TIMEOUT);
328
- }
329
- };
330
- }
331
- /**
332
- * Translates raw keypress characters into key events.
333
- * Buffers escape sequences until a full sequence is received or
334
- * until an empty string is sent to indicate a timeout.
335
- */
336
- function* emitKeys(keypressHandler) {
337
- const lang = process.env.LANG || "";
338
- const lcAll = process.env.LC_ALL || "";
339
- const isGreek = lang.startsWith("el") || lcAll.startsWith("el");
340
- while (true) {
341
- let ch = yield;
342
- let sequence = ch;
343
- let escaped = false;
344
- let name;
345
- let shift = false;
346
- let alt = false;
347
- let ctrl = false;
348
- let cmd = false;
349
- let code;
350
- let insertable = false;
351
- if (ch === ESC) {
352
- escaped = true;
353
- ch = yield;
354
- sequence += ch;
355
- if (ch === ESC) {
356
- ch = yield;
357
- sequence += ch;
358
- }
359
- }
360
- if (escaped && (ch === "O" || ch === "[" || ch === "]")) {
361
- // ANSI escape sequence
362
- code = ch;
363
- let modifier = 0;
364
- if (ch === "]") {
365
- // OSC sequence
366
- // ESC ] <params> ; <data> BEL
367
- // ESC ] <params> ; <data> ESC \
368
- let buffer = "";
369
- // Read until BEL, `ESC \`, or timeout (empty string)
370
- while (true) {
371
- const next = yield;
372
- if (next === "" || next === "\u0007") {
373
- break;
374
- }
375
- else if (next === ESC) {
376
- const afterEsc = yield;
377
- if (afterEsc === "" || afterEsc === "\\") {
378
- break;
379
- }
380
- buffer += next + afterEsc;
381
- continue;
382
- }
383
- buffer += next;
384
- }
385
- // Check for OSC 52 (Clipboard) response
386
- // Format: 52;c;<base64> or 52;p;<base64>
387
- const match = /^52;[cp];(.*)$/.exec(buffer);
388
- if (match) {
389
- try {
390
- const base64Data = match[1];
391
- const decoded = Buffer.from(base64Data, "base64").toString("utf-8");
392
- keypressHandler({
393
- name: "paste",
394
- shift: false,
395
- alt: false,
396
- ctrl: false,
397
- cmd: false,
398
- insertable: true,
399
- sequence: decoded,
400
- });
401
- }
402
- catch {
403
- debugLogger.log("Failed to decode OSC 52 clipboard data");
404
- }
405
- }
406
- continue; // resume main loop
407
- }
408
- else if (ch === "O") {
409
- // ESC O letter
410
- // ESC O modifier letter
411
- ch = yield;
412
- sequence += ch;
413
- if (ch >= "0" && ch <= "9") {
414
- modifier = parseInt(ch, 10) - 1;
415
- ch = yield;
416
- sequence += ch;
417
- }
418
- code += ch;
419
- }
420
- else if (ch === "[") {
421
- // ESC [ letter
422
- // ESC [ modifier letter
423
- // ESC [ [ modifier letter
424
- // ESC [ [ num char
425
- ch = yield;
426
- sequence += ch;
427
- if (ch === "[") {
428
- // \x1b[[A
429
- // ^--- escape codes might have a second bracket
430
- code += ch;
431
- ch = yield;
432
- sequence += ch;
433
- }
434
- /*
435
- * Here and later we try to buffer just enough data to get
436
- * a complete ascii sequence.
437
- *
438
- * We have basically two classes of ascii characters to process:
439
- *
440
- *
441
- * 1. `\x1b[24;5~` should be parsed as { code: '[24~', modifier: 5 }
442
- *
443
- * This particular example is featuring Ctrl+F12 in xterm.
444
- *
445
- * - `;5` part is optional, e.g. it could be `\x1b[24~`
446
- * - first part can contain one or two digits
447
- * - there is also special case when there can be 3 digits
448
- * but without modifier. They are the case of paste bracket mode
449
- *
450
- * So the generic regexp is like /^(?:\d\d?(;\d)?[~^$]|\d{3}~)$/
451
- *
452
- *
453
- * 2. `\x1b[1;5H` should be parsed as { code: '[H', modifier: 5 }
454
- *
455
- * This particular example is featuring Ctrl+Home in xterm.
456
- *
457
- * - `1;5` part is optional, e.g. it could be `\x1b[H`
458
- * - `1;` part is optional, e.g. it could be `\x1b[5H`
459
- *
460
- * So the generic regexp is like /^((\d;)?\d)?[A-Za-z]$/
461
- *
462
- */
463
- const cmdStart = sequence.length - 1;
464
- // collect as many digits as possible
465
- while (ch >= "0" && ch <= "9") {
466
- ch = yield;
467
- sequence += ch;
468
- }
469
- // skip modifier
470
- if (ch === ";") {
471
- while (ch === ";") {
472
- ch = yield;
473
- sequence += ch;
474
- // collect as many digits as possible
475
- while (ch >= "0" && ch <= "9") {
476
- ch = yield;
477
- sequence += ch;
478
- }
479
- }
480
- }
481
- else if (ch === "<") {
482
- // SGR mouse mode
483
- ch = yield;
484
- sequence += ch;
485
- // Don't skip on empty string here to avoid timeouts on slow events.
486
- while (ch === "" || ch === ";" || (ch >= "0" && ch <= "9")) {
487
- ch = yield;
488
- sequence += ch;
489
- }
490
- }
491
- else if (ch === "M") {
492
- // X11 mouse mode
493
- // three characters after 'M'
494
- ch = yield;
495
- sequence += ch;
496
- ch = yield;
497
- sequence += ch;
498
- ch = yield;
499
- sequence += ch;
500
- }
501
- /*
502
- * We buffered enough data, now trying to extract code
503
- * and modifier from it
504
- */
505
- const cmd = sequence.slice(cmdStart);
506
- let match;
507
- if ((match = /^(\d+)(?:;(\d+))?(?:;(\d+))?([~^$u])$/.exec(cmd))) {
508
- if (match[1] === "27" && match[3] && match[4] === "~") {
509
- // modifyOtherKeys format: CSI 27 ; modifier ; key ~
510
- // Treat as CSI u: key + 'u'
511
- code += `${match[3]}u`;
512
- modifier = parseInt(match[2] ?? "1", 10) - 1;
513
- }
514
- else {
515
- code += match[1] + match[4];
516
- // Defaults to '1' if no modifier exists, resulting in a 0 modifier value
517
- modifier = parseInt(match[2] ?? "1", 10) - 1;
518
- }
519
- }
520
- else if ((match = /^(\d+)?(?:;(\d+))?([A-Za-z])$/.exec(cmd))) {
521
- code += match[3];
522
- modifier = parseInt(match[2] ?? match[1] ?? "1", 10) - 1;
523
- }
524
- else {
525
- code += cmd;
526
- }
527
- }
528
- // Parse the key modifier
529
- shift = !!(modifier & 1);
530
- alt = !!(modifier & 2);
531
- ctrl = !!(modifier & 4);
532
- cmd = !!(modifier & 8);
533
- const keyInfo = KEY_INFO_MAP[code];
534
- if (keyInfo) {
535
- name = keyInfo.name;
536
- if (keyInfo.shift) {
537
- shift = true;
538
- }
539
- if (keyInfo.ctrl) {
540
- ctrl = true;
541
- }
542
- if (name === "space" && !ctrl && !cmd && !alt) {
543
- sequence = " ";
544
- insertable = true;
545
- }
546
- }
547
- else {
548
- const numpadChar = NUMPAD_MAP[code];
549
- if (numpadChar) {
550
- name = numpadChar;
551
- if (!ctrl && !cmd && !alt) {
552
- sequence = numpadChar;
553
- insertable = true;
554
- }
555
- }
556
- else {
557
- name = "undefined";
558
- if (code.endsWith("u") || code.endsWith("~")) {
559
- // CSI-u or tilde-coded functional keys: ESC [ <code> ; <mods> (u|~)
560
- const codeNumber = parseInt(code.slice(1, -1), 10);
561
- const mapped = KITTY_CODE_MAP[codeNumber];
562
- if (mapped) {
563
- name = mapped.name;
564
- if (mapped.sequence && !ctrl && !cmd && !alt) {
565
- sequence = mapped.sequence;
566
- insertable = true;
567
- }
568
- }
569
- else if (codeNumber >= 33 && // Printable characters start after space (32),
570
- codeNumber <= 0x10ffff && // Valid Unicode scalar values (excluding control characters)
571
- (codeNumber < 0xd800 || codeNumber > 0xdfff) // Exclude UTF-16 surrogate halves
572
- ) {
573
- // Valid printable Unicode scalar values (up to Unicode maximum)
574
- // Note: Kitty maps its special keys to the PUA (57344+), which are handled by KITTY_CODE_MAP above.
575
- const char = String.fromCodePoint(codeNumber);
576
- name = char.toLowerCase();
577
- if (char !== name) {
578
- shift = true;
579
- }
580
- if (!ctrl && !cmd && !alt) {
581
- sequence = char;
582
- insertable = true;
583
- }
584
- }
585
- }
586
- }
587
- }
588
- }
589
- else if (ch === "\r") {
590
- // carriage return
591
- name = "enter";
592
- alt = escaped;
593
- }
594
- else if (escaped && ch === "\n") {
595
- // Alt+Enter (linefeed), should be consistent with carriage return
596
- name = "enter";
597
- alt = escaped;
598
- }
599
- else if (ch === "\t") {
600
- // tab
601
- name = "tab";
602
- alt = escaped;
603
- }
604
- else if (ch === "\b") {
605
- // ctrl+h / ctrl+backspace (windows terminals send \x08 for ctrl+backspace)
606
- name = "backspace";
607
- // In Windows environments, \b is sent for Ctrl+Backspace (standard backspace is translated to \x7f).
608
- // We scope this to Windows/WT_SESSION to avoid breaking other unixes where \b is a plain backspace.
609
- if (typeof process !== "undefined" &&
610
- (process.env?.OS === "Windows_NT" || !!process.env?.WT_SESSION)) {
611
- ctrl = true;
612
- }
613
- alt = escaped;
614
- }
615
- else if (ch === "\x7f") {
616
- // backspace
617
- name = "backspace";
618
- alt = escaped;
619
- }
620
- else if (ch === ESC) {
621
- // escape key
622
- name = "escape";
623
- alt = escaped;
624
- }
625
- else if (ch === " ") {
626
- name = "space";
627
- alt = escaped;
628
- insertable = true;
629
- }
630
- else if (!escaped && ch <= "\x1a") {
631
- // ctrl+letter
632
- name = String.fromCharCode(ch.charCodeAt(0) + "a".charCodeAt(0) - 1);
633
- ctrl = true;
634
- }
635
- else if (/^[0-9A-Za-z]$/.exec(ch) !== null) {
636
- // Letter, number, shift+letter
637
- name = ch.toLowerCase();
638
- shift = /^[A-Z]$/.exec(ch) !== null;
639
- alt = escaped;
640
- insertable = true;
641
- }
642
- else if (MAC_ALT_KEY_CHARACTER_MAP[ch]) {
643
- // Note: we do this even if we are not on Mac, because mac users may
644
- // remotely connect to non-Mac systems.
645
- // We skip this mapping for Greek users to avoid blocking the Omega character.
646
- if (isGreek && ch === "\u03A9") {
647
- insertable = true;
648
- }
649
- else {
650
- const mapped = MAC_ALT_KEY_CHARACTER_MAP[ch];
651
- name = mapped.toLowerCase();
652
- shift = mapped !== name;
653
- alt = true;
654
- }
655
- }
656
- else if (sequence === `${ESC}${ESC}`) {
657
- // Double escape
658
- name = "escape";
659
- alt = false;
660
- // Emit first escape key here, then continue processing
661
- keypressHandler({
662
- name: "escape",
663
- shift,
664
- alt,
665
- ctrl,
666
- cmd,
667
- insertable: false,
668
- sequence: ESC,
669
- });
670
- }
671
- else if (escaped) {
672
- // Escape sequence timeout
673
- name = ch.length ? undefined : "escape";
674
- alt = ch.length > 0;
675
- }
676
- else {
677
- // Any other character is considered printable.
678
- name = ch.toLowerCase();
679
- if (ch !== name) {
680
- shift = true;
681
- }
682
- insertable = true;
683
- }
684
- if ((sequence.length !== 0 && (name !== undefined || escaped)) ||
685
- charLengthAt(sequence, 0) === sequence.length) {
686
- keypressHandler({
687
- name: name || "",
688
- shift,
689
- alt,
690
- ctrl,
691
- cmd,
692
- insertable,
693
- sequence,
694
- });
695
- }
696
- // Unrecognized or broken escape sequence, don't emit anything
697
- }
698
- }
699
- const KeypressContext = createContext(undefined);
700
- export function useKeypressContext() {
701
- const context = useContext(KeypressContext);
702
- if (!context) {
703
- throw new Error("useKeypressContext must be used within a KeypressProvider");
704
- }
705
- return context;
706
- }
707
- export function KeypressProvider({ children, config, }) {
708
- const { settings } = useSettingsStore();
709
- const debugKeystrokeLogging = settings.merged.general.debugKeystrokeLogging;
710
- const { stdin, setRawMode } = useStdin();
711
- const subscribersToPriority = useRef(new Map()).current;
712
- const subscribers = useRef(new MultiMap(Set)).current;
713
- const sortedPriorities = useRef([]);
714
- const subscribe = useCallback((handler, priority = KeypressPriority.Normal) => {
715
- const p = typeof priority === "boolean"
716
- ? priority
717
- ? KeypressPriority.High
718
- : KeypressPriority.Normal
719
- : priority;
720
- subscribersToPriority.set(handler, p);
721
- const hadPriority = subscribers.has(p);
722
- subscribers.set(p, handler);
723
- if (!hadPriority) {
724
- // Cache sorted priorities only when a new priority level is added
725
- sortedPriorities.current = Array.from(subscribers.keys()).sort((a, b) => b - a);
726
- }
727
- }, [subscribers, subscribersToPriority]);
728
- const unsubscribe = useCallback((handler) => {
729
- const p = subscribersToPriority.get(handler);
730
- if (p !== undefined) {
731
- subscribers.remove(p, handler);
732
- subscribersToPriority.delete(handler);
733
- if (!subscribers.has(p)) {
734
- // Cache sorted priorities only when a priority level is completely removed
735
- sortedPriorities.current = Array.from(subscribers.keys()).sort((a, b) => b - a);
736
- }
737
- }
738
- }, [subscribers, subscribersToPriority]);
739
- const broadcast = useCallback((key) => {
740
- if (debugKeystrokeLogging) {
741
- debugLogger.log("[DEBUG] Keystroke:", JSON.stringify(key));
742
- }
743
- // Use cached sorted priorities to avoid sorting on every keypress
744
- for (const p of sortedPriorities.current) {
745
- const set = subscribers.get(p);
746
- if (!set)
747
- continue;
748
- // Within a priority level, use stack behavior (last subscribed is first to handle)
749
- const handlers = Array.from(set).reverse();
750
- for (const handler of handlers) {
751
- if (handler(key) === true) {
752
- return;
753
- }
754
- }
755
- }
756
- }, [subscribers, debugKeystrokeLogging]);
757
- useEffect(() => {
758
- terminalCapabilityManager.enableSupportedModes();
759
- const wasRaw = stdin.isRaw;
760
- if (wasRaw === false) {
761
- setRawMode(true);
762
- }
763
- process.stdin.setEncoding("utf8"); // Make data events emit strings
764
- let processor = nonKeyboardEventFilter(broadcast);
765
- if (!terminalCapabilityManager.isKittyProtocolEnabled()) {
766
- processor = bufferFastReturn(processor);
767
- }
768
- processor = bufferBackslashEnter(processor);
769
- processor = bufferPaste(processor);
770
- let dataListener = createDataListener(processor);
771
- if (debugKeystrokeLogging) {
772
- const old = dataListener;
773
- dataListener = (data) => {
774
- if (data.length > 0) {
775
- debugLogger.log(`[DEBUG] Raw StdIn: ${JSON.stringify(data)}`);
776
- }
777
- old(data);
778
- };
779
- }
780
- stdin.on("data", dataListener);
781
- return () => {
782
- stdin.removeListener("data", dataListener);
783
- if (wasRaw === false) {
784
- setRawMode(false);
785
- }
786
- };
787
- }, [stdin, setRawMode, debugKeystrokeLogging, broadcast]);
788
- const contextValue = useMemo(() => ({ subscribe, unsubscribe }), [subscribe, unsubscribe]);
789
- return (_jsx(KeypressContext.Provider, { value: contextValue, children: children }));
790
- }
791
- //# sourceMappingURL=KerypressContext.js.map