@linxiraos/pi-tui 1.4.4 → 1.4.7

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 (363) hide show
  1. package/CHANGELOG.md +208 -207
  2. package/README.md +34 -34
  3. package/dist/types/app-keybindings.d.ts +20 -0
  4. package/dist/types/apps/session-picker.d.ts +5 -0
  5. package/dist/types/charts/chart-plan.d.ts +9 -7
  6. package/dist/types/chat/assistant-message.d.ts +15 -3
  7. package/dist/types/chat/bash-execution.d.ts +2 -0
  8. package/dist/types/chat/display-preferences.d.ts +2 -0
  9. package/dist/types/chat/extension-types.d.ts +31 -0
  10. package/dist/types/chat/reply-write.d.ts +48 -0
  11. package/dist/types/chat/table-chart.d.ts +4 -3
  12. package/dist/types/chat/tool-execution.d.ts +1 -2
  13. package/dist/types/chat/transcript-outline.d.ts +7 -0
  14. package/dist/types/chat/transcript-render-helpers.d.ts +2 -0
  15. package/dist/types/chrome/context-map.d.ts +15 -0
  16. package/dist/types/chrome/context-presentation.d.ts +48 -0
  17. package/dist/types/chrome/context-view-model.d.ts +77 -0
  18. package/dist/types/chrome/index.d.ts +1 -0
  19. package/dist/types/chrome/transcript-notice.d.ts +35 -0
  20. package/dist/types/chrome/transcript-status.d.ts +20 -8
  21. package/dist/types/components/editor.d.ts +8 -0
  22. package/dist/types/components/image.d.ts +20 -0
  23. package/dist/types/components/loader.d.ts +1 -1
  24. package/dist/types/components/markdown.d.ts +7 -0
  25. package/dist/types/native/blobs.d.ts +11 -1
  26. package/dist/types/native/picker.d.ts +4 -4
  27. package/dist/types/overlays/advisor-config.d.ts +6 -0
  28. package/dist/types/overlays/agent-hub-projection.d.ts +3 -1
  29. package/dist/types/overlays/annotation-overlay.d.ts +7 -1
  30. package/dist/types/overlays/annotation-types.d.ts +28 -0
  31. package/dist/types/overlays/ask-dialog.d.ts +12 -3
  32. package/dist/types/overlays/btw-history-panel.d.ts +16 -2
  33. package/dist/types/overlays/btw-history.d.ts +7 -0
  34. package/dist/types/overlays/btw-panel.d.ts +2 -0
  35. package/dist/types/overlays/context-viewer-format.d.ts +42 -0
  36. package/dist/types/overlays/context-viewer-overview.d.ts +70 -0
  37. package/dist/types/overlays/context-viewer.d.ts +25 -0
  38. package/dist/types/overlays/hook-input.d.ts +1 -0
  39. package/dist/types/overlays/login-dialog.d.ts +5 -1
  40. package/dist/types/overlays/mcp-add-wizard.d.ts +2 -0
  41. package/dist/types/overlays/model-browser.d.ts +10 -1
  42. package/dist/types/overlays/oauth-selector.d.ts +23 -0
  43. package/dist/types/overlays/pause-screen.d.ts +13 -3
  44. package/dist/types/overlays/plan-review-overlay.d.ts +2 -0
  45. package/dist/types/overlays/rewind-selector.d.ts +1 -1
  46. package/dist/types/overlays/running-subagent-badge.d.ts +7 -1
  47. package/dist/types/overlays/session-selector.d.ts +22 -2
  48. package/dist/types/prompt/composer.d.ts +43 -0
  49. package/dist/types/prompt/interactive-context-helpers.d.ts +10 -3
  50. package/dist/types/prompt/macos-spelling.d.ts +2 -2
  51. package/dist/types/render/extension-links.d.ts +65 -0
  52. package/dist/types/render/hyperlink.d.ts +38 -7
  53. package/dist/types/render/index.d.ts +1 -0
  54. package/dist/types/render/output-pane.d.ts +1 -1
  55. package/dist/types/render/render-utils.d.ts +7 -1
  56. package/dist/types/setup/scenes/glyph.d.ts +1 -1
  57. package/dist/types/setup/scenes/model.d.ts +1 -1
  58. package/dist/types/setup/scenes/outro.d.ts +5 -4
  59. package/dist/types/setup/scenes/sign-in.d.ts +13 -8
  60. package/dist/types/setup/scenes/types.d.ts +16 -1
  61. package/dist/types/setup/startup-splash.d.ts +1 -1
  62. package/dist/types/setup/wizard-overlay.d.ts +11 -7
  63. package/dist/types/setup/wizard.d.ts +5 -1
  64. package/dist/types/status-line/component.d.ts +3 -3
  65. package/dist/types/status-line/context-usage.d.ts +42 -35
  66. package/dist/types/status-line/host.d.ts +6 -2
  67. package/dist/types/terminal-capabilities.d.ts +7 -0
  68. package/dist/types/theme/symbols.d.ts +1 -1
  69. package/dist/types/theme/theme.d.ts +0 -23
  70. package/dist/types/tools/ask.d.ts +4 -0
  71. package/dist/types/tools/bash-interactive.d.ts +6 -0
  72. package/dist/types/tools/bash.d.ts +2 -0
  73. package/dist/types/tools/default-renderer.d.ts +6 -4
  74. package/dist/types/tools/edit.d.ts +3 -1
  75. package/dist/types/tools/fetch.d.ts +1 -0
  76. package/dist/types/tools/github.d.ts +3 -0
  77. package/dist/types/tools/grouped-file-output.d.ts +2 -0
  78. package/dist/types/tools/irc.d.ts +6 -0
  79. package/dist/types/tools/json-tree.d.ts +23 -4
  80. package/dist/types/tools/lsp.d.ts +2 -0
  81. package/dist/types/tools/mcp.d.ts +7 -6
  82. package/dist/types/tools/native-view.d.ts +1 -1
  83. package/dist/types/tools/read.d.ts +3 -0
  84. package/dist/types/tools/renderer.d.ts +2 -0
  85. package/dist/types/tools/streaming-output.d.ts +11 -0
  86. package/dist/types/tools/task.d.ts +9 -1
  87. package/dist/types/tools/url-scheme-host.d.ts +17 -0
  88. package/dist/types/tools/wait.d.ts +16 -2
  89. package/dist/types/tools/yield.d.ts +1 -1
  90. package/dist/types/tui.d.ts +9 -2
  91. package/dist/types/vim.d.ts +39 -0
  92. package/package.json +10 -14
  93. package/src/app-keybindings.d.ts +20 -0
  94. package/src/app-keybindings.ts +20 -0
  95. package/src/apps/session-picker.ts +7 -0
  96. package/src/charts/chart-plan.d.ts +9 -7
  97. package/src/charts/chart-plan.ts +20 -50
  98. package/src/chat/advisor-message.ts +2 -0
  99. package/src/chat/assistant-message.d.ts +15 -3
  100. package/src/chat/assistant-message.ts +137 -19
  101. package/src/chat/background-tan-message.ts +4 -0
  102. package/src/chat/bash-execution.d.ts +2 -0
  103. package/src/chat/bash-execution.ts +13 -1
  104. package/src/chat/chat-transcript-builder.ts +58 -28
  105. package/src/chat/compaction-summary-message.ts +2 -1
  106. package/src/chat/display-preferences.d.ts +2 -0
  107. package/src/chat/display-preferences.ts +3 -0
  108. package/src/chat/extension-types.d.ts +31 -0
  109. package/src/chat/extension-types.ts +34 -0
  110. package/src/chat/read-tool-group.ts +1 -2
  111. package/src/chat/reply-write.d.ts +48 -0
  112. package/src/chat/reply-write.ts +127 -0
  113. package/src/chat/skill-message.ts +2 -6
  114. package/src/chat/table-chart.d.ts +4 -3
  115. package/src/chat/table-chart.ts +10 -4
  116. package/src/chat/tool-execution.d.ts +1 -2
  117. package/src/chat/tool-execution.ts +20 -13
  118. package/src/chat/transcript-outline.d.ts +7 -0
  119. package/src/chat/transcript-outline.ts +27 -0
  120. package/src/chat/transcript-render-helpers.d.ts +2 -0
  121. package/src/chat/transcript-render-helpers.ts +66 -24
  122. package/src/chrome/context-map.ts +62 -0
  123. package/src/chrome/context-presentation.ts +26 -0
  124. package/src/chrome/context-view-model.ts +73 -0
  125. package/src/chrome/index.ts +1 -0
  126. package/src/chrome/transcript-container.ts +89 -59
  127. package/src/chrome/transcript-notice.d.ts +35 -0
  128. package/src/chrome/transcript-notice.ts +83 -0
  129. package/src/chrome/transcript-status.d.ts +20 -8
  130. package/src/chrome/transcript-status.ts +29 -29
  131. package/src/components/editor.d.ts +8 -0
  132. package/src/components/editor.ts +465 -14
  133. package/src/components/image.d.ts +20 -0
  134. package/src/components/image.ts +83 -18
  135. package/src/components/loader.d.ts +1 -1
  136. package/src/components/loader.ts +1 -1
  137. package/src/components/markdown.d.ts +7 -0
  138. package/src/components/markdown.ts +225 -13
  139. package/src/hotkeys-markdown.ts +2 -0
  140. package/src/native/backend.ts +5 -66
  141. package/src/native/blobs.d.ts +11 -1
  142. package/src/native/blobs.ts +5 -3
  143. package/src/native/picker.d.ts +4 -4
  144. package/src/native/picker.ts +4 -4
  145. package/src/overlays/advisor-config.ts +10 -12
  146. package/src/overlays/agent-hub-projection.d.ts +3 -1
  147. package/src/overlays/agent-hub-projection.ts +6 -5
  148. package/src/overlays/agent-hub.ts +51 -42
  149. package/src/overlays/annotation-overlay.ts +125 -37
  150. package/src/overlays/annotation-types.ts +24 -0
  151. package/src/overlays/ask-dialog.ts +125 -35
  152. package/src/overlays/btw-history-panel.ts +124 -12
  153. package/src/overlays/btw-history.ts +11 -0
  154. package/src/overlays/btw-panel.ts +8 -4
  155. package/src/overlays/context-viewer-format.ts +145 -0
  156. package/src/overlays/context-viewer-overview.ts +381 -0
  157. package/src/overlays/context-viewer.ts +728 -0
  158. package/src/overlays/hook-input.ts +2 -0
  159. package/src/overlays/hook-selector.ts +2 -2
  160. package/src/overlays/login-dialog.ts +31 -5
  161. package/src/overlays/mcp-add-wizard.ts +6 -1
  162. package/src/overlays/model-browser.ts +37 -0
  163. package/src/overlays/model-hub.ts +1 -7
  164. package/src/overlays/model-picker.ts +1 -10
  165. package/src/overlays/oauth-selector.ts +44 -6
  166. package/src/overlays/pause-screen.ts +166 -33
  167. package/src/overlays/plan-review-overlay.ts +13 -2
  168. package/src/overlays/rewind-selector.ts +29 -12
  169. package/src/overlays/running-subagent-badge.ts +12 -1
  170. package/src/overlays/session-selector.ts +313 -42
  171. package/src/overlays/settings-defs.ts +1 -0
  172. package/src/overlays/usage-dashboard.ts +20 -14
  173. package/src/prompt/composer.ts +216 -1
  174. package/src/prompt/custom-editor.ts +6 -1
  175. package/src/prompt/emoji-autocomplete.ts +0 -2
  176. package/src/prompt/interactive-context-helpers.ts +29 -4
  177. package/src/prompt/macos-spelling.ts +24 -15
  178. package/src/render/extension-links.d.ts +65 -0
  179. package/src/render/extension-links.ts +214 -0
  180. package/src/render/hyperlink.d.ts +38 -7
  181. package/src/render/hyperlink.ts +102 -23
  182. package/src/render/index.d.ts +1 -0
  183. package/src/render/index.ts +1 -0
  184. package/src/render/output-pane.d.ts +1 -1
  185. package/src/render/output-pane.ts +60 -17
  186. package/src/render/render-utils.d.ts +7 -1
  187. package/src/render/render-utils.ts +11 -2
  188. package/src/setup/scenes/composer.ts +2 -0
  189. package/src/setup/scenes/glyph.ts +3 -1
  190. package/src/setup/scenes/model.ts +192 -29
  191. package/src/setup/scenes/outro.ts +33 -15
  192. package/src/setup/scenes/sign-in.ts +194 -392
  193. package/src/setup/scenes/theme.ts +2 -0
  194. package/src/setup/scenes/types.ts +18 -1
  195. package/src/setup/startup-splash.ts +8 -7
  196. package/src/setup/wizard-overlay.ts +164 -35
  197. package/src/setup/wizard.ts +11 -2
  198. package/src/status-line/component.ts +10 -14
  199. package/src/status-line/context-usage.ts +122 -597
  200. package/src/status-line/host.ts +6 -2
  201. package/src/terminal-capabilities.d.ts +7 -0
  202. package/src/terminal-capabilities.ts +10 -0
  203. package/src/terminal.ts +24 -2
  204. package/src/theme/defaults.json +1 -0
  205. package/src/theme/loader.ts +1 -1
  206. package/src/theme/symbols.d.ts +1 -1
  207. package/src/theme/symbols.ts +16 -0
  208. package/src/theme/theme.d.ts +0 -23
  209. package/src/theme/theme.ts +2 -75
  210. package/src/tools/ask.d.ts +4 -0
  211. package/src/tools/ask.ts +4 -0
  212. package/src/tools/ast-grep.ts +3 -2
  213. package/src/tools/bash-interactive.d.ts +49 -0
  214. package/src/tools/bash-interactive.ts +6 -1
  215. package/src/tools/bash.d.ts +2 -0
  216. package/src/tools/bash.ts +7 -23
  217. package/src/tools/default-renderer.d.ts +6 -4
  218. package/src/tools/default-renderer.ts +9 -6
  219. package/src/tools/edit.d.ts +3 -1
  220. package/src/tools/edit.ts +8 -4
  221. package/src/tools/eval.ts +14 -4
  222. package/src/tools/fetch.d.ts +1 -0
  223. package/src/tools/fetch.ts +1 -0
  224. package/src/tools/find.ts +3 -10
  225. package/src/tools/github.d.ts +3 -0
  226. package/src/tools/github.ts +23 -3
  227. package/src/tools/glob.ts +4 -3
  228. package/src/tools/grep.ts +3 -4
  229. package/src/tools/grouped-file-output.d.ts +2 -0
  230. package/src/tools/grouped-file-output.ts +8 -2
  231. package/src/tools/irc.d.ts +6 -0
  232. package/src/tools/irc.ts +6 -0
  233. package/src/tools/job-widget.ts +13 -1
  234. package/src/tools/json-tree.d.ts +23 -4
  235. package/src/tools/json-tree.ts +132 -42
  236. package/src/tools/lsp.d.ts +2 -0
  237. package/src/tools/lsp.ts +36 -15
  238. package/src/tools/mcp.d.ts +7 -6
  239. package/src/tools/mcp.ts +41 -15
  240. package/src/tools/native-view.d.ts +1 -1
  241. package/src/tools/native-view.ts +3 -3
  242. package/src/tools/read.d.ts +3 -0
  243. package/src/tools/read.ts +3 -1
  244. package/src/tools/renderer.d.ts +2 -0
  245. package/src/tools/renderer.ts +2 -0
  246. package/src/tools/streaming-output.d.ts +11 -0
  247. package/src/tools/streaming-output.ts +41 -0
  248. package/src/tools/task.d.ts +9 -1
  249. package/src/tools/task.ts +59 -16
  250. package/src/tools/url-scheme-host.d.ts +17 -0
  251. package/src/tools/url-scheme-host.ts +21 -0
  252. package/src/tools/vibe.ts +14 -3
  253. package/src/tools/wait.d.ts +16 -2
  254. package/src/tools/wait.ts +16 -2
  255. package/src/tools/yield.d.ts +1 -1
  256. package/src/tools/yield.ts +18 -9
  257. package/src/tui.d.ts +9 -2
  258. package/src/tui.ts +102 -34
  259. package/src/vim.d.ts +39 -0
  260. package/src/vim.ts +313 -22
  261. package/dist/types/theme/defaults/index.d.ts +0 -10289
  262. package/src/theme/defaults/alabaster.json +0 -103
  263. package/src/theme/defaults/amethyst.json +0 -106
  264. package/src/theme/defaults/anthracite.json +0 -103
  265. package/src/theme/defaults/basalt.json +0 -101
  266. package/src/theme/defaults/birch.json +0 -105
  267. package/src/theme/defaults/dark-abyss.json +0 -101
  268. package/src/theme/defaults/dark-arctic.json +0 -114
  269. package/src/theme/defaults/dark-aurora.json +0 -105
  270. package/src/theme/defaults/dark-catppuccin.json +0 -117
  271. package/src/theme/defaults/dark-cavern.json +0 -101
  272. package/src/theme/defaults/dark-celestial.json +0 -116
  273. package/src/theme/defaults/dark-copper.json +0 -105
  274. package/src/theme/defaults/dark-cosmos.json +0 -100
  275. package/src/theme/defaults/dark-cyberpunk.json +0 -112
  276. package/src/theme/defaults/dark-dracula.json +0 -108
  277. package/src/theme/defaults/dark-eclipse.json +0 -101
  278. package/src/theme/defaults/dark-ember.json +0 -105
  279. package/src/theme/defaults/dark-equinox.json +0 -100
  280. package/src/theme/defaults/dark-forest.json +0 -106
  281. package/src/theme/defaults/dark-github.json +0 -115
  282. package/src/theme/defaults/dark-gruvbox.json +0 -122
  283. package/src/theme/defaults/dark-lavender.json +0 -105
  284. package/src/theme/defaults/dark-lunar.json +0 -99
  285. package/src/theme/defaults/dark-midnight.json +0 -105
  286. package/src/theme/defaults/dark-monochrome.json +0 -104
  287. package/src/theme/defaults/dark-monokai.json +0 -108
  288. package/src/theme/defaults/dark-nebula.json +0 -100
  289. package/src/theme/defaults/dark-neon-noir.json +0 -110
  290. package/src/theme/defaults/dark-nord.json +0 -108
  291. package/src/theme/defaults/dark-ocean.json +0 -111
  292. package/src/theme/defaults/dark-one.json +0 -110
  293. package/src/theme/defaults/dark-poimandres.json +0 -125
  294. package/src/theme/defaults/dark-rainforest.json +0 -101
  295. package/src/theme/defaults/dark-reef.json +0 -101
  296. package/src/theme/defaults/dark-retro.json +0 -102
  297. package/src/theme/defaults/dark-rose-pine.json +0 -106
  298. package/src/theme/defaults/dark-sakura.json +0 -105
  299. package/src/theme/defaults/dark-slate.json +0 -105
  300. package/src/theme/defaults/dark-solarized.json +0 -107
  301. package/src/theme/defaults/dark-solstice.json +0 -100
  302. package/src/theme/defaults/dark-starfall.json +0 -101
  303. package/src/theme/defaults/dark-sunset.json +0 -109
  304. package/src/theme/defaults/dark-swamp.json +0 -100
  305. package/src/theme/defaults/dark-synthwave.json +0 -113
  306. package/src/theme/defaults/dark-taiga.json +0 -101
  307. package/src/theme/defaults/dark-terminal.json +0 -105
  308. package/src/theme/defaults/dark-tokyo-night.json +0 -111
  309. package/src/theme/defaults/dark-tundra.json +0 -101
  310. package/src/theme/defaults/dark-twilight.json +0 -101
  311. package/src/theme/defaults/dark-volcanic.json +0 -101
  312. package/src/theme/defaults/graphite.json +0 -102
  313. package/src/theme/defaults/index.d.ts +0 -10289
  314. package/src/theme/defaults/index.ts +0 -203
  315. package/src/theme/defaults/light-arctic.json +0 -117
  316. package/src/theme/defaults/light-aurora-day.json +0 -101
  317. package/src/theme/defaults/light-canyon.json +0 -101
  318. package/src/theme/defaults/light-catppuccin.json +0 -116
  319. package/src/theme/defaults/light-cirrus.json +0 -100
  320. package/src/theme/defaults/light-coral.json +0 -105
  321. package/src/theme/defaults/light-cyberpunk.json +0 -106
  322. package/src/theme/defaults/light-dawn.json +0 -100
  323. package/src/theme/defaults/light-dunes.json +0 -101
  324. package/src/theme/defaults/light-eucalyptus.json +0 -105
  325. package/src/theme/defaults/light-forest.json +0 -110
  326. package/src/theme/defaults/light-frost.json +0 -105
  327. package/src/theme/defaults/light-github.json +0 -125
  328. package/src/theme/defaults/light-glacier.json +0 -101
  329. package/src/theme/defaults/light-gruvbox.json +0 -118
  330. package/src/theme/defaults/light-haze.json +0 -100
  331. package/src/theme/defaults/light-honeycomb.json +0 -105
  332. package/src/theme/defaults/light-lagoon.json +0 -101
  333. package/src/theme/defaults/light-lavender.json +0 -105
  334. package/src/theme/defaults/light-meadow.json +0 -101
  335. package/src/theme/defaults/light-mint.json +0 -105
  336. package/src/theme/defaults/light-monochrome.json +0 -111
  337. package/src/theme/defaults/light-ocean.json +0 -109
  338. package/src/theme/defaults/light-one.json +0 -109
  339. package/src/theme/defaults/light-opal.json +0 -101
  340. package/src/theme/defaults/light-orchard.json +0 -101
  341. package/src/theme/defaults/light-paper.json +0 -105
  342. package/src/theme/defaults/light-poimandres.json +0 -125
  343. package/src/theme/defaults/light-prism.json +0 -100
  344. package/src/theme/defaults/light-retro.json +0 -108
  345. package/src/theme/defaults/light-sand.json +0 -105
  346. package/src/theme/defaults/light-savanna.json +0 -101
  347. package/src/theme/defaults/light-solarized.json +0 -112
  348. package/src/theme/defaults/light-soleil.json +0 -100
  349. package/src/theme/defaults/light-sunset.json +0 -109
  350. package/src/theme/defaults/light-synthwave.json +0 -108
  351. package/src/theme/defaults/light-tokyo-night.json +0 -121
  352. package/src/theme/defaults/light-wetland.json +0 -101
  353. package/src/theme/defaults/light-zenith.json +0 -99
  354. package/src/theme/defaults/limestone.json +0 -104
  355. package/src/theme/defaults/mahogany.json +0 -107
  356. package/src/theme/defaults/marble.json +0 -103
  357. package/src/theme/defaults/obsidian.json +0 -101
  358. package/src/theme/defaults/onyx.json +0 -101
  359. package/src/theme/defaults/pearl.json +0 -103
  360. package/src/theme/defaults/porcelain.json +0 -101
  361. package/src/theme/defaults/quartz.json +0 -106
  362. package/src/theme/defaults/sandstone.json +0 -105
  363. package/src/theme/defaults/titanium.json +0 -100
package/src/tui.ts CHANGED
@@ -21,7 +21,7 @@ import * as postmortem from "@linxiraos/pi-utils/postmortem";
21
21
  import type { TspFrame, TspNode, TspText } from "@linxiraos/pi-wire";
22
22
  import { DEFAULT_MAX_INLINE_IMAGES, ImageBudget } from "./components/image";
23
23
  import { TuiDebugServer } from "./debug-server";
24
- import { isKeyRelease, matchesKey } from "./keys";
24
+ import { extractPrintableText, isKeyRelease, matchesKey } from "./keys";
25
25
  import { KITTY_PLACEHOLDER } from "./kitty-graphics";
26
26
  import { LoopWatchdog } from "./loop-watchdog";
27
27
  import { assumedTspHello, NativeBackend, type NativeHost } from "./native/backend";
@@ -48,9 +48,11 @@ import {
48
48
  shouldEnableSynchronizedOutputByDefault,
49
49
  synchronizedOutputUserOverride,
50
50
  TERMINAL,
51
+ withDirectPlacementLift,
51
52
  } from "./terminal-capabilities";
52
53
  import { onTerminalBackgroundFallbackChange } from "./theme/theme";
53
54
  import { compositeLineAt } from "./render/composite";
55
+ import { stripExtensionLinkMarkers } from "./render/extension-links";
54
56
  import { tmuxMultiplexer } from "./multiplexers/tmux";
55
57
  import {
56
58
  Ellipsis,
@@ -213,7 +215,9 @@ export interface TUIStartOptions {
213
215
  * switches to raw input and replays the kernel-buffered keystrokes.
214
216
  *
215
217
  * A terminal expected to speak TSP needs raw input from the start, so it
216
- * gets it; its keystrokes are held instead (TSP events and the cell-size
218
+ * gets it. Plain typing (printable text, Backspace) still edits the focused
219
+ * component live, as the kernel echo shows it elsewhere; the first other key
220
+ * and every key after it are held instead (TSP events and the cell-size
217
221
  * reply still apply) until {@link TUI.releaseHeldInput} replays them.
218
222
  */
219
223
  deferInput?: boolean;
@@ -943,6 +947,7 @@ export class TUI extends Container {
943
947
  /** True from the end of start() until stop(): the terminal modes start listeners enable are live. */
944
948
  #started = false;
945
949
  #paintListeners = new Set<PaintListener>();
950
+ #frameWriteListeners = new Set<(data: string) => void>();
946
951
 
947
952
  /** Global callback for debug key (Shift+Ctrl+D). Called before input is forwarded to focused component. */
948
953
  onDebug?: () => void;
@@ -1042,7 +1047,8 @@ export class TUI extends Container {
1042
1047
  #inputDeferred = false;
1043
1048
  /**
1044
1049
  * Keystrokes held since a TSP `deferInput` start, replayed by
1045
- * releaseHeldInput(); undefined when not holding.
1050
+ * releaseHeldInput(); undefined when not holding, empty while plain typing
1051
+ * still goes through live.
1046
1052
  */
1047
1053
  #heldInput: string[] | undefined;
1048
1054
  /**
@@ -1159,6 +1165,14 @@ export class TUI extends Container {
1159
1165
  };
1160
1166
  }
1161
1167
 
1168
+ /** Observe actual ANSI frame writes, including transient resize paints; returns the unsubscribe. */
1169
+ addFrameWriteListener(listener: (data: string) => void): () => void {
1170
+ this.#frameWriteListeners.add(listener);
1171
+ return () => {
1172
+ this.#frameWriteListeners.delete(listener);
1173
+ };
1174
+ }
1175
+
1162
1176
  /** Install the product-owned bounded frame provider. */
1163
1177
  setFrameProvider(provider: TerminalFrameProvider | undefined): void {
1164
1178
  this.#frameProvider = provider;
@@ -2539,8 +2553,13 @@ export class TUI extends Container {
2539
2553
  }
2540
2554
  }
2541
2555
 
2542
- addInputListener(listener: InputListener): () => void {
2543
- this.#inputListeners.add(listener);
2556
+ /** Registers a key listener; `prepend` gives a foreground input owner first refusal over global shortcuts. */
2557
+ addInputListener(listener: InputListener, options?: { prepend?: boolean }): () => void {
2558
+ if (options?.prepend) {
2559
+ this.#inputListeners = new Set([listener, ...this.#inputListeners]);
2560
+ } else {
2561
+ this.#inputListeners.add(listener);
2562
+ }
2544
2563
  return () => {
2545
2564
  this.#inputListeners.delete(listener);
2546
2565
  };
@@ -3059,7 +3078,11 @@ export class TUI extends Container {
3059
3078
  }
3060
3079
  if (data.length === 0) return;
3061
3080
 
3062
- if (this.#heldInput !== undefined && this.#focusedComponent === this.#heldFocus) {
3081
+ if (
3082
+ this.#heldInput !== undefined &&
3083
+ this.#focusedComponent === this.#heldFocus &&
3084
+ !this.#typesThroughHold(data)
3085
+ ) {
3063
3086
  this.#holdInput(data);
3064
3087
  return;
3065
3088
  }
@@ -3149,6 +3172,18 @@ export class TUI extends Container {
3149
3172
  return holder?.component === focused ? holder.preFocus : null;
3150
3173
  }
3151
3174
 
3175
+ /**
3176
+ * Whether a keystroke typed during a TSP startup hold edits the focused
3177
+ * component now: plain typing (printable text, Backspace) and key releases,
3178
+ * while nothing is queued ahead of them. The draft then grows as it is typed,
3179
+ * like a cooked tty's echo; a shortcut waits for the handlers that act on it,
3180
+ * and whatever follows it waits behind it to keep typing order.
3181
+ */
3182
+ #typesThroughHold(data: string): boolean {
3183
+ if (this.#heldInput!.length > 0) return false;
3184
+ return extractPrintableText(data) !== undefined || matchesKey(data, "backspace") || isKeyRelease(data);
3185
+ }
3186
+
3152
3187
  /**
3153
3188
  * Queue a keystroke typed before the app installed its key handlers; input
3154
3189
  * listeners see it once, on replay. The cell-size reply is a terminal report,
@@ -3391,29 +3426,40 @@ export class TUI extends Container {
3391
3426
 
3392
3427
  /**
3393
3428
  * Clip direct placements to the visible source slice: Kitty tracks a live
3394
- * placement owner, while SIXEL crops the encoded raster (iTerm2 images are
3395
- * not cropped). SIXEL and iTerm2 have no delete command and composite over
3396
- * existing pixels, so erase the visible rows they paint above `screenRow`
3397
- * before repainting.
3429
+ * placement owner, while SIXEL crops the encoded raster. An iTerm2 image
3430
+ * or a Kitty transmit-and-display image cannot be cropped, so a block
3431
+ * clipped at the top is omitted rather than painted over following text.
3432
+ * SIXEL and iTerm2 have no delete command and composite over existing
3433
+ * pixels, so erase the visible rows they paint above the line before repainting.
3434
+ *
3435
+ * `frameRow` is the line's row within the frame it was rendered in, so at
3436
+ * most that many rows above it belong to its image block. A viewport whose
3437
+ * top clips a block sits below history rows on screen; bounding the lift by
3438
+ * the physical row instead would erase and paint over those history rows
3439
+ * just before they scroll into native scrollback.
3398
3440
  */
3399
3441
  #imageLineSequence(
3400
3442
  line: string,
3401
- screenRow: number,
3443
+ frameRow: number,
3402
3444
  placements: Map<number, LiveImagePlacement> | undefined,
3403
3445
  placementRow: number,
3404
3446
  ): string {
3405
- if (screenRow < 0) return line;
3447
+ if (frameRow < 0) return line;
3406
3448
  const parsed = parseKittyDirectPlacementLine(line);
3407
3449
  if (!parsed) {
3408
3450
  const requestedLift = directPlacementLift(line);
3409
- const lift = Math.min(requestedLift, screenRow);
3451
+ const lift = Math.min(requestedLift, frameRow);
3410
3452
  if (requestedLift > lift) {
3411
3453
  const cellHeight = getCellDimensions().heightPx;
3412
3454
  const cropPixels = Math.round((requestedLift - lift) * cellHeight);
3413
- const maxHeightPixels = Math.floor((screenRow + 1) * cellHeight);
3414
- line = line.replace(/\x1bP[0-9;]*q[\s\S]*?\x1b\\/g, sequence =>
3455
+ const maxHeightPixels = Math.floor((frameRow + 1) * cellHeight);
3456
+ const clipped = line.replace(/\x1bP[0-9;]*q[\s\S]*?\x1b\\/g, sequence =>
3415
3457
  this.#cropSixel(sequence, cropPixels, maxHeightPixels),
3416
3458
  );
3459
+ // Re-anchoring an uncropped OSC/APC image would paint its hidden
3460
+ // rows below the reserved slice, over the following text.
3461
+ if (clipped === line) return "";
3462
+ line = withDirectPlacementLift(clipped, lift);
3417
3463
  }
3418
3464
  return lift > 0 ? `\x1b[${lift}A${`${ERASE_LINE}\x1b[B`.repeat(lift)}${line}` : line;
3419
3465
  }
@@ -3428,7 +3474,7 @@ export class TUI extends Container {
3428
3474
  placementId,
3429
3475
  columns: parsed.columns,
3430
3476
  rows: parsed.rows,
3431
- screenRow,
3477
+ screenRow: frameRow,
3432
3478
  imageHeightPx: this.#imageBudget.getPlacementGeometry(parsed.imageId)?.heightPx ?? 0,
3433
3479
  })
3434
3480
  );
@@ -3501,6 +3547,16 @@ export class TUI extends Container {
3501
3547
  }
3502
3548
  }
3503
3549
 
3550
+ #notifyFrameWrite(data: string): void {
3551
+ for (const listener of this.#frameWriteListeners) {
3552
+ try {
3553
+ listener(data);
3554
+ } catch (err) {
3555
+ logger.error("TUI frame write listener failed", { err });
3556
+ }
3557
+ }
3558
+ }
3559
+
3504
3560
  #renderProviderFrame(mainWidth: number, rawWidth: number, height: number): void {
3505
3561
  const provider = this.#frameProvider;
3506
3562
  if (!provider || mainWidth <= 0 || height <= 0) return;
@@ -3825,9 +3881,9 @@ export class TUI extends Container {
3825
3881
  buffer += `\x1b[${newTop + index + 1};1H${this.#lineRewriteSequence(
3826
3882
  current,
3827
3883
  width,
3828
- newTop + index,
3884
+ index,
3829
3885
  this.#osc66SpacerGlyphWidth(prepared.lines, index),
3830
- { imagePlacements: this.#screenImagePlacements },
3886
+ { imagePlacements: this.#screenImagePlacements, imageRow: newTop + index },
3831
3887
  )}`;
3832
3888
  }
3833
3889
  if (this.#providerWindow.length > rows && newTop + rows < height) {
@@ -3870,15 +3926,18 @@ export class TUI extends Container {
3870
3926
  }
3871
3927
  for (let index = 0; index < rows; index++) {
3872
3928
  if (screenRow > startTop) buffer += "\n";
3929
+ // Replay-split rows continue the history ledger written above them;
3930
+ // the provider's own rows reach no higher than its viewport top.
3931
+ const moved = index < replayViewportRows;
3873
3932
  append(
3874
3933
  this.#lineRewriteSequence(
3875
3934
  prepared.rows[index]!,
3876
3935
  width,
3877
- Math.min(screenRow, height - 1),
3936
+ moved ? Math.min(screenRow, height - 1) : index,
3878
3937
  this.#osc66SpacerGlyphWidth(prepared.lines, index),
3879
3938
  {
3880
3939
  blankRow: compactReplay,
3881
- imagePlacements: index < replayViewportRows ? undefined : this.#screenImagePlacements,
3940
+ imagePlacements: moved ? undefined : this.#screenImagePlacements,
3882
3941
  imageRow: newTop + index,
3883
3942
  },
3884
3943
  ),
@@ -3915,6 +3974,7 @@ export class TUI extends Container {
3915
3974
  this.terminal.write(this.#rebuildNoticeSequence(width, height));
3916
3975
  }
3917
3976
  this.terminal.write(buffer);
3977
+ this.#notifyFrameWrite(buffer);
3918
3978
  this.#debugPaint = {
3919
3979
  lines: prepared.lines,
3920
3980
  windowTop: this.#debugNextWindowTop,
@@ -4231,45 +4291,48 @@ export class TUI extends Container {
4231
4291
  LINE_FIT_MAX_SOURCE_CODE_UNITS,
4232
4292
  Math.max(LINE_FIT_MIN_SOURCE_CODE_UNITS, safeWidth * LINE_FIT_SOURCE_WIDTH_MULTIPLIER),
4233
4293
  );
4294
+ // Extension link markers exist only for hit-testing; the terminal must never get an openable
4295
+ // hyperlink. Strip before fitting (so a cut cannot split one) and before classifying.
4296
+ const output = stripExtensionLinkMarkers(raw);
4234
4297
 
4235
4298
  let source: string;
4236
4299
  let classification: LineClassification;
4237
- if (raw.length <= maxSourceLength) {
4300
+ if (output.length <= maxSourceLength) {
4238
4301
  // The overwhelmingly common path classifies image markers, OSC 8,
4239
4302
  // ANSI validity, OSC 66, non-ASCII, and exact ASCII width together.
4240
- classification = this.#classifyLine(raw, safeWidth);
4303
+ classification = this.#classifyLine(output, safeWidth);
4241
4304
  if (classification.isImage) {
4242
4305
  return {
4243
4306
  raw,
4244
4307
  width,
4245
4308
  widthEpoch,
4246
4309
  imageProtocol,
4247
- line: raw,
4248
- terminalContent: raw,
4310
+ line: output,
4311
+ terminalContent: output,
4249
4312
  asciiWidth: undefined,
4250
4313
  isImage: true,
4251
4314
  hasOsc8: false,
4252
4315
  };
4253
4316
  }
4254
- source = raw;
4317
+ source = output;
4255
4318
  } else {
4256
4319
  // Fitting a giant source can discard everything after the visible
4257
4320
  // prefix. Preserve image rows verbatim first, but do not scan the
4258
4321
  // entire source for width/OSC metadata that will immediately vanish.
4259
- if (TERMINAL.isImageLine(raw)) {
4322
+ if (TERMINAL.isImageLine(output)) {
4260
4323
  return {
4261
4324
  raw,
4262
4325
  width,
4263
4326
  widthEpoch,
4264
4327
  imageProtocol,
4265
- line: raw,
4266
- terminalContent: raw,
4328
+ line: output,
4329
+ terminalContent: output,
4267
4330
  asciiWidth: undefined,
4268
4331
  isImage: true,
4269
4332
  hasOsc8: false,
4270
4333
  };
4271
4334
  }
4272
- source = this.#lineFitSource(raw, safeWidth, maxSourceLength);
4335
+ source = this.#lineFitSource(output, safeWidth, maxSourceLength);
4273
4336
  // Preserve the former lineRewriteSequence classification: fitting can
4274
4337
  // move a marker from outside the raw scan window into the prepared
4275
4338
  // line's window, at which point terminal image dispatch owns it.
@@ -4512,10 +4575,15 @@ export class TUI extends Container {
4512
4575
  );
4513
4576
  }
4514
4577
 
4578
+ /**
4579
+ * Terminal bytes that rewrite one row. `frameRow` is the row's index within
4580
+ * the frame it belongs to (see {@link #imageLineSequence}); `imageRow`, the
4581
+ * physical row keying live Kitty placements, defaults to it.
4582
+ */
4515
4583
  #lineRewriteSequence(
4516
4584
  line: PreparedLine,
4517
4585
  width: number,
4518
- screenRow = -1,
4586
+ frameRow = -1,
4519
4587
  spacerGlyphWidth = -1,
4520
4588
  options?: { blankRow?: boolean; imagePlacements?: Map<number, LiveImagePlacement>; imageRow?: number },
4521
4589
  ): string {
@@ -4536,7 +4604,7 @@ export class TUI extends Container {
4536
4604
  } else if (line.isImage) {
4537
4605
  rewrite =
4538
4606
  ERASE_LINE +
4539
- this.#imageLineSequence(line.line, screenRow, options?.imagePlacements, options?.imageRow ?? screenRow);
4607
+ this.#imageLineSequence(line.line, frameRow, options?.imagePlacements, options?.imageRow ?? frameRow);
4540
4608
  } else {
4541
4609
  const terminalLine = this.#terminalLine(line);
4542
4610
  if (options?.blankRow) {
@@ -4728,9 +4796,9 @@ export class TUI extends Container {
4728
4796
  } else if (hideCursor) {
4729
4797
  cursorBuffer = "\x1b[?25l";
4730
4798
  }
4731
- this.terminal.write(
4732
- `${this.#paintBeginSequence}${prelude}${full ? "\x1b[H" : ""}${rowsBuffer}${cursorBuffer}${this.#paintEndSequence}`,
4733
- );
4799
+ const frame = `${this.#paintBeginSequence}${prelude}${full ? "\x1b[H" : ""}${rowsBuffer}${cursorBuffer}${this.#paintEndSequence}`;
4800
+ this.terminal.write(frame);
4801
+ this.#notifyFrameWrite(frame);
4734
4802
  this.#debugPaint = {
4735
4803
  lines: prepared.lines,
4736
4804
  windowTop: 0,
package/src/vim.d.ts CHANGED
@@ -64,13 +64,43 @@ export type VimCommand = {
64
64
  fromLine: number;
65
65
  toLine: number;
66
66
  out: boolean;
67
+ } | {
68
+ kind: "retype";
69
+ record: VimInsertRecord;
70
+ times: number;
71
+ newline: boolean;
72
+ overwrite: boolean;
67
73
  };
74
+ /** What an Insert/Replace session typed, relative to where it started; `.` replays it. */
75
+ export interface VimInsertRecord {
76
+ /** Graphemes removed before the session's start cursor (Backspace past the insert point). */
77
+ deleteBefore: number;
78
+ /** Graphemes removed after it (forward delete). */
79
+ deleteAfter: number;
80
+ text: string;
81
+ }
68
82
  /** Start offset of the grapheme after `col`, clamped to `text.length`. */
69
83
  export declare function nextGraphemeStart(text: string, col: number): number;
70
84
  /** Start offset of the grapheme before `col`, clamped to 0. */
71
85
  export declare function prevGraphemeStart(text: string, col: number): number;
72
86
  /** Offset of the final grapheme — where a Normal-mode cursor rests on a non-empty line. */
73
87
  export declare function lastGraphemeStart(text: string): number;
88
+ export declare function countGraphemes(text: string): number;
89
+ /** Offset `count` graphemes forward or backward from `offset`, clamped to the text. */
90
+ export declare function stepGraphemes(text: string, offset: number, count: number, forward: boolean): number;
91
+ /**
92
+ * What a session turned `before` into, anchored at its start `cursor`: the prefix match stops at the
93
+ * cursor and the suffix match never crosses it, so typing `aa` before an existing `a` records `aa`
94
+ * at the cursor rather than after the old one. Comparisons are whole graphemes, so a shared high
95
+ * surrogate cannot split an emoji into the replayed text.
96
+ */
97
+ export declare function diffInsertSession(before: string, cursor: number, after: string): VimInsertRecord;
98
+ /** Buffer flattened to one string plus the cursor's offset in it, so scans can cross lines. */
99
+ export declare function flatten(buf: VimBuffer): {
100
+ text: string;
101
+ cursor: number;
102
+ };
103
+ export declare function offsetToPos(lines: readonly string[], offset: number): VimPosition;
74
104
  export declare class VimState {
75
105
  #private;
76
106
  mode: VimMode;
@@ -94,6 +124,15 @@ export declare class VimState {
94
124
  * through to its regular handling (and, for Escape in Normal mode, to the app's interrupt).
95
125
  */
96
126
  handleKey(key: string, buf: VimBuffer): VimCommand[] | null;
127
+ /**
128
+ * Attach what an Insert/Replace session typed to the change that opened it. After an arrow key
129
+ * split the session, Vim's redo becomes a plain insert of the text typed since.
130
+ */
131
+ recordInsert(record: VimInsertRecord, afterArrow: boolean): void;
132
+ /** Commit a staged change when the editor confirms text changed. */
133
+ commitChange(): void;
134
+ /** Discard a staged change when the command was a no-op (e.g. `J` on the last line). */
135
+ discardChange(): void;
97
136
  }
98
137
  /**
99
138
  * Normalized, end-exclusive span covered by a Visual selection.