@visulima/tui 1.0.0-alpha.6 → 1.0.0-alpha.8

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 (412) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/core/index.js +1 -5
  3. package/dist/ink/index.d.ts +15 -34
  4. package/dist/ink/index.js +1 -155
  5. package/dist/packem_chunks/devtools.js +3 -26
  6. package/dist/packem_shared/Accordion-BXsqchV-.js +1 -0
  7. package/dist/packem_shared/Alert-BhYVMHtR.js +1 -0
  8. package/dist/packem_shared/AnimatePresence-Eu7Z8KHc.js +1 -0
  9. package/dist/packem_shared/ApprovalPrompt-BSn0FT1g.js +1 -0
  10. package/dist/packem_shared/AreaChart-Chy-frI7.js +1 -0
  11. package/dist/packem_shared/Badge-B8WPyRsK.js +1 -0
  12. package/dist/packem_shared/BarChart-rpZtlMcF.js +1 -0
  13. package/dist/packem_shared/BigText-CRpwUzrt.js +1 -0
  14. package/dist/packem_shared/BlinkDot-BvnRuWP8.js +1 -0
  15. package/dist/packem_shared/Box-BwqSvWuq.js +1 -0
  16. package/dist/packem_shared/Breadcrumb-D0hClbRV.js +1 -0
  17. package/dist/packem_shared/Button-B89Yvbc6.js +1 -0
  18. package/dist/packem_shared/COLOR_BLINDNESS_SIMULATION-DqErf7XX.js +1 -0
  19. package/dist/packem_shared/Calendar-Dmflvm2S.js +1 -0
  20. package/dist/packem_shared/Canvas-CKg6WV47.js +1 -0
  21. package/dist/packem_shared/Card-B_9fXdtU.js +1 -0
  22. package/dist/packem_shared/Cell-BrXn3jxY.js +1 -0
  23. package/dist/packem_shared/Checkbox-BN71eCWU.js +1 -0
  24. package/dist/packem_shared/Code-HhevcyiH.js +2 -0
  25. package/dist/packem_shared/Collapsible-u6uf_FdV.js +1 -0
  26. package/dist/packem_shared/CommandBlock-B-nslpCv.js +4 -0
  27. package/dist/packem_shared/CommandPalette-CEFdaURo.js +1 -0
  28. package/dist/packem_shared/ConfirmDialog-5Jje_Xpu.js +1 -0
  29. package/dist/packem_shared/ConfirmInput-D44Mb9oo.js +1 -0
  30. package/dist/packem_shared/ConsoleOverlay-CM3APfgP.js +1 -0
  31. package/dist/packem_shared/ContentSwitcher-Dm5BkrCt.js +1 -0
  32. package/dist/packem_shared/ControlledScrollView-DI8KZOQB.js +1 -0
  33. package/dist/packem_shared/Cursor-BoLFIMol.js +1 -0
  34. package/dist/packem_shared/DatePicker-CnSrFFAE.js +1 -0
  35. package/dist/packem_shared/DefinitionList-v8RDuF_R.js +1 -0
  36. package/dist/packem_shared/DevTools-O8EbCfHa.js +1 -0
  37. package/dist/packem_shared/Dialog-CTaL8pn0.js +1 -0
  38. package/dist/packem_shared/DiffView-BUIFqUB0.js +1 -0
  39. package/dist/packem_shared/Divider-C47bKmqu.js +1 -0
  40. package/dist/packem_shared/FilePicker-CUo7R5Qb.js +1 -0
  41. package/dist/packem_shared/FocusContext-Xy0cwJpO.js +1 -0
  42. package/dist/packem_shared/FormField-af3aUpRL.js +1 -0
  43. package/dist/packem_shared/Fullscreen-CuJ8y0s0.js +1 -0
  44. package/dist/packem_shared/Gauge-Dz-usH__.js +1 -0
  45. package/dist/packem_shared/Gradient-DYNc0GZA.js +1 -0
  46. package/dist/packem_shared/Heading-mwEYza3Y.js +1 -0
  47. package/dist/packem_shared/Heatmap-ChL97U1-.js +1 -0
  48. package/dist/packem_shared/Help-Zcelyw_U.js +1 -0
  49. package/dist/packem_shared/Histogram-FIf2F83d.js +1 -0
  50. package/dist/packem_shared/IMECompositionBuffer-C89PhiOu.js +1 -0
  51. package/dist/packem_shared/InputParser-rZKjY_7Y.js +2 -0
  52. package/dist/packem_shared/KEY-Bk8B-3h_.js +1 -0
  53. package/dist/packem_shared/Kbd-DpkPp4jB.js +1 -0
  54. package/dist/packem_shared/LayoutNode-rxblE317.js +1 -0
  55. package/dist/packem_shared/LineChart-BXE_girm.js +1 -0
  56. package/dist/packem_shared/Link-i2o2EG4-.js +1 -0
  57. package/dist/packem_shared/LoadingIndicator-TC1Fjwyt.js +1 -0
  58. package/dist/packem_shared/Markdown-R1XqK63D.js +1 -0
  59. package/dist/packem_shared/MaskedInput-J01phOZs.js +1 -0
  60. package/dist/packem_shared/Menu-CfrH4ymk.js +1 -0
  61. package/dist/packem_shared/MessageBubble-BmBBU2Rm.js +1 -0
  62. package/dist/packem_shared/ModelBadge-D3wrXncu.js +1 -0
  63. package/dist/packem_shared/MouseProvider-pjza-lpc.js +1 -0
  64. package/dist/packem_shared/MultiSelect-Dqmn-bVo.js +1 -0
  65. package/dist/packem_shared/NAMED_COLORS-B9fJsYdg.js +1 -0
  66. package/dist/packem_shared/Newline-BSG4iUqp.js +2 -0
  67. package/dist/packem_shared/OperationTree-DksxjMIV.js +1 -0
  68. package/dist/packem_shared/OptionList-CNx7r9yN.js +1 -0
  69. package/dist/packem_shared/OrderedList-BeDy035w.js +1 -0
  70. package/dist/packem_shared/Paginator-B56s6bhS.js +1 -0
  71. package/dist/packem_shared/Paragraph-BqJlH0R-.js +1 -0
  72. package/dist/packem_shared/Placeholder-GMpHRGC8.js +1 -0
  73. package/dist/packem_shared/ProgressBar-Bj3fmORR.js +1 -0
  74. package/dist/packem_shared/RadioGroup-Br8BeEwS.js +1 -0
  75. package/dist/packem_shared/Renderer-DJXooAsp.js +1 -0
  76. package/dist/packem_shared/ResizeObserverEntry-Dq0dk8Kq.js +1 -0
  77. package/dist/packem_shared/ScatterPlot-OhfYco5l.js +1 -0
  78. package/dist/packem_shared/ScrollBar-Da5Y3z7N.js +1 -0
  79. package/dist/packem_shared/ScrollBarBox-Dz6F-Eat.js +1 -0
  80. package/dist/packem_shared/ScrollList-DiVGyEjv.js +1 -0
  81. package/dist/packem_shared/ScrollView-BojONotI.js +1 -0
  82. package/dist/packem_shared/SearchInput-BoPTRbhV.js +1 -0
  83. package/dist/packem_shared/SelectInput-CAJ7SCBq.js +1 -0
  84. package/dist/packem_shared/SelectInputIndicator-N1n8ULHs.js +1 -0
  85. package/dist/packem_shared/SelectInputItem-BEkbmobs.js +1 -0
  86. package/dist/packem_shared/ShimmerText-CuGQ2NDC.js +1 -0
  87. package/dist/packem_shared/Slider-Cg_tJpKa.js +1 -0
  88. package/dist/packem_shared/Spacer-eT3HOrXk.js +1 -0
  89. package/dist/packem_shared/Sparkline-T6_FPVET.js +1 -0
  90. package/dist/packem_shared/Spinner-B0-A50pu.js +1 -0
  91. package/dist/packem_shared/Static-DLynr5pn.js +1 -0
  92. package/dist/packem_shared/Static-jzLPaHJF.js +1 -0
  93. package/dist/packem_shared/StaticRender-BgD61E7x.js +1 -0
  94. package/dist/packem_shared/StatusLine-Ch4jjef1.js +1 -0
  95. package/dist/packem_shared/StatusMessage-B1qfKeMM.js +1 -0
  96. package/dist/packem_shared/Stepper-CNPAqxiU.js +1 -0
  97. package/dist/packem_shared/Stopwatch-CAx2EWwq.js +1 -0
  98. package/dist/packem_shared/StreamingText-BYOKSB2T.js +1 -0
  99. package/dist/packem_shared/Switch-DzSpKYu7.js +1 -0
  100. package/dist/packem_shared/Tab-BcXzSUdj.js +1 -0
  101. package/dist/packem_shared/Table-DJp1TLrR.js +1 -0
  102. package/dist/packem_shared/Tabs-D68z0SOt.js +1 -0
  103. package/dist/packem_shared/Tag-BvLHnYRn.js +1 -0
  104. package/dist/packem_shared/Text-mTAve9R2.js +1 -0
  105. package/dist/packem_shared/TextInput-C_gYQlnF.js +1 -0
  106. package/dist/packem_shared/Textarea-C2ET_oMb.js +2 -0
  107. package/dist/packem_shared/Timer-CI3aQX65.js +1 -0
  108. package/dist/packem_shared/Toast-Drvc8XfG.js +1 -0
  109. package/dist/packem_shared/Tooltip-C5UnQlLd.js +1 -0
  110. package/dist/packem_shared/Transform-fYmcdqRT.js +1 -0
  111. package/dist/packem_shared/Transition-CJDBKYUB.js +1 -0
  112. package/dist/packem_shared/TreeNodeMap-CspqSCpb.js +1 -0
  113. package/dist/packem_shared/TreeView-DjhacGJ5.js +1 -0
  114. package/dist/packem_shared/TuiApp-DrjI_i-R.js +1 -0
  115. package/dist/packem_shared/TuiContext-BoJvG3NN.js +3 -0
  116. package/dist/packem_shared/UnorderedList-BnfqexZs.js +1 -0
  117. package/dist/packem_shared/accessibility-context-DDyHTwmA.js +1 -0
  118. package/dist/packem_shared/animation-context-DW3p-vpk.js +1 -0
  119. package/dist/packem_shared/ansi-parser-B6uXaq65.js +1 -0
  120. package/dist/packem_shared/ansi-tokenizer-DqX9nJuk.js +1 -0
  121. package/dist/packem_shared/app-context-BVpKlG1z.js +1 -0
  122. package/dist/packem_shared/background-context-rjOaWFki.js +1 -0
  123. package/dist/packem_shared/boxes-DyY_LXCi.js +1 -0
  124. package/dist/packem_shared/braille-BBjIoaN0.js +1 -0
  125. package/dist/packem_shared/colorize-DbTZMrJO.js +1 -0
  126. package/dist/packem_shared/comparePoints-C85EsmNz.js +1 -0
  127. package/dist/packem_shared/controlled-scroll-view-CmrAEvJk.js +1 -0
  128. package/dist/packem_shared/createInlineLoop-DRNZ7jqH.js +2 -0
  129. package/dist/packem_shared/createLinkedScrollGroup-BMTJ7rAj.js +1 -0
  130. package/dist/packem_shared/createMemoryStorage-QVZNXbWz.js +2 -0
  131. package/dist/packem_shared/createScreen-CrLrxA6t.js +3 -0
  132. package/dist/packem_shared/cursor-context-CFviBqPX.js +1 -0
  133. package/dist/packem_shared/dom-4y__5fWB.js +1 -0
  134. package/dist/packem_shared/focus-context-CsT69klR.js +1 -0
  135. package/dist/packem_shared/format-time-C7Q-hQZq.js +1 -0
  136. package/dist/packem_shared/getPathToRoot-B2tKmx3i.js +1 -0
  137. package/dist/packem_shared/getScrollHeight-BTEY8ewu.js +1 -0
  138. package/dist/packem_shared/input-utils-fAxzSlNh.js +1 -0
  139. package/dist/packem_shared/isIntersecting-B3KbKTmu.js +1 -0
  140. package/dist/packem_shared/isOsc52Supported-DKK7Uee6.js +1 -0
  141. package/dist/packem_shared/isTerminalPaletteQuerySupported-Dn2hFAZ_.js +1 -0
  142. package/dist/packem_shared/kittyFlags-C3rZLbcK.js +1 -0
  143. package/dist/packem_shared/line-chart-DrM8PwnI.js +1 -0
  144. package/dist/packem_shared/measure-element-DSp7YDus.js +2 -0
  145. package/dist/packem_shared/measure-text-DDjHT1jD.js +3 -0
  146. package/dist/packem_shared/measureElement-DA8WqFP_.js +1 -0
  147. package/dist/packem_shared/mouse-context-DaARgUu1.js +1 -0
  148. package/dist/packem_shared/parseSgrMouse-Ccj70ijb.js +1 -0
  149. package/dist/packem_shared/processLayout-DXDfFb_d.js +1 -0
  150. package/dist/packem_shared/reconciler-BuOP-TZ6.js +1 -0
  151. package/dist/packem_shared/reconciler-DSYCrIZs.js +1 -0
  152. package/dist/packem_shared/render-DDqtMAFN.js +1 -0
  153. package/dist/packem_shared/render-_r0K9K11.js +28 -0
  154. package/dist/packem_shared/renderToString-DeqOWRP8.js +4 -0
  155. package/dist/packem_shared/renderToString-IYYPyASm.js +2 -0
  156. package/dist/packem_shared/renderTreeToBuffer-DPkoCgP2.js +2 -0
  157. package/dist/packem_shared/renderer-D2p6av2X.js +17 -0
  158. package/dist/packem_shared/setEnableStyledLineCache-D2gZbwFM.js +1 -0
  159. package/dist/packem_shared/squashTextNodesWithMap-Cpqmc45i.js +1 -0
  160. package/dist/packem_shared/stderr-context-BzEaUICS.js +1 -0
  161. package/dist/packem_shared/stdin-context-BTaaFagk.js +1 -0
  162. package/dist/packem_shared/stdout-context-BnblEPez.js +1 -0
  163. package/dist/packem_shared/text-width-CZ9vPvM0.js +2 -0
  164. package/dist/packem_shared/token-to-elements-BYxT6J_Q.js +1 -0
  165. package/dist/packem_shared/treeViewTheme-1RIZyB4M.js +1 -0
  166. package/dist/packem_shared/useAnimation-B9we6ZzL.js +1 -0
  167. package/dist/packem_shared/useApp-B6fvM42d.js +1 -0
  168. package/dist/packem_shared/useBoxMetrics-D5pkIr6P.js +1 -0
  169. package/dist/packem_shared/useClipboard-CBxy0hT8.js +1 -0
  170. package/dist/packem_shared/useColorBlindness-BvWcu2Bb.js +1 -0
  171. package/dist/packem_shared/useConsoleCapture-BxiG8iLJ.js +1 -0
  172. package/dist/packem_shared/useCursor-CPu8T5Db.js +1 -0
  173. package/dist/packem_shared/useElementDimensions-qJ_WXFZ9.js +1 -0
  174. package/dist/packem_shared/useFocus-DSmziO_x.js +1 -0
  175. package/dist/packem_shared/useFocusManager-Uapn3LQo.js +1 -0
  176. package/dist/packem_shared/useForm-CzV-Oext.js +1 -0
  177. package/dist/packem_shared/useHotkey-D0dGey14.js +1 -0
  178. package/dist/packem_shared/useInput-D1_jG26Z.js +2 -0
  179. package/dist/packem_shared/useInterval-AobjZT3u.js +1 -0
  180. package/dist/packem_shared/useIsScreenReaderEnabled-DjWHh-II.js +1 -0
  181. package/dist/packem_shared/useKeyBindings-zabkEJQs.js +1 -0
  182. package/dist/packem_shared/useKeyChord-CICQIxXj.js +1 -0
  183. package/dist/packem_shared/useMouseAction-2dRfU1vE.js +1 -0
  184. package/dist/packem_shared/useMouseContext-C746G7kY.js +1 -0
  185. package/dist/packem_shared/useMousePosition-BTWfV4JK.js +1 -0
  186. package/dist/packem_shared/useOnMouseClick-nY8xLZmt.js +1 -0
  187. package/dist/packem_shared/useOnMouseHover-D3DczIol.js +1 -0
  188. package/dist/packem_shared/useOnMouseState-cRK8QvzD.js +1 -0
  189. package/dist/packem_shared/usePaste-CKKB9H-Z.js +1 -0
  190. package/dist/packem_shared/useScrollAcceleration-NrY1oVMs.js +1 -0
  191. package/dist/packem_shared/useScrollInput-Caghtn-Q.js +1 -0
  192. package/dist/packem_shared/useStderr-BDZb6InG.js +1 -0
  193. package/dist/packem_shared/useStdin-DKa4h35k.js +1 -0
  194. package/dist/packem_shared/useStdout-B-2lX4C5.js +1 -0
  195. package/dist/packem_shared/useStopwatch-DffK7iMh.js +1 -0
  196. package/dist/packem_shared/useTerminalPalette-Cv7tSduR.js +1 -0
  197. package/dist/packem_shared/useTextBuffer-DekkGLxI.js +4 -0
  198. package/dist/packem_shared/useTextSelection-CGT0GLDR.js +1 -0
  199. package/dist/packem_shared/useTimeout-7LEFYTnG.js +1 -0
  200. package/dist/packem_shared/useTimer-DyoqSyGi.js +1 -0
  201. package/dist/packem_shared/useTreeView-8UlTK6sW.js +1 -0
  202. package/dist/packem_shared/useTreeViewState-CRPCUWrb.js +1 -0
  203. package/dist/packem_shared/useWindowSize-yDZsXF8z.js +1 -0
  204. package/dist/packem_shared/utils-THUhYKG2.js +1 -0
  205. package/dist/packem_shared/variant-config-BJqpNo7H.js +1 -0
  206. package/dist/packem_shared/waitFor-Dj5zfL5s.js +4 -0
  207. package/dist/packem_shared/wrapOrTruncateStyledLine-BZ00SM8i.js +3 -0
  208. package/dist/react/index.js +1 -9
  209. package/dist/testing/index.js +1 -152
  210. package/package.json +9 -9
  211. package/dist/packem_shared/Accordion-BG-yfIkV.js +0 -80
  212. package/dist/packem_shared/Alert-BLcwIW8V.js +0 -17
  213. package/dist/packem_shared/AnimatePresence-D8nEOr_B.js +0 -98
  214. package/dist/packem_shared/ApprovalPrompt-BXdPros1.js +0 -104
  215. package/dist/packem_shared/AreaChart-CmTcxLum.js +0 -116
  216. package/dist/packem_shared/Badge-CUfbXwAB.js +0 -13
  217. package/dist/packem_shared/BarChart-DWRae67P.js +0 -87
  218. package/dist/packem_shared/BigText-CVq2X7B5.js +0 -24
  219. package/dist/packem_shared/BlinkDot-CrbHMR3L.js +0 -11
  220. package/dist/packem_shared/Box-W1w_NGin.js +0 -71
  221. package/dist/packem_shared/Breadcrumb-CPdNxVYs.js +0 -26
  222. package/dist/packem_shared/Button-CBmTbJ_D.js +0 -57
  223. package/dist/packem_shared/COLOR_BLINDNESS_SIMULATION-BsMy5Ewl.js +0 -81
  224. package/dist/packem_shared/Calendar-C2Qxt-LA.js +0 -139
  225. package/dist/packem_shared/Canvas-COttmLPX.js +0 -246
  226. package/dist/packem_shared/Card-D3tGkNCm.js +0 -24
  227. package/dist/packem_shared/Cell-DCg1kJY-.js +0 -48
  228. package/dist/packem_shared/Checkbox-Dpy_4Lws.js +0 -49
  229. package/dist/packem_shared/Code-CwzzbsLx.js +0 -53
  230. package/dist/packem_shared/Collapsible-BMDrXf5C.js +0 -45
  231. package/dist/packem_shared/CommandBlock-jdOGJPjY.js +0 -80
  232. package/dist/packem_shared/CommandPalette-B5IfUQwi.js +0 -146
  233. package/dist/packem_shared/ConfirmDialog-5XJv3Cc4.js +0 -67
  234. package/dist/packem_shared/ConfirmInput-CxUS0XAA.js +0 -44
  235. package/dist/packem_shared/ConsoleOverlay-BvnCEgjG.js +0 -57
  236. package/dist/packem_shared/ContentSwitcher-BHFpO5Za.js +0 -81
  237. package/dist/packem_shared/ControlledScrollView-C2wOOlJO.js +0 -5
  238. package/dist/packem_shared/Cursor-DiW7YoSK.js +0 -18
  239. package/dist/packem_shared/DatePicker-CPejKoqS.js +0 -73
  240. package/dist/packem_shared/DefinitionList-BAwr0l5J.js +0 -18
  241. package/dist/packem_shared/DevTools-BdxRSkhL.js +0 -63
  242. package/dist/packem_shared/Dialog-S9r7Izff.js +0 -71
  243. package/dist/packem_shared/DiffView-BR4T6-Sj.js +0 -329
  244. package/dist/packem_shared/Divider-DocXIqNn.js +0 -30
  245. package/dist/packem_shared/FilePicker-BZ55oF_n.js +0 -261
  246. package/dist/packem_shared/FocusContext-D5wFxSRz.js +0 -153
  247. package/dist/packem_shared/FormField-BSG16cnA.js +0 -29
  248. package/dist/packem_shared/Fullscreen-DO7voOq5.js +0 -11
  249. package/dist/packem_shared/Gauge-CKXUXxft.js +0 -122
  250. package/dist/packem_shared/Gradient-Dg0NezWc.js +0 -136
  251. package/dist/packem_shared/Heading-BnR7McmP.js +0 -29
  252. package/dist/packem_shared/Heatmap-_jqISOU0.js +0 -79
  253. package/dist/packem_shared/Help-0yZ_IcQg.js +0 -105
  254. package/dist/packem_shared/Histogram-CB6XcmZW.js +0 -92
  255. package/dist/packem_shared/IMECompositionBuffer-Dl3S0KnF.js +0 -55
  256. package/dist/packem_shared/InputParser-BlsfeY9J.js +0 -158
  257. package/dist/packem_shared/KEY-STOdi-nc.js +0 -74
  258. package/dist/packem_shared/Kbd-BNDXQgey.js +0 -19
  259. package/dist/packem_shared/LayoutNode-DAkKg9TE.js +0 -129
  260. package/dist/packem_shared/LineChart-ef3HF816.js +0 -7
  261. package/dist/packem_shared/Link-DZ2Tiq1m.js +0 -66
  262. package/dist/packem_shared/LoadingIndicator-DzbLGfyJ.js +0 -13
  263. package/dist/packem_shared/Markdown-33bpCUoe.js +0 -212
  264. package/dist/packem_shared/MaskedInput-Ctr6v2dO.js +0 -119
  265. package/dist/packem_shared/Menu-CeKxhEix.js +0 -112
  266. package/dist/packem_shared/MessageBubble-BMoU8L2Q.js +0 -26
  267. package/dist/packem_shared/ModelBadge-CNIxPs7v.js +0 -40
  268. package/dist/packem_shared/MouseProvider-CekPbXCh.js +0 -136
  269. package/dist/packem_shared/MultiSelect-yz7-w0Zv.js +0 -129
  270. package/dist/packem_shared/NAMED_COLORS-DcI3erCu.js +0 -300
  271. package/dist/packem_shared/Newline-DBtYEg8x.js +0 -7
  272. package/dist/packem_shared/OperationTree-Dudx5o1o.js +0 -67
  273. package/dist/packem_shared/OptionList-CTyqQaZ1.js +0 -24
  274. package/dist/packem_shared/OrderedList-VsvSmHUC.js +0 -26
  275. package/dist/packem_shared/Paginator-DmGogvEI.js +0 -104
  276. package/dist/packem_shared/Paragraph-CNNhfepo.js +0 -9
  277. package/dist/packem_shared/Placeholder-DkM69Q8Z.js +0 -29
  278. package/dist/packem_shared/ProgressBar-B7cS4uQm.js +0 -22
  279. package/dist/packem_shared/RadioGroup-B4F9PUyL.js +0 -108
  280. package/dist/packem_shared/Renderer-zZ5O3vxc.js +0 -31
  281. package/dist/packem_shared/ResizeObserverEntry-Vr8GZ74x.js +0 -102
  282. package/dist/packem_shared/ScatterPlot-CWOg4G5h.js +0 -63
  283. package/dist/packem_shared/ScrollBar-DFeWH43I.js +0 -106
  284. package/dist/packem_shared/ScrollBarBox-C7VL6Izd.js +0 -72
  285. package/dist/packem_shared/ScrollList-DRcr_RrN.js +0 -227
  286. package/dist/packem_shared/ScrollView-C6rdlGwU.js +0 -196
  287. package/dist/packem_shared/SearchInput-cB8zFhSg.js +0 -32
  288. package/dist/packem_shared/SelectInput-WzZSqp72.js +0 -260
  289. package/dist/packem_shared/SelectInputIndicator-DKeN6v5Z.js +0 -9
  290. package/dist/packem_shared/SelectInputItem-CxFL3spM.js +0 -8
  291. package/dist/packem_shared/ShimmerText-B2VbPUSB.js +0 -34
  292. package/dist/packem_shared/Slider-BOrNTOQe.js +0 -116
  293. package/dist/packem_shared/Spacer-DhmXyTb8.js +0 -8
  294. package/dist/packem_shared/Sparkline-BSbjPrwK.js +0 -44
  295. package/dist/packem_shared/Spinner-BcO5BCAa.js +0 -1942
  296. package/dist/packem_shared/Static-DpTd6Eed.js +0 -22
  297. package/dist/packem_shared/Static-xmD9giJj.js +0 -18
  298. package/dist/packem_shared/StaticRender-C3XWvJdC.js +0 -69
  299. package/dist/packem_shared/StatusLine-DQNUstN9.js +0 -22
  300. package/dist/packem_shared/StatusMessage-BYTL6Pl-.js +0 -14
  301. package/dist/packem_shared/Stepper-CmUPRK3z.js +0 -60
  302. package/dist/packem_shared/Stopwatch-zqLQAxXC.js +0 -21
  303. package/dist/packem_shared/StreamingText-BmuoJtGu.js +0 -38
  304. package/dist/packem_shared/Switch-DcPdy8nm.js +0 -59
  305. package/dist/packem_shared/Tab-C6r5q4hR.js +0 -7
  306. package/dist/packem_shared/Table-Bgxo87Df.js +0 -88
  307. package/dist/packem_shared/Tabs-DubuHdYV.js +0 -164
  308. package/dist/packem_shared/Tag-CCqM7Ee9.js +0 -35
  309. package/dist/packem_shared/Text-CtUwV89_.js +0 -65
  310. package/dist/packem_shared/TextInput-C9r7zT0U.js +0 -137
  311. package/dist/packem_shared/Textarea-CGmgt-Nl.js +0 -272
  312. package/dist/packem_shared/Timer-D7ZZ0_wz.js +0 -20
  313. package/dist/packem_shared/Toast-DXSCXFPY.js +0 -37
  314. package/dist/packem_shared/Tooltip-SvVjj-2k.js +0 -32
  315. package/dist/packem_shared/Transform-Cfyva2wd.js +0 -14
  316. package/dist/packem_shared/Transition-CbNfKhaj.js +0 -108
  317. package/dist/packem_shared/TreeNodeMap-CtJUvBnd.js +0 -155
  318. package/dist/packem_shared/TreeView-DGlZeSsK.js +0 -148
  319. package/dist/packem_shared/TuiApp-DtdgNRWa.js +0 -122
  320. package/dist/packem_shared/TuiContext-lXmJFd-x.js +0 -418
  321. package/dist/packem_shared/UnorderedList-D8RPaEAW.js +0 -33
  322. package/dist/packem_shared/accessibility-context-BLelHhNU.js +0 -7
  323. package/dist/packem_shared/animation-context-BcJg8Jr6.js +0 -15
  324. package/dist/packem_shared/ansi-parser-BOP8fNdT.js +0 -43
  325. package/dist/packem_shared/ansi-tokenizer-LHq2LUWA.js +0 -307
  326. package/dist/packem_shared/app-context-CP0U6H7O.js +0 -11
  327. package/dist/packem_shared/background-context-BAUaxfOb.js +0 -5
  328. package/dist/packem_shared/boxes-oi3WUbyR.js +0 -92
  329. package/dist/packem_shared/braille-BoEWoH2I.js +0 -93
  330. package/dist/packem_shared/colorize-88_Vk8cn.js +0 -48
  331. package/dist/packem_shared/comparePoints-CAAlhiMS.js +0 -287
  332. package/dist/packem_shared/controlled-scroll-view-DJXfdWMm.js +0 -286
  333. package/dist/packem_shared/createInlineLoop-Dnfm1ZSJ.js +0 -99
  334. package/dist/packem_shared/createLinkedScrollGroup-Djw4Ceo0.js +0 -44
  335. package/dist/packem_shared/createMemoryStorage-esFJ61La.js +0 -115
  336. package/dist/packem_shared/createScreen-Dh0sZlQ0.js +0 -38
  337. package/dist/packem_shared/cursor-context-JxRzlqAx.js +0 -9
  338. package/dist/packem_shared/dom-CrbpQgat.js +0 -228
  339. package/dist/packem_shared/focus-context-CWkYtgcm.js +0 -26
  340. package/dist/packem_shared/format-time-BGmnDukX.js +0 -12
  341. package/dist/packem_shared/getPathToRoot-BbvlppLC.js +0 -4
  342. package/dist/packem_shared/getScrollHeight-Cz3CDQN2.js +0 -63
  343. package/dist/packem_shared/input-utils-ViAEXa0Z.js +0 -19
  344. package/dist/packem_shared/isIntersecting-fEXHJN5R.js +0 -10
  345. package/dist/packem_shared/isOsc52Supported-G0k4sXJx.js +0 -36
  346. package/dist/packem_shared/isTerminalPaletteQuerySupported-EeiwMKbr.js +0 -93
  347. package/dist/packem_shared/kittyFlags-bNNf_9kX.js +0 -26
  348. package/dist/packem_shared/line-chart-VGU2l7pu.js +0 -139
  349. package/dist/packem_shared/measure-element-Bc6PEaIe.js +0 -405
  350. package/dist/packem_shared/measure-text-BdOhbOeh.js +0 -1256
  351. package/dist/packem_shared/measureElement-DTELRaij.js +0 -4
  352. package/dist/packem_shared/mouse-context-BUHWKEIe.js +0 -6
  353. package/dist/packem_shared/parseSgrMouse-4hpBJBsW.js +0 -1
  354. package/dist/packem_shared/processLayout-B0Coz0Ua.js +0 -2
  355. package/dist/packem_shared/reconciler-Dd7Z0A97.js +0 -696
  356. package/dist/packem_shared/reconciler-mzMwSOft.js +0 -221
  357. package/dist/packem_shared/render-Bm9Oa1sG.js +0 -2799
  358. package/dist/packem_shared/render-CjlKdg4m.js +0 -199
  359. package/dist/packem_shared/renderToString-CWYS1ZXE.js +0 -86
  360. package/dist/packem_shared/renderToString-DB3ILWFm.js +0 -62
  361. package/dist/packem_shared/renderTreeToBuffer-CDDTGyZn.js +0 -311
  362. package/dist/packem_shared/renderer-GE9OLNNM.js +0 -1437
  363. package/dist/packem_shared/setEnableStyledLineCache-D5f4favX.js +0 -2
  364. package/dist/packem_shared/squashTextNodesWithMap-iqm6OMMT.js +0 -100
  365. package/dist/packem_shared/stderr-context-Bj4Mf7v7.js +0 -17
  366. package/dist/packem_shared/stdin-context-Bq_GNJ3z.js +0 -38
  367. package/dist/packem_shared/stdout-context-CgjWeCdO.js +0 -17
  368. package/dist/packem_shared/text-width-Db-AxMea.js +0 -43
  369. package/dist/packem_shared/token-to-elements-CK4s8MJd.js +0 -249
  370. package/dist/packem_shared/treeViewTheme-BpSw9TMf.js +0 -52
  371. package/dist/packem_shared/useAnimation-DV22qxiJ.js +0 -62
  372. package/dist/packem_shared/useApp-Cbi788rV.js +0 -6
  373. package/dist/packem_shared/useBoxMetrics-_5icypir.js +0 -54
  374. package/dist/packem_shared/useClipboard-MNj6MNR-.js +0 -23
  375. package/dist/packem_shared/useColorBlindness-D_sTIhcb.js +0 -30
  376. package/dist/packem_shared/useConsoleCapture-Dvt7G1W1.js +0 -61
  377. package/dist/packem_shared/useCursor-DS6LjIgv.js +0 -19
  378. package/dist/packem_shared/useElementDimensions-CAoKitVD.js +0 -67
  379. package/dist/packem_shared/useFocus-DLoGQJd9.js +0 -37
  380. package/dist/packem_shared/useFocusManager-UeZWtnNc.js +0 -16
  381. package/dist/packem_shared/useForm-sQENbEuv.js +0 -88
  382. package/dist/packem_shared/useHotkey-D9giUX3q.js +0 -112
  383. package/dist/packem_shared/useInput-DKZbqMRc.js +0 -594
  384. package/dist/packem_shared/useInterval-CSXM8c2I.js +0 -32
  385. package/dist/packem_shared/useIsScreenReaderEnabled-BeoVqo1R.js +0 -9
  386. package/dist/packem_shared/useKeyBindings-S4fSIEAk.js +0 -66
  387. package/dist/packem_shared/useKeyChord-BmXGNuEO.js +0 -114
  388. package/dist/packem_shared/useMouseAction-C5gZ2nj7.js +0 -29
  389. package/dist/packem_shared/useMouseContext-D-rFy60Q.js +0 -12
  390. package/dist/packem_shared/useMousePosition-BHBJ-kBk.js +0 -25
  391. package/dist/packem_shared/useOnMouseClick--ZIyBOBO.js +0 -35
  392. package/dist/packem_shared/useOnMouseHover-26diuXUC.js +0 -32
  393. package/dist/packem_shared/useOnMouseState-NO_Kda_C.js +0 -13
  394. package/dist/packem_shared/usePaste-png73gvT.js +0 -35
  395. package/dist/packem_shared/useScrollAcceleration-R9LfrPVG.js +0 -73
  396. package/dist/packem_shared/useScrollInput-DfzRGQFe.js +0 -72
  397. package/dist/packem_shared/useStderr-BSWerMZ7.js +0 -6
  398. package/dist/packem_shared/useStdin-Rf0zPzVA.js +0 -7
  399. package/dist/packem_shared/useStdout-B5yRcg9N.js +0 -6
  400. package/dist/packem_shared/useStopwatch-C__Zu6hd.js +0 -33
  401. package/dist/packem_shared/useTerminalPalette-CtFG2JTq.js +0 -38
  402. package/dist/packem_shared/useTextBuffer-C8fEe9Ly.js +0 -398
  403. package/dist/packem_shared/useTextSelection-ChrYZXsn.js +0 -50
  404. package/dist/packem_shared/useTimeout-DuCqgWPX.js +0 -34
  405. package/dist/packem_shared/useTimer-DnBtbhB5.js +0 -46
  406. package/dist/packem_shared/useTreeView-mkN5Di7w.js +0 -101
  407. package/dist/packem_shared/useTreeViewState-BpS_KZ-K.js +0 -502
  408. package/dist/packem_shared/useWindowSize-D3UU41mv.js +0 -20
  409. package/dist/packem_shared/utils-BgdlrbOH.js +0 -140
  410. package/dist/packem_shared/variant-config-DSZoX5TM.js +0 -8
  411. package/dist/packem_shared/waitFor-Cv9M2jKA.js +0 -39
  412. package/dist/packem_shared/wrapOrTruncateStyledLine-49Mne3t3.js +0 -147
@@ -1,2799 +0,0 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
2
-
3
- const __cjs_require = __cjs_createRequire(import.meta.url);
4
-
5
- const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
-
7
- const __cjs_getBuiltinModule = (module) => {
8
- // Check if we're in Node.js and version supports getBuiltinModule
9
- if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
- const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
- // Node.js 20.16.0+ and 22.3.0+
12
- if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
- return __cjs_getProcess.getBuiltinModule(module);
14
- }
15
- }
16
- // Fallback to createRequire
17
- return __cjs_require(module);
18
- };
19
-
20
- const process$2 = __cjs_getProcess;
21
- const {
22
- env,
23
- cwd
24
- } = process$2;
25
- const {
26
- Stream
27
- } = __cjs_getBuiltinModule("node:stream");
28
- import { jsxs, jsx } from 'react/jsx-runtime';
29
- const {
30
- Buffer
31
- } = __cjs_getBuiltinModule("node:buffer");
32
- const {
33
- Console
34
- } = __cjs_getBuiltinModule("node:console");
35
- import { cursorShow, setMode, BracketedPasteMode, resetMode, cursorUp, cursorTo, cursorHide, cursorDown, eraseLines, cursorNextLine, eraseLineEnd, createDecMode, ALT_SCREEN_ON, clearScreenAndHomeCursor, ALT_SCREEN_OFF } from '@visulima/ansi';
36
- import { wordWrap } from '@visulima/string';
37
- import patchConsole from 'patch-console';
38
- import { ConcurrentRoot, LegacyRoot } from 'react-reconciler/constants.js';
39
- import Yoga from 'yoga-layout';
40
- import { a as accessibilityContext } from './accessibility-context-BLelHhNU.js';
41
- const {
42
- EventEmitter
43
- } = __cjs_getBuiltinModule("node:events");
44
- import { PureComponent, useState, useRef, useCallback, useEffect, useMemo } from 'react';
45
- import { a as animationContext } from './animation-context-BcJg8Jr6.js';
46
- import { A as AppContext } from './app-context-CP0U6H7O.js';
47
- import { C as CursorContext } from './cursor-context-JxRzlqAx.js';
48
- const {
49
- existsSync,
50
- readFileSync
51
- } = __cjs_getBuiltinModule("node:fs");
52
- const require$$1 = __cjs_getBuiltinModule("module");
53
- import Box from './Box-W1w_NGin.js';
54
- import Text from './Text-CtUwV89_.js';
55
- import { F as FocusContext } from './focus-context-CWkYtgcm.js';
56
- import { S as StderrContext } from './stderr-context-Bj4Mf7v7.js';
57
- import { S as StdinContext } from './stdin-context-Bq_GNJ3z.js';
58
- import { S as StdoutContext } from './stdout-context-CgjWeCdO.js';
59
- import { c as createNode } from './dom-CrbpQgat.js';
60
- import { resolveFlags } from './kittyFlags-bNNf_9kX.js';
61
- import { a as clearStyledLineCache } from './measure-text-BdOhbOeh.js';
62
- import { r as reconcilerInstance, s as styles } from './reconciler-Dd7Z0A97.js';
63
- import { a as renderToStatic, r as renderer } from './renderer-GE9OLNNM.js';
64
- import { measureAndExtractObservers } from './ResizeObserverEntry-Vr8GZ74x.js';
65
- import { calculateScroll } from './getScrollHeight-Cz3CDQN2.js';
66
- import { g as getWindowSize } from './utils-BgdlrbOH.js';
67
-
68
- import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
69
- const require = __cjs_mod__.createRequire(import.meta.url);
70
- function debounce$1(func, debounceMs, { signal, edges } = {}) {
71
- let pendingThis = void 0;
72
- let pendingArgs = null;
73
- const leading = edges != null && edges.includes("leading");
74
- const trailing = edges == null || edges.includes("trailing");
75
- const invoke = () => {
76
- if (pendingArgs !== null) {
77
- func.apply(pendingThis, pendingArgs);
78
- pendingThis = void 0;
79
- pendingArgs = null;
80
- }
81
- };
82
- const onTimerEnd = () => {
83
- if (trailing) {
84
- invoke();
85
- }
86
- cancel();
87
- };
88
- let timeoutId = null;
89
- const schedule = () => {
90
- if (timeoutId != null) {
91
- clearTimeout(timeoutId);
92
- }
93
- timeoutId = setTimeout(() => {
94
- timeoutId = null;
95
- onTimerEnd();
96
- }, debounceMs);
97
- };
98
- const cancelTimer = () => {
99
- if (timeoutId !== null) {
100
- clearTimeout(timeoutId);
101
- timeoutId = null;
102
- }
103
- };
104
- const cancel = () => {
105
- cancelTimer();
106
- pendingThis = void 0;
107
- pendingArgs = null;
108
- };
109
- const flush = () => {
110
- invoke();
111
- };
112
- const debounced = function(...args) {
113
- if (signal?.aborted) {
114
- return;
115
- }
116
- pendingThis = this;
117
- pendingArgs = args;
118
- const isFirstCall = timeoutId == null;
119
- schedule();
120
- if (leading && isFirstCall) {
121
- invoke();
122
- }
123
- };
124
- debounced.schedule = schedule;
125
- debounced.cancel = cancel;
126
- debounced.flush = flush;
127
- signal?.addEventListener("abort", cancel, { once: true });
128
- return debounced;
129
- }
130
-
131
- function debounce(func, debounceMs = 0, options = {}) {
132
- if (typeof options !== "object") {
133
- options = {};
134
- }
135
- const { leading = false, trailing = true, maxWait } = options;
136
- const edges = Array(2);
137
- if (leading) {
138
- edges[0] = "leading";
139
- }
140
- if (trailing) {
141
- edges[1] = "trailing";
142
- }
143
- let result = void 0;
144
- let pendingAt = null;
145
- const _debounced = debounce$1(function(...args) {
146
- result = func.apply(this, args);
147
- pendingAt = null;
148
- }, debounceMs, { edges });
149
- const debounced = function(...args) {
150
- if (maxWait != null) {
151
- if (pendingAt === null) {
152
- pendingAt = Date.now();
153
- }
154
- if (Date.now() - pendingAt >= maxWait) {
155
- result = func.apply(this, args);
156
- pendingAt = Date.now();
157
- _debounced.cancel();
158
- _debounced.schedule();
159
- return result;
160
- }
161
- }
162
- _debounced.apply(this, args);
163
- return result;
164
- };
165
- const flush = () => {
166
- _debounced.flush();
167
- return result;
168
- };
169
- debounced.cancel = _debounced.cancel;
170
- debounced.flush = flush;
171
- return debounced;
172
- }
173
-
174
- function throttle(func, throttleMs = 0, options = {}) {
175
- const { leading = true, trailing = true } = options;
176
- return debounce(func, throttleMs, {
177
- leading,
178
- maxWait: throttleMs,
179
- trailing
180
- });
181
- }
182
-
183
- const check = (key) => key in env && env[key] !== "0" && env[key] !== "false";
184
- const isInCi = check("CI") || check("CONTINUOUS_INTEGRATION");
185
-
186
- const signals = [];
187
- signals.push("SIGHUP", "SIGINT", "SIGTERM");
188
- if (process.platform !== "win32") {
189
- signals.push(
190
- "SIGALRM",
191
- "SIGABRT",
192
- "SIGVTALRM",
193
- "SIGXCPU",
194
- "SIGXFSZ",
195
- "SIGUSR2",
196
- "SIGTRAP",
197
- "SIGSYS",
198
- "SIGQUIT",
199
- "SIGIOT"
200
- // should detect profiler and enable/disable accordingly.
201
- // see #21
202
- // 'SIGPROF'
203
- );
204
- }
205
- if (process.platform === "linux") {
206
- signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
207
- }
208
-
209
- const processOk = (process2) => !!process2 && true && typeof process2.removeListener === "function" && typeof process2.emit === "function" && typeof process2.reallyExit === "function" && typeof process2.listeners === "function" && typeof process2.kill === "function" && typeof process2.pid === "number" && typeof process2.on === "function";
210
- const kExitEmitter = /* @__PURE__ */ Symbol.for("signal-exit emitter");
211
- const global = globalThis;
212
- const ObjectDefineProperty = Object.defineProperty.bind(Object);
213
- class Emitter {
214
- emitted = {
215
- afterExit: false,
216
- exit: false
217
- };
218
- listeners = {
219
- afterExit: [],
220
- exit: []
221
- };
222
- count = 0;
223
- id = Math.random();
224
- constructor() {
225
- if (global[kExitEmitter]) {
226
- return global[kExitEmitter];
227
- }
228
- ObjectDefineProperty(global, kExitEmitter, {
229
- value: this,
230
- writable: false,
231
- enumerable: false,
232
- configurable: false
233
- });
234
- }
235
- on(ev, fn) {
236
- this.listeners[ev].push(fn);
237
- }
238
- removeListener(ev, fn) {
239
- const list = this.listeners[ev];
240
- const i = list.indexOf(fn);
241
- if (i === -1) {
242
- return;
243
- }
244
- if (i === 0 && list.length === 1) {
245
- list.length = 0;
246
- } else {
247
- list.splice(i, 1);
248
- }
249
- }
250
- emit(ev, code, signal) {
251
- if (this.emitted[ev]) {
252
- return false;
253
- }
254
- this.emitted[ev] = true;
255
- let ret = false;
256
- for (const fn of this.listeners[ev]) {
257
- ret = fn(code, signal) === true || ret;
258
- }
259
- if (ev === "exit") {
260
- ret = this.emit("afterExit", code, signal) || ret;
261
- }
262
- return ret;
263
- }
264
- }
265
- class SignalExitBase {
266
- }
267
- const signalExitWrap = (handler) => {
268
- return {
269
- onExit(cb, opts) {
270
- return handler.onExit(cb, opts);
271
- },
272
- load() {
273
- return handler.load();
274
- },
275
- unload() {
276
- return handler.unload();
277
- }
278
- };
279
- };
280
- class SignalExitFallback extends SignalExitBase {
281
- onExit() {
282
- return () => {
283
- };
284
- }
285
- load() {
286
- }
287
- unload() {
288
- }
289
- }
290
- class SignalExit extends SignalExitBase {
291
- // "SIGHUP" throws an `ENOSYS` error on Windows,
292
- // so use a supported signal instead
293
- /* c8 ignore start */
294
- #hupSig = process$1.platform === "win32" ? "SIGINT" : "SIGHUP";
295
- /* c8 ignore stop */
296
- #emitter = new Emitter();
297
- #process;
298
- #originalProcessEmit;
299
- #originalProcessReallyExit;
300
- #sigListeners = {};
301
- #loaded = false;
302
- constructor(process2) {
303
- super();
304
- this.#process = process2;
305
- this.#sigListeners = {};
306
- for (const sig of signals) {
307
- this.#sigListeners[sig] = () => {
308
- const listeners = this.#process.listeners(sig);
309
- let { count } = this.#emitter;
310
- const p = process2;
311
- if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") {
312
- count += p.__signal_exit_emitter__.count;
313
- }
314
- if (listeners.length === count) {
315
- this.unload();
316
- const ret = this.#emitter.emit("exit", null, sig);
317
- const s = sig === "SIGHUP" ? this.#hupSig : sig;
318
- if (!ret)
319
- process2.kill(process2.pid, s);
320
- }
321
- };
322
- }
323
- this.#originalProcessReallyExit = process2.reallyExit;
324
- this.#originalProcessEmit = process2.emit;
325
- }
326
- onExit(cb, opts) {
327
- if (!processOk(this.#process)) {
328
- return () => {
329
- };
330
- }
331
- if (this.#loaded === false) {
332
- this.load();
333
- }
334
- const ev = opts?.alwaysLast ? "afterExit" : "exit";
335
- this.#emitter.on(ev, cb);
336
- return () => {
337
- this.#emitter.removeListener(ev, cb);
338
- if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) {
339
- this.unload();
340
- }
341
- };
342
- }
343
- load() {
344
- if (this.#loaded) {
345
- return;
346
- }
347
- this.#loaded = true;
348
- this.#emitter.count += 1;
349
- for (const sig of signals) {
350
- try {
351
- const fn = this.#sigListeners[sig];
352
- if (fn)
353
- this.#process.on(sig, fn);
354
- } catch (_) {
355
- }
356
- }
357
- this.#process.emit = (ev, ...a) => {
358
- return this.#processEmit(ev, ...a);
359
- };
360
- this.#process.reallyExit = (code) => {
361
- return this.#processReallyExit(code);
362
- };
363
- }
364
- unload() {
365
- if (!this.#loaded) {
366
- return;
367
- }
368
- this.#loaded = false;
369
- signals.forEach((sig) => {
370
- const listener = this.#sigListeners[sig];
371
- if (!listener) {
372
- throw new Error("Listener not defined for signal: " + sig);
373
- }
374
- try {
375
- this.#process.removeListener(sig, listener);
376
- } catch (_) {
377
- }
378
- });
379
- this.#process.emit = this.#originalProcessEmit;
380
- this.#process.reallyExit = this.#originalProcessReallyExit;
381
- this.#emitter.count -= 1;
382
- }
383
- #processReallyExit(code) {
384
- if (!processOk(this.#process)) {
385
- return 0;
386
- }
387
- this.#process.exitCode = code || 0;
388
- this.#emitter.emit("exit", this.#process.exitCode, null);
389
- return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
390
- }
391
- #processEmit(ev, ...args) {
392
- const og = this.#originalProcessEmit;
393
- if (ev === "exit" && processOk(this.#process)) {
394
- if (typeof args[0] === "number") {
395
- this.#process.exitCode = args[0];
396
- }
397
- const ret = og.call(this.#process, ev, ...args);
398
- this.#emitter.emit("exit", this.#process.exitCode, null);
399
- return ret;
400
- } else {
401
- return og.call(this.#process, ev, ...args);
402
- }
403
- }
404
- }
405
- const process$1 = globalThis.process;
406
- const {
407
- /**
408
- * Called when the process is exiting, whether via signal, explicit
409
- * exit, or running out of stuff to do.
410
- *
411
- * If the global process object is not suitable for instrumentation,
412
- * then this will be a no-op.
413
- *
414
- * Returns a function that may be used to unload signal-exit.
415
- */
416
- onExit} = signalExitWrap(processOk(process$1) ? new SignalExit(process$1) : new SignalExitFallback());
417
-
418
- const escape$1 = "\x1B";
419
- const pasteStart = "\x1B[200~";
420
- const pasteEnd = "\x1B[201~";
421
- const isCsiParameterByte = (byte) => byte >= 48 && byte <= 63;
422
- const isCsiIntermediateByte = (byte) => byte >= 32 && byte <= 47;
423
- const isCsiFinalByte = (byte) => byte >= 64 && byte <= 126;
424
- const parseCsiSequence = (input, startIndex, prefixLength) => {
425
- const csiPayloadStart = startIndex + prefixLength + 1;
426
- let index = csiPayloadStart;
427
- for (; index < input.length; index++) {
428
- const byte = input.codePointAt(index);
429
- if (byte === void 0) {
430
- return "pending";
431
- }
432
- if (isCsiParameterByte(byte) || isCsiIntermediateByte(byte)) {
433
- continue;
434
- }
435
- if (byte === 91 && index === csiPayloadStart) {
436
- continue;
437
- }
438
- if (isCsiFinalByte(byte)) {
439
- return {
440
- nextIndex: index + 1,
441
- sequence: input.slice(startIndex, index + 1)
442
- };
443
- }
444
- return void 0;
445
- }
446
- return "pending";
447
- };
448
- const parseSs3Sequence = (input, startIndex, prefixLength) => {
449
- const nextIndex = startIndex + prefixLength + 2;
450
- if (nextIndex > input.length) {
451
- return "pending";
452
- }
453
- const finalByte = input.codePointAt(nextIndex - 1);
454
- if (finalByte === void 0 || !isCsiFinalByte(finalByte)) {
455
- return void 0;
456
- }
457
- return {
458
- nextIndex,
459
- sequence: input.slice(startIndex, nextIndex)
460
- };
461
- };
462
- const parseControlSequence = (input, startIndex, prefixLength) => {
463
- const sequenceType = input[startIndex + prefixLength];
464
- if (sequenceType === void 0) {
465
- return "pending";
466
- }
467
- if (sequenceType === "[") {
468
- return parseCsiSequence(input, startIndex, prefixLength);
469
- }
470
- if (sequenceType === "O") {
471
- return parseSs3Sequence(input, startIndex, prefixLength);
472
- }
473
- return void 0;
474
- };
475
- const parseEscapedCodePoint = (input, escapeIndex) => {
476
- const nextCodePoint = input.codePointAt(escapeIndex + 1);
477
- const nextCodePointLength = nextCodePoint !== void 0 && nextCodePoint > 65535 ? 2 : 1;
478
- const nextIndex = escapeIndex + 1 + nextCodePointLength;
479
- return {
480
- nextIndex,
481
- sequence: input.slice(escapeIndex, nextIndex)
482
- };
483
- };
484
- const parseEscapeSequence = (input, escapeIndex) => {
485
- if (escapeIndex === input.length - 1) {
486
- return "pending";
487
- }
488
- const next = input[escapeIndex + 1];
489
- if (next === escape$1) {
490
- if (escapeIndex + 2 >= input.length) {
491
- return "pending";
492
- }
493
- const doubleEscapeSequence = parseControlSequence(input, escapeIndex, 2);
494
- if (doubleEscapeSequence === "pending") {
495
- return "pending";
496
- }
497
- if (doubleEscapeSequence) {
498
- return doubleEscapeSequence;
499
- }
500
- return {
501
- nextIndex: escapeIndex + 2,
502
- sequence: input.slice(escapeIndex, escapeIndex + 2)
503
- };
504
- }
505
- const controlSequence = parseControlSequence(input, escapeIndex, 1);
506
- if (controlSequence === "pending") {
507
- return "pending";
508
- }
509
- if (controlSequence) {
510
- return controlSequence;
511
- }
512
- return parseEscapedCodePoint(input, escapeIndex);
513
- };
514
- const splitDeleteAndBackspace = (text, events) => {
515
- let textSegmentStart = 0;
516
- for (let index = 0; index < text.length; index++) {
517
- const character = text[index];
518
- if (character === "" || character === "\b") {
519
- if (index > textSegmentStart) {
520
- events.push(text.slice(textSegmentStart, index));
521
- }
522
- events.push(character);
523
- textSegmentStart = index + 1;
524
- }
525
- }
526
- if (textSegmentStart < text.length) {
527
- events.push(text.slice(textSegmentStart));
528
- }
529
- };
530
- const parseKeypresses = (input) => {
531
- const events = [];
532
- let index = 0;
533
- const pendingFrom = (pendingStartIndex) => {
534
- return {
535
- events,
536
- pending: input.slice(pendingStartIndex)
537
- };
538
- };
539
- while (index < input.length) {
540
- const escapeIndex = input.indexOf(escape$1, index);
541
- if (escapeIndex === -1) {
542
- splitDeleteAndBackspace(input.slice(index), events);
543
- return {
544
- events,
545
- pending: ""
546
- };
547
- }
548
- if (escapeIndex > index) {
549
- splitDeleteAndBackspace(input.slice(index, escapeIndex), events);
550
- }
551
- const parsedEscapeSequence = parseEscapeSequence(input, escapeIndex);
552
- if (parsedEscapeSequence === "pending") {
553
- return pendingFrom(escapeIndex);
554
- }
555
- if (parsedEscapeSequence.sequence === pasteStart) {
556
- const afterStart = parsedEscapeSequence.nextIndex;
557
- const endIndex = input.indexOf(pasteEnd, afterStart);
558
- if (endIndex === -1) {
559
- return pendingFrom(escapeIndex);
560
- }
561
- events.push({ paste: input.slice(afterStart, endIndex) });
562
- index = endIndex + pasteEnd.length;
563
- continue;
564
- }
565
- events.push(parsedEscapeSequence.sequence);
566
- index = parsedEscapeSequence.nextIndex;
567
- }
568
- return {
569
- events,
570
- pending: ""
571
- };
572
- };
573
- const createInputParser = () => {
574
- let pending = "";
575
- return {
576
- flushPendingEscape() {
577
- if (!pending.startsWith(escape$1)) {
578
- return void 0;
579
- }
580
- const pendingEscape = pending;
581
- pending = "";
582
- return pendingEscape;
583
- },
584
- hasPendingEscape() {
585
- return pending.startsWith(escape$1) && !pending.startsWith(pasteStart) && pending !== "\x1B[200";
586
- },
587
- push(chunk) {
588
- const parsedInput = parseKeypresses(pending + chunk);
589
- pending = parsedInput.pending;
590
- return parsedInput.events;
591
- },
592
- reset() {
593
- pending = "";
594
- }
595
- };
596
- };
597
-
598
- const convertToSpaces = (input, spaces = 2) => {
599
- return input.replace(/^\t+/gm, ($1) => " ".repeat($1.length * spaces));
600
- };
601
-
602
- const generateLineNumbers = (line, around) => {
603
- const lineNumbers = [];
604
- const min = line - around;
605
- const max = line + around;
606
- for (let lineNumber = min; lineNumber <= max; lineNumber++) {
607
- lineNumbers.push(lineNumber);
608
- }
609
- return lineNumbers;
610
- };
611
- const codeExcerpt = (source, line, options = {}) => {
612
- var _a;
613
- if (typeof source !== "string") {
614
- throw new TypeError("Source code is missing.");
615
- }
616
- if (!line || line < 1) {
617
- throw new TypeError("Line number must start from `1`.");
618
- }
619
- const lines = convertToSpaces(source).split(/\r?\n/);
620
- if (line > lines.length) {
621
- return;
622
- }
623
- return generateLineNumbers(line, (_a = options.around) !== null && _a !== void 0 ? _a : 3).filter((line2) => lines[line2 - 1] !== void 0).map((line2) => ({ line: line2, value: lines[line2 - 1] }));
624
- };
625
-
626
- function getDefaultExportFromCjs(x) {
627
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
628
- }
629
-
630
- var escapeStringRegexp;
631
- var hasRequiredEscapeStringRegexp;
632
-
633
- function requireEscapeStringRegexp () {
634
- if (hasRequiredEscapeStringRegexp) return escapeStringRegexp;
635
- hasRequiredEscapeStringRegexp = 1;
636
- const matchOperatorsRegex = /[|\\{}()[\]^$+*?.-]/g;
637
- escapeStringRegexp = (string) => {
638
- if (typeof string !== "string") {
639
- throw new TypeError("Expected a string");
640
- }
641
- return string.replace(matchOperatorsRegex, "\\$&");
642
- };
643
- return escapeStringRegexp;
644
- }
645
-
646
- var stackUtils$1;
647
- var hasRequiredStackUtils;
648
-
649
- function requireStackUtils () {
650
- if (hasRequiredStackUtils) return stackUtils$1;
651
- hasRequiredStackUtils = 1;
652
- const escapeStringRegexp = requireEscapeStringRegexp();
653
- const cwd = process && typeof process.cwd === "function" ? process.cwd() : ".";
654
- const natives = [].concat(
655
- require$$1.builtinModules,
656
- "bootstrap_node",
657
- "node"
658
- ).map((n) => new RegExp(`(?:\\((?:node:)?${n}(?:\\.js)?:\\d+:\\d+\\)$|^\\s*at (?:node:)?${n}(?:\\.js)?:\\d+:\\d+$)`));
659
- natives.push(
660
- /\((?:node:)?internal\/[^:]+:\d+:\d+\)$/,
661
- /\s*at (?:node:)?internal\/[^:]+:\d+:\d+$/,
662
- /\/\.node-spawn-wrap-\w+-\w+\/node:\d+:\d+\)?$/
663
- );
664
- class StackUtils {
665
- constructor(opts) {
666
- opts = {
667
- ignoredPackages: [],
668
- ...opts
669
- };
670
- if ("internals" in opts === false) {
671
- opts.internals = StackUtils.nodeInternals();
672
- }
673
- if ("cwd" in opts === false) {
674
- opts.cwd = cwd;
675
- }
676
- this._cwd = opts.cwd.replace(/\\/g, "/");
677
- this._internals = [].concat(
678
- opts.internals,
679
- ignoredPackagesRegExp(opts.ignoredPackages)
680
- );
681
- this._wrapCallSite = opts.wrapCallSite || false;
682
- }
683
- static nodeInternals() {
684
- return [...natives];
685
- }
686
- clean(stack, indent = 0) {
687
- indent = " ".repeat(indent);
688
- if (!Array.isArray(stack)) {
689
- stack = stack.split("\n");
690
- }
691
- if (!/^\s*at /.test(stack[0]) && /^\s*at /.test(stack[1])) {
692
- stack = stack.slice(1);
693
- }
694
- let outdent = false;
695
- let lastNonAtLine = null;
696
- const result = [];
697
- stack.forEach((st) => {
698
- st = st.replace(/\\/g, "/");
699
- if (this._internals.some((internal) => internal.test(st))) {
700
- return;
701
- }
702
- const isAtLine = /^\s*at /.test(st);
703
- if (outdent) {
704
- st = st.trimEnd().replace(/^(\s+)at /, "$1");
705
- } else {
706
- st = st.trim();
707
- if (isAtLine) {
708
- st = st.slice(3);
709
- }
710
- }
711
- st = st.replace(`${this._cwd}/`, "");
712
- if (st) {
713
- if (isAtLine) {
714
- if (lastNonAtLine) {
715
- result.push(lastNonAtLine);
716
- lastNonAtLine = null;
717
- }
718
- result.push(st);
719
- } else {
720
- outdent = true;
721
- lastNonAtLine = st;
722
- }
723
- }
724
- });
725
- return result.map((line) => `${indent}${line}
726
- `).join("");
727
- }
728
- captureString(limit, fn = this.captureString) {
729
- if (typeof limit === "function") {
730
- fn = limit;
731
- limit = Infinity;
732
- }
733
- const { stackTraceLimit } = Error;
734
- if (limit) {
735
- Error.stackTraceLimit = limit;
736
- }
737
- const obj = {};
738
- Error.captureStackTrace(obj, fn);
739
- const { stack } = obj;
740
- Error.stackTraceLimit = stackTraceLimit;
741
- return this.clean(stack);
742
- }
743
- capture(limit, fn = this.capture) {
744
- if (typeof limit === "function") {
745
- fn = limit;
746
- limit = Infinity;
747
- }
748
- const { prepareStackTrace, stackTraceLimit } = Error;
749
- Error.prepareStackTrace = (obj2, site) => {
750
- if (this._wrapCallSite) {
751
- return site.map(this._wrapCallSite);
752
- }
753
- return site;
754
- };
755
- if (limit) {
756
- Error.stackTraceLimit = limit;
757
- }
758
- const obj = {};
759
- Error.captureStackTrace(obj, fn);
760
- const { stack } = obj;
761
- Object.assign(Error, { prepareStackTrace, stackTraceLimit });
762
- return stack;
763
- }
764
- at(fn = this.at) {
765
- const [site] = this.capture(1, fn);
766
- if (!site) {
767
- return {};
768
- }
769
- const res = {
770
- line: site.getLineNumber(),
771
- column: site.getColumnNumber()
772
- };
773
- setFile(res, site.getFileName(), this._cwd);
774
- if (site.isConstructor()) {
775
- Object.defineProperty(res, "constructor", {
776
- value: true,
777
- configurable: true
778
- });
779
- }
780
- if (site.isEval()) {
781
- res.evalOrigin = site.getEvalOrigin();
782
- }
783
- if (site.isNative()) {
784
- res.native = true;
785
- }
786
- let typename;
787
- try {
788
- typename = site.getTypeName();
789
- } catch (_) {
790
- }
791
- if (typename && typename !== "Object" && typename !== "[object Object]") {
792
- res.type = typename;
793
- }
794
- const fname = site.getFunctionName();
795
- if (fname) {
796
- res.function = fname;
797
- }
798
- const meth = site.getMethodName();
799
- if (meth && fname !== meth) {
800
- res.method = meth;
801
- }
802
- return res;
803
- }
804
- parseLine(line) {
805
- const match = line && line.match(re);
806
- if (!match) {
807
- return null;
808
- }
809
- const ctor = match[1] === "new";
810
- let fname = match[2];
811
- const evalOrigin = match[3];
812
- const evalFile = match[4];
813
- const evalLine = Number(match[5]);
814
- const evalCol = Number(match[6]);
815
- let file = match[7];
816
- const lnum = match[8];
817
- const col = match[9];
818
- const native = match[10] === "native";
819
- const closeParen = match[11] === ")";
820
- let method;
821
- const res = {};
822
- if (lnum) {
823
- res.line = Number(lnum);
824
- }
825
- if (col) {
826
- res.column = Number(col);
827
- }
828
- if (closeParen && file) {
829
- let closes = 0;
830
- for (let i = file.length - 1; i > 0; i--) {
831
- if (file.charAt(i) === ")") {
832
- closes++;
833
- } else if (file.charAt(i) === "(" && file.charAt(i - 1) === " ") {
834
- closes--;
835
- if (closes === -1 && file.charAt(i - 1) === " ") {
836
- const before = file.slice(0, i - 1);
837
- const after = file.slice(i + 1);
838
- file = after;
839
- fname += ` (${before}`;
840
- break;
841
- }
842
- }
843
- }
844
- }
845
- if (fname) {
846
- const methodMatch = fname.match(methodRe);
847
- if (methodMatch) {
848
- fname = methodMatch[1];
849
- method = methodMatch[2];
850
- }
851
- }
852
- setFile(res, file, this._cwd);
853
- if (ctor) {
854
- Object.defineProperty(res, "constructor", {
855
- value: true,
856
- configurable: true
857
- });
858
- }
859
- if (evalOrigin) {
860
- res.evalOrigin = evalOrigin;
861
- res.evalLine = evalLine;
862
- res.evalColumn = evalCol;
863
- res.evalFile = evalFile && evalFile.replace(/\\/g, "/");
864
- }
865
- if (native) {
866
- res.native = true;
867
- }
868
- if (fname) {
869
- res.function = fname;
870
- }
871
- if (method && fname !== method) {
872
- res.method = method;
873
- }
874
- return res;
875
- }
876
- }
877
- function setFile(result, filename, cwd2) {
878
- if (filename) {
879
- filename = filename.replace(/\\/g, "/");
880
- if (filename.startsWith(`${cwd2}/`)) {
881
- filename = filename.slice(cwd2.length + 1);
882
- }
883
- result.file = filename;
884
- }
885
- }
886
- function ignoredPackagesRegExp(ignoredPackages) {
887
- if (ignoredPackages.length === 0) {
888
- return [];
889
- }
890
- const packages = ignoredPackages.map((mod) => escapeStringRegexp(mod));
891
- return new RegExp(`[/\\\\]node_modules[/\\\\](?:${packages.join("|")})[/\\\\][^:]+:\\d+:\\d+`);
892
- }
893
- const re = new RegExp(
894
- "^(?:\\s*at )?(?:(new) )?(?:(.*?) \\()?(?:eval at ([^ ]+) \\((.+?):(\\d+):(\\d+)\\), )?(?:(.+?):(\\d+):(\\d+)|(native))(\\)?)$"
895
- );
896
- const methodRe = /^(.*?) \[as (.*?)\]$/;
897
- stackUtils$1 = StackUtils;
898
- return stackUtils$1;
899
- }
900
-
901
- var stackUtilsExports = requireStackUtils();
902
- const StackUtils = /*@__PURE__*/getDefaultExportFromCjs(stackUtilsExports);
903
-
904
- const cleanupPath = (path) => path?.replace(`file://${cwd()}/`, "");
905
- const stackUtils = new StackUtils({
906
- cwd: cwd(),
907
- internals: StackUtils.nodeInternals()
908
- });
909
- function ErrorOverview({ error }) {
910
- const stack = error.stack ? error.stack.split("\n").slice(1) : void 0;
911
- const origin = stack ? stackUtils.parseLine(stack[0]) : void 0;
912
- const filePath = cleanupPath(origin?.file);
913
- let excerpt;
914
- let lineWidth = 0;
915
- if (filePath && origin?.line && existsSync(filePath)) {
916
- const sourceCode = readFileSync(filePath, "utf8");
917
- excerpt = codeExcerpt(sourceCode, origin.line);
918
- if (excerpt) {
919
- for (const { line } of excerpt) {
920
- lineWidth = Math.max(lineWidth, String(line).length);
921
- }
922
- }
923
- }
924
- return jsxs(Box, { flexDirection: "column", padding: 1, children: [
925
- jsxs(Box, { children: [
926
- jsxs(Text, { backgroundColor: "red", color: "white", children: [
927
- " ",
928
- "ERROR",
929
- " "
930
- ] }),
931
- jsxs(Text, { children: [
932
- " ",
933
- error.message
934
- ] })
935
- ] }),
936
- origin && filePath ? jsx(Box, { marginTop: 1, children: jsxs(Text, { dimColor: true, children: [
937
- filePath,
938
- ":",
939
- origin.line,
940
- ":",
941
- origin.column
942
- ] }) }) : null,
943
- origin && excerpt ? jsx(Box, { flexDirection: "column", marginTop: 1, children: excerpt.map(({ line, value }) => jsxs(Box, { children: [
944
- jsx(Box, { width: lineWidth + 1, children: jsxs(
945
- Text,
946
- {
947
- "aria-label": line === origin.line ? `Line ${line}, error` : `Line ${line}`,
948
- backgroundColor: line === origin.line ? "red" : void 0,
949
- color: line === origin.line ? "white" : void 0,
950
- dimColor: line !== origin.line,
951
- children: [
952
- String(line).padStart(lineWidth, " "),
953
- ":"
954
- ]
955
- }
956
- ) }),
957
- jsx(Text, { backgroundColor: line === origin.line ? "red" : void 0, color: line === origin.line ? "white" : void 0, children: ` ${value}` }, line)
958
- ] }, line)) }) : null,
959
- stack ? jsx(Box, { flexDirection: "column", marginTop: 1, children: stack.map((line) => {
960
- const parsedLine = stackUtils.parseLine(line);
961
- if (!parsedLine) {
962
- return jsxs(Box, { children: [
963
- jsx(Text, { dimColor: true, children: "- " }),
964
- jsxs(Text, { bold: true, dimColor: true, children: [
965
- line,
966
- "\\t",
967
- " "
968
- ] })
969
- ] }, line);
970
- }
971
- return jsxs(Box, { children: [
972
- jsx(Text, { dimColor: true, children: "- " }),
973
- jsx(Text, { bold: true, dimColor: true, children: parsedLine.function }),
974
- jsxs(
975
- Text,
976
- {
977
- "aria-label": `at ${cleanupPath(parsedLine.file) ?? ""} line ${parsedLine.line} column ${parsedLine.column}`,
978
- color: "gray",
979
- dimColor: true,
980
- children: [
981
- " ",
982
- "(",
983
- cleanupPath(parsedLine.file) ?? "",
984
- ":",
985
- parsedLine.line,
986
- ":",
987
- parsedLine.column,
988
- ")"
989
- ]
990
- }
991
- )
992
- ] }, line);
993
- }) }) : null
994
- ] });
995
- }
996
-
997
- class ErrorBoundary extends PureComponent {
998
- static displayName = "InternalErrorBoundary";
999
- static getDerivedStateFromError(error) {
1000
- return { error };
1001
- }
1002
- state = {
1003
- error: void 0
1004
- };
1005
- componentDidCatch(error) {
1006
- this.props.onError(error);
1007
- }
1008
- render() {
1009
- if (this.state.error) {
1010
- return jsx(ErrorOverview, { error: this.state.error });
1011
- }
1012
- return this.props.children;
1013
- }
1014
- }
1015
-
1016
- const tab = " ";
1017
- const shiftTab = "\x1B[Z";
1018
- const escape = "\x1B";
1019
- const enableBracketedPaste = setMode(BracketedPasteMode);
1020
- const disableBracketedPaste = resetMode(BracketedPasteMode);
1021
- const App = ({
1022
- children,
1023
- exitOnCtrlC,
1024
- interactive,
1025
- onExit,
1026
- onWaitUntilRenderFlush,
1027
- renderThrottleMs,
1028
- setCursorPosition,
1029
- stderr,
1030
- stdin,
1031
- stdout,
1032
- writeToStderr,
1033
- writeToStdout
1034
- }) => {
1035
- const [isFocusEnabled, setIsFocusEnabled] = useState(true);
1036
- const [activeFocusId, setActiveFocusId] = useState(void 0);
1037
- const [, setFocusables] = useState([]);
1038
- const focusablesCountRef = useRef(0);
1039
- const animationSubscribersRef = useRef(/* @__PURE__ */ new Map());
1040
- const animationTimerRef = useRef(void 0);
1041
- const rawModeEnabledCount = useRef(0);
1042
- const bracketedPasteModeEnabledCount = useRef(0);
1043
- const [internal_eventEmitter] = useState(() => {
1044
- const emitter = new EventEmitter();
1045
- emitter.setMaxListeners(Infinity);
1046
- return emitter;
1047
- });
1048
- const readableListenerRef = useRef(void 0);
1049
- const inputParserRef = useRef(void 0);
1050
- inputParserRef.current ??= createInputParser();
1051
- const pendingInputFlushRef = useRef(void 0);
1052
- const didWarnAboutDeprecatedPasteFallbackRef = useRef(false);
1053
- const pendingInputFlushDelayMilliseconds = 20;
1054
- const clearPendingInputFlush = useCallback(() => {
1055
- if (!pendingInputFlushRef.current) {
1056
- return;
1057
- }
1058
- clearTimeout(pendingInputFlushRef.current);
1059
- pendingInputFlushRef.current = void 0;
1060
- }, []);
1061
- const clearAnimationTimer = useCallback(() => {
1062
- if (!animationTimerRef.current) {
1063
- return;
1064
- }
1065
- clearTimeout(animationTimerRef.current);
1066
- animationTimerRef.current = void 0;
1067
- }, []);
1068
- const scheduleAnimationTick = useCallback(() => {
1069
- clearAnimationTimer();
1070
- if (animationSubscribersRef.current.size === 0) {
1071
- return;
1072
- }
1073
- let nextDueTime = Number.POSITIVE_INFINITY;
1074
- for (const subscriber of animationSubscribersRef.current.values()) {
1075
- nextDueTime = Math.min(nextDueTime, subscriber.nextDueTime);
1076
- }
1077
- const delay = Math.max(0, nextDueTime - performance.now());
1078
- animationTimerRef.current = setTimeout(() => {
1079
- animationTimerRef.current = void 0;
1080
- const currentTime = performance.now();
1081
- const subscribers = [...animationSubscribersRef.current.values()];
1082
- for (const subscriber of subscribers) {
1083
- if (currentTime < subscriber.nextDueTime) {
1084
- continue;
1085
- }
1086
- subscriber.callback(currentTime);
1087
- const elapsedTime = currentTime - subscriber.startTime;
1088
- const elapsedFrames = Math.floor(elapsedTime / subscriber.interval) + 1;
1089
- subscriber.nextDueTime = subscriber.startTime + elapsedFrames * subscriber.interval;
1090
- }
1091
- scheduleAnimationTick();
1092
- }, delay);
1093
- }, [clearAnimationTimer]);
1094
- const animationSubscribe = useCallback(
1095
- (callback, interval) => {
1096
- const startTime = performance.now();
1097
- animationSubscribersRef.current.set(callback, {
1098
- callback,
1099
- interval,
1100
- nextDueTime: startTime + interval,
1101
- startTime
1102
- });
1103
- scheduleAnimationTick();
1104
- return {
1105
- startTime,
1106
- unsubscribe() {
1107
- animationSubscribersRef.current.delete(callback);
1108
- if (animationSubscribersRef.current.size === 0) {
1109
- clearAnimationTimer();
1110
- return;
1111
- }
1112
- scheduleAnimationTick();
1113
- }
1114
- };
1115
- },
1116
- [clearAnimationTimer, scheduleAnimationTick]
1117
- );
1118
- useEffect(
1119
- () => () => {
1120
- clearAnimationTimer();
1121
- },
1122
- [clearAnimationTimer]
1123
- );
1124
- const isRawModeSupported = stdin.isTTY;
1125
- const detachReadableListener = useCallback(() => {
1126
- if (!readableListenerRef.current) {
1127
- return;
1128
- }
1129
- stdin.removeListener("readable", readableListenerRef.current);
1130
- readableListenerRef.current = void 0;
1131
- }, [stdin]);
1132
- const disableRawMode = useCallback(() => {
1133
- stdin.setRawMode(false);
1134
- detachReadableListener();
1135
- stdin.unref();
1136
- rawModeEnabledCount.current = 0;
1137
- inputParserRef.current?.reset();
1138
- clearPendingInputFlush();
1139
- }, [stdin, detachReadableListener, clearPendingInputFlush]);
1140
- const handleExit = useCallback(
1141
- (errorOrResult) => {
1142
- if (isRawModeSupported && rawModeEnabledCount.current > 0) {
1143
- disableRawMode();
1144
- }
1145
- onExit(errorOrResult);
1146
- },
1147
- [isRawModeSupported, disableRawMode, onExit]
1148
- );
1149
- const handleInput = useCallback(
1150
- (input) => {
1151
- if (input.includes("") && exitOnCtrlC) {
1152
- handleExit();
1153
- return;
1154
- }
1155
- if (input === escape) {
1156
- setActiveFocusId((currentActiveFocusId) => {
1157
- if (currentActiveFocusId) {
1158
- return void 0;
1159
- }
1160
- return currentActiveFocusId;
1161
- });
1162
- }
1163
- },
1164
- [exitOnCtrlC, handleExit]
1165
- );
1166
- const emitInput = useCallback(
1167
- (input) => {
1168
- handleInput(input);
1169
- internal_eventEmitter.emit("input", input);
1170
- },
1171
- [handleInput, internal_eventEmitter]
1172
- );
1173
- const schedulePendingInputFlush = useCallback(() => {
1174
- clearPendingInputFlush();
1175
- pendingInputFlushRef.current = setTimeout(() => {
1176
- pendingInputFlushRef.current = void 0;
1177
- const pendingEscape = inputParserRef.current.flushPendingEscape();
1178
- if (!pendingEscape) {
1179
- return;
1180
- }
1181
- emitInput(pendingEscape);
1182
- }, pendingInputFlushDelayMilliseconds);
1183
- }, [clearPendingInputFlush, emitInput]);
1184
- const handleReadable = useCallback(() => {
1185
- clearPendingInputFlush();
1186
- let chunk;
1187
- while ((chunk = stdin.read()) !== null) {
1188
- const inputEvents = inputParserRef.current.push(chunk);
1189
- for (const event of inputEvents) {
1190
- if (typeof event === "string") {
1191
- emitInput(event);
1192
- } else {
1193
- if (internal_eventEmitter.listenerCount("paste") === 0) {
1194
- if (!didWarnAboutDeprecatedPasteFallbackRef.current) {
1195
- didWarnAboutDeprecatedPasteFallbackRef.current = true;
1196
- writeToStderr(
1197
- "Warning: useInput() received bracketed paste because no usePaste() handler is active. This fallback is deprecated and will be removed in the next major version. Migrate paste handling to usePaste().\n"
1198
- );
1199
- }
1200
- emitInput(event.paste);
1201
- continue;
1202
- }
1203
- internal_eventEmitter.emit("paste", event.paste);
1204
- }
1205
- }
1206
- }
1207
- if (inputParserRef.current.hasPendingEscape()) {
1208
- schedulePendingInputFlush();
1209
- }
1210
- }, [stdin, emitInput, clearPendingInputFlush, schedulePendingInputFlush, writeToStderr, internal_eventEmitter]);
1211
- const handleSetRawMode = useCallback(
1212
- (isEnabled) => {
1213
- if (!isRawModeSupported) {
1214
- if (stdin === process$2.stdin) {
1215
- throw new Error(
1216
- "Raw mode is not supported on the current process.stdin, which Ink uses as input stream by default.\nRead about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported"
1217
- );
1218
- } else {
1219
- throw new Error(
1220
- "Raw mode is not supported on the stdin provided to Ink.\nRead about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported"
1221
- );
1222
- }
1223
- }
1224
- stdin.setEncoding("utf8");
1225
- if (isEnabled) {
1226
- if (rawModeEnabledCount.current === 0) {
1227
- stdin.ref();
1228
- stdin.setRawMode(true);
1229
- readableListenerRef.current = handleReadable;
1230
- stdin.addListener("readable", handleReadable);
1231
- }
1232
- rawModeEnabledCount.current++;
1233
- return;
1234
- }
1235
- if (rawModeEnabledCount.current === 0) {
1236
- return;
1237
- }
1238
- if (--rawModeEnabledCount.current === 0) {
1239
- disableRawMode();
1240
- }
1241
- },
1242
- [isRawModeSupported, stdin, handleReadable, disableRawMode]
1243
- );
1244
- const handleSetBracketedPasteMode = useCallback(
1245
- (isEnabled) => {
1246
- if (!stdout.isTTY) {
1247
- return;
1248
- }
1249
- if (isEnabled) {
1250
- if (bracketedPasteModeEnabledCount.current === 0) {
1251
- stdout.write(enableBracketedPaste);
1252
- }
1253
- bracketedPasteModeEnabledCount.current++;
1254
- return;
1255
- }
1256
- if (bracketedPasteModeEnabledCount.current === 0) {
1257
- return;
1258
- }
1259
- if (--bracketedPasteModeEnabledCount.current === 0) {
1260
- stdout.write(disableBracketedPaste);
1261
- }
1262
- },
1263
- [stdout]
1264
- );
1265
- const findNextFocusable = useCallback((currentFocusables, currentActiveFocusId) => {
1266
- const activeIndex = currentFocusables.findIndex((focusable) => focusable.id === currentActiveFocusId);
1267
- for (let index = activeIndex + 1; index < currentFocusables.length; index++) {
1268
- const focusable = currentFocusables[index];
1269
- if (focusable?.isActive) {
1270
- return focusable.id;
1271
- }
1272
- }
1273
- return void 0;
1274
- }, []);
1275
- const findPreviousFocusable = useCallback((currentFocusables, currentActiveFocusId) => {
1276
- const activeIndex = currentFocusables.findIndex((focusable) => focusable.id === currentActiveFocusId);
1277
- for (let index = activeIndex - 1; index >= 0; index--) {
1278
- const focusable = currentFocusables[index];
1279
- if (focusable?.isActive) {
1280
- return focusable.id;
1281
- }
1282
- }
1283
- return void 0;
1284
- }, []);
1285
- const focusNext = useCallback(() => {
1286
- setFocusables((currentFocusables) => {
1287
- setActiveFocusId((currentActiveFocusId) => {
1288
- const firstFocusableId = currentFocusables.find((focusable) => focusable.isActive)?.id;
1289
- const nextFocusableId = findNextFocusable(currentFocusables, currentActiveFocusId);
1290
- return nextFocusableId ?? firstFocusableId;
1291
- });
1292
- return currentFocusables;
1293
- });
1294
- }, [findNextFocusable]);
1295
- const focusPrevious = useCallback(() => {
1296
- setFocusables((currentFocusables) => {
1297
- setActiveFocusId((currentActiveFocusId) => {
1298
- const lastFocusableId = currentFocusables.findLast((focusable) => focusable.isActive)?.id;
1299
- const previousFocusableId = findPreviousFocusable(currentFocusables, currentActiveFocusId);
1300
- return previousFocusableId ?? lastFocusableId;
1301
- });
1302
- return currentFocusables;
1303
- });
1304
- }, [findPreviousFocusable]);
1305
- useEffect(() => {
1306
- const handleTabNavigation = (input) => {
1307
- if (!isFocusEnabled || focusablesCountRef.current === 0) {
1308
- return;
1309
- }
1310
- if (input === tab) {
1311
- focusNext();
1312
- }
1313
- if (input === shiftTab) {
1314
- focusPrevious();
1315
- }
1316
- };
1317
- internal_eventEmitter.on("input", handleTabNavigation);
1318
- const emitter = internal_eventEmitter;
1319
- return () => {
1320
- emitter.off("input", handleTabNavigation);
1321
- };
1322
- }, [isFocusEnabled, focusNext, focusPrevious, internal_eventEmitter]);
1323
- const enableFocus = useCallback(() => {
1324
- setIsFocusEnabled(true);
1325
- }, []);
1326
- const disableFocus = useCallback(() => {
1327
- setIsFocusEnabled(false);
1328
- }, []);
1329
- const focus = useCallback((id) => {
1330
- setFocusables((currentFocusables) => {
1331
- const hasFocusableId = currentFocusables.some((focusable) => focusable?.id === id);
1332
- if (hasFocusableId) {
1333
- setActiveFocusId(id);
1334
- }
1335
- return currentFocusables;
1336
- });
1337
- }, []);
1338
- const addFocusable = useCallback((id, { autoFocus }) => {
1339
- setFocusables((currentFocusables) => {
1340
- focusablesCountRef.current = currentFocusables.length + 1;
1341
- return [
1342
- ...currentFocusables,
1343
- {
1344
- id,
1345
- isActive: true
1346
- }
1347
- ];
1348
- });
1349
- if (autoFocus) {
1350
- setActiveFocusId((currentActiveFocusId) => {
1351
- if (!currentActiveFocusId) {
1352
- return id;
1353
- }
1354
- return currentActiveFocusId;
1355
- });
1356
- }
1357
- }, []);
1358
- const removeFocusable = useCallback((id) => {
1359
- setActiveFocusId((currentActiveFocusId) => {
1360
- if (currentActiveFocusId === id) {
1361
- return void 0;
1362
- }
1363
- return currentActiveFocusId;
1364
- });
1365
- setFocusables((currentFocusables) => {
1366
- const filtered = currentFocusables.filter((focusable) => focusable.id !== id);
1367
- focusablesCountRef.current = filtered.length;
1368
- return filtered;
1369
- });
1370
- }, []);
1371
- const activateFocusable = useCallback((id) => {
1372
- setFocusables(
1373
- (currentFocusables) => currentFocusables.map((focusable) => {
1374
- if (focusable.id !== id) {
1375
- return focusable;
1376
- }
1377
- return {
1378
- id,
1379
- isActive: true
1380
- };
1381
- })
1382
- );
1383
- }, []);
1384
- const deactivateFocusable = useCallback((id) => {
1385
- setActiveFocusId((currentActiveFocusId) => {
1386
- if (currentActiveFocusId === id) {
1387
- return void 0;
1388
- }
1389
- return currentActiveFocusId;
1390
- });
1391
- setFocusables(
1392
- (currentFocusables) => currentFocusables.map((focusable) => {
1393
- if (focusable.id !== id) {
1394
- return focusable;
1395
- }
1396
- return {
1397
- id,
1398
- isActive: false
1399
- };
1400
- })
1401
- );
1402
- }, []);
1403
- useEffect(
1404
- () => () => {
1405
- const canWriteToStdout = !stdout.destroyed && !stdout.writableEnded;
1406
- if (interactive && canWriteToStdout) {
1407
- stdout.write(cursorShow);
1408
- }
1409
- if (isRawModeSupported && rawModeEnabledCount.current > 0) {
1410
- disableRawMode();
1411
- }
1412
- if (bracketedPasteModeEnabledCount.current > 0) {
1413
- if (stdout.isTTY && canWriteToStdout) {
1414
- stdout.write(disableBracketedPaste);
1415
- }
1416
- bracketedPasteModeEnabledCount.current = 0;
1417
- }
1418
- },
1419
- [stdout, isRawModeSupported, disableRawMode, interactive]
1420
- );
1421
- const appContextValue = useMemo(() => {
1422
- return {
1423
- exit: handleExit,
1424
- waitUntilRenderFlush: onWaitUntilRenderFlush
1425
- };
1426
- }, [handleExit, onWaitUntilRenderFlush]);
1427
- const stdinContextValue = useMemo(() => {
1428
- return {
1429
- internal_eventEmitter,
1430
- internal_exitOnCtrlC: exitOnCtrlC,
1431
- isRawModeSupported,
1432
- setBracketedPasteMode: handleSetBracketedPasteMode,
1433
- setRawMode: handleSetRawMode,
1434
- stdin
1435
- };
1436
- }, [stdin, handleSetRawMode, handleSetBracketedPasteMode, isRawModeSupported, exitOnCtrlC, internal_eventEmitter]);
1437
- const stdoutContextValue = useMemo(() => {
1438
- return {
1439
- stdout,
1440
- write: writeToStdout
1441
- };
1442
- }, [stdout, writeToStdout]);
1443
- const stderrContextValue = useMemo(() => {
1444
- return {
1445
- stderr,
1446
- write: writeToStderr
1447
- };
1448
- }, [stderr, writeToStderr]);
1449
- const cursorContextValue = useMemo(() => {
1450
- return {
1451
- setCursorPosition
1452
- };
1453
- }, [setCursorPosition]);
1454
- const focusContextValue = useMemo(() => {
1455
- return {
1456
- activate: activateFocusable,
1457
- activeId: activeFocusId,
1458
- add: addFocusable,
1459
- deactivate: deactivateFocusable,
1460
- disableFocus,
1461
- enableFocus,
1462
- focus,
1463
- focusNext,
1464
- focusPrevious,
1465
- remove: removeFocusable
1466
- };
1467
- }, [activeFocusId, addFocusable, removeFocusable, activateFocusable, deactivateFocusable, enableFocus, disableFocus, focusNext, focusPrevious, focus]);
1468
- const animationContextValue = useMemo(() => {
1469
- return {
1470
- renderThrottleMs,
1471
- subscribe: animationSubscribe
1472
- };
1473
- }, [animationSubscribe, renderThrottleMs]);
1474
- return jsx(AppContext.Provider, { value: appContextValue, children: jsx(StdinContext.Provider, { value: stdinContextValue, children: jsx(StdoutContext.Provider, { value: stdoutContextValue, children: jsx(StderrContext.Provider, { value: stderrContextValue, children: jsx(FocusContext.Provider, { value: focusContextValue, children: jsx(animationContext.Provider, { value: animationContextValue, children: jsx(CursorContext.Provider, { value: cursorContextValue, children: jsx(ErrorBoundary, { onError: handleExit, children }) }) }) }) }) }) }) });
1475
- };
1476
- App.displayName = "InternalApp";
1477
-
1478
- const instances = /* @__PURE__ */ new WeakMap();
1479
-
1480
- const cursorPositionChanged = (a, b) => a?.x !== b?.x || a?.y !== b?.y;
1481
- const buildCursorSuffix = (visibleLineCount, cursorPosition) => {
1482
- if (!cursorPosition) {
1483
- return "";
1484
- }
1485
- const moveUp = visibleLineCount - cursorPosition.y;
1486
- return (moveUp > 0 ? cursorUp(moveUp) : "") + cursorTo(cursorPosition.x) + cursorShow;
1487
- };
1488
- const buildReturnToBottom = (previousLineCount, previousCursorPosition) => {
1489
- if (!previousCursorPosition) {
1490
- return "";
1491
- }
1492
- const down = previousLineCount - 1 - previousCursorPosition.y;
1493
- return (down > 0 ? cursorDown(down) : "") + cursorTo(0);
1494
- };
1495
- const buildCursorOnlySequence = (input) => {
1496
- const hidePrefix = input.cursorWasShown ? cursorHide : "";
1497
- const returnToBottom = buildReturnToBottom(input.previousLineCount, input.previousCursorPosition);
1498
- const cursorSuffix = buildCursorSuffix(input.visibleLineCount, input.cursorPosition);
1499
- return hidePrefix + returnToBottom + cursorSuffix;
1500
- };
1501
- const buildReturnToBottomPrefix = (cursorWasShown, previousLineCount, previousCursorPosition) => {
1502
- if (!cursorWasShown) {
1503
- return "";
1504
- }
1505
- return cursorHide + buildReturnToBottom(previousLineCount, previousCursorPosition);
1506
- };
1507
-
1508
- const visibleLineCount = (lines, string_) => string_.endsWith("\n") ? lines.length - 1 : lines.length;
1509
- const getViewportRows = (stream) => stream.rows || Infinity;
1510
- const clampToViewport = (lineCount, stream) => Math.min(lineCount, getViewportRows(stream));
1511
- const createStandard = (stream, { showCursor = false } = {}) => {
1512
- let previousLineCount = 0;
1513
- let previousOutput = "";
1514
- let hasHiddenCursor = false;
1515
- let cursorPosition;
1516
- let cursorDirty = false;
1517
- let previousCursorPosition;
1518
- let cursorWasShown = false;
1519
- const getActiveCursor = () => cursorDirty ? cursorPosition : void 0;
1520
- const hasChanges = (string_, activeCursor) => {
1521
- const cursorChanged = cursorPositionChanged(activeCursor, previousCursorPosition);
1522
- return string_ !== previousOutput || cursorChanged;
1523
- };
1524
- const render = (string_) => {
1525
- if (!showCursor && !hasHiddenCursor) {
1526
- stream.write(cursorHide);
1527
- hasHiddenCursor = true;
1528
- }
1529
- const activeCursor = getActiveCursor();
1530
- cursorDirty = false;
1531
- const cursorChanged = cursorPositionChanged(activeCursor, previousCursorPosition);
1532
- if (!hasChanges(string_, activeCursor)) {
1533
- return false;
1534
- }
1535
- const lines = string_.split("\n");
1536
- const visibleCount = visibleLineCount(lines, string_);
1537
- const cursorSuffix = buildCursorSuffix(visibleCount, activeCursor);
1538
- if (string_ === previousOutput && cursorChanged) {
1539
- stream.write(
1540
- buildCursorOnlySequence({
1541
- cursorPosition: activeCursor,
1542
- cursorWasShown,
1543
- previousCursorPosition,
1544
- previousLineCount,
1545
- visibleLineCount: visibleCount
1546
- })
1547
- );
1548
- } else {
1549
- previousOutput = string_;
1550
- const returnPrefix = buildReturnToBottomPrefix(cursorWasShown, previousLineCount, previousCursorPosition);
1551
- stream.write(returnPrefix + eraseLines(clampToViewport(previousLineCount, stream)) + string_ + cursorSuffix);
1552
- previousLineCount = lines.length;
1553
- }
1554
- previousCursorPosition = activeCursor ? { ...activeCursor } : void 0;
1555
- cursorWasShown = activeCursor !== void 0;
1556
- return true;
1557
- };
1558
- render.clear = () => {
1559
- const prefix = buildReturnToBottomPrefix(cursorWasShown, previousLineCount, previousCursorPosition);
1560
- stream.write(prefix + eraseLines(clampToViewport(previousLineCount, stream)));
1561
- previousOutput = "";
1562
- previousLineCount = 0;
1563
- previousCursorPosition = void 0;
1564
- cursorWasShown = false;
1565
- };
1566
- render.done = () => {
1567
- previousOutput = "";
1568
- previousLineCount = 0;
1569
- previousCursorPosition = void 0;
1570
- cursorWasShown = false;
1571
- if (!showCursor) {
1572
- stream.write(cursorShow);
1573
- hasHiddenCursor = false;
1574
- }
1575
- };
1576
- render.reset = () => {
1577
- previousOutput = "";
1578
- previousLineCount = 0;
1579
- previousCursorPosition = void 0;
1580
- cursorWasShown = false;
1581
- };
1582
- render.sync = (string_) => {
1583
- const activeCursor = cursorDirty ? cursorPosition : void 0;
1584
- cursorDirty = false;
1585
- const lines = string_.split("\n");
1586
- previousOutput = string_;
1587
- previousLineCount = lines.length;
1588
- if (!activeCursor && cursorWasShown) {
1589
- stream.write(cursorHide);
1590
- }
1591
- if (activeCursor) {
1592
- stream.write(buildCursorSuffix(visibleLineCount(lines, string_), activeCursor));
1593
- }
1594
- previousCursorPosition = activeCursor ? { ...activeCursor } : void 0;
1595
- cursorWasShown = activeCursor !== void 0;
1596
- };
1597
- render.setCursorPosition = (position) => {
1598
- cursorPosition = position;
1599
- cursorDirty = true;
1600
- };
1601
- render.isCursorDirty = () => cursorDirty;
1602
- render.willRender = (string_) => hasChanges(string_, getActiveCursor());
1603
- return render;
1604
- };
1605
- const createIncremental = (stream, { showCursor = false } = {}) => {
1606
- let previousLines = [];
1607
- let previousOutput = "";
1608
- let hasHiddenCursor = false;
1609
- let cursorPosition;
1610
- let cursorDirty = false;
1611
- let previousCursorPosition;
1612
- let cursorWasShown = false;
1613
- const getActiveCursor = () => cursorDirty ? cursorPosition : void 0;
1614
- const hasChanges = (string_, activeCursor) => {
1615
- const cursorChanged = cursorPositionChanged(activeCursor, previousCursorPosition);
1616
- return string_ !== previousOutput || cursorChanged;
1617
- };
1618
- const render = (string_) => {
1619
- if (!showCursor && !hasHiddenCursor) {
1620
- stream.write(cursorHide);
1621
- hasHiddenCursor = true;
1622
- }
1623
- const activeCursor = getActiveCursor();
1624
- cursorDirty = false;
1625
- const cursorChanged = cursorPositionChanged(activeCursor, previousCursorPosition);
1626
- if (!hasChanges(string_, activeCursor)) {
1627
- return false;
1628
- }
1629
- const nextLines = string_.split("\n");
1630
- const visibleCount = visibleLineCount(nextLines, string_);
1631
- const previousVisible = visibleLineCount(previousLines, previousOutput);
1632
- if (string_ === previousOutput && cursorChanged) {
1633
- stream.write(
1634
- buildCursorOnlySequence({
1635
- cursorPosition: activeCursor,
1636
- cursorWasShown,
1637
- previousCursorPosition,
1638
- previousLineCount: previousLines.length,
1639
- visibleLineCount: visibleCount
1640
- })
1641
- );
1642
- previousCursorPosition = activeCursor ? { ...activeCursor } : void 0;
1643
- cursorWasShown = activeCursor !== void 0;
1644
- return true;
1645
- }
1646
- const returnPrefix = buildReturnToBottomPrefix(cursorWasShown, previousLines.length, previousCursorPosition);
1647
- if (string_ === "\n" || previousOutput.length === 0) {
1648
- const cursorSuffix2 = buildCursorSuffix(visibleCount, activeCursor);
1649
- stream.write(returnPrefix + eraseLines(clampToViewport(previousLines.length, stream)) + string_ + cursorSuffix2);
1650
- cursorWasShown = activeCursor !== void 0;
1651
- previousCursorPosition = activeCursor ? { ...activeCursor } : void 0;
1652
- previousOutput = string_;
1653
- previousLines = nextLines;
1654
- return true;
1655
- }
1656
- const hasTrailingNewline = string_.endsWith("\n");
1657
- const buffer = [returnPrefix];
1658
- const viewportRows = getViewportRows(stream);
1659
- if (visibleCount < previousVisible) {
1660
- const previousHadTrailingNewline = previousOutput.endsWith("\n");
1661
- const extraSlot = previousHadTrailingNewline ? 1 : 0;
1662
- buffer.push(eraseLines(Math.min(previousVisible - visibleCount + extraSlot, viewportRows)), cursorUp(Math.min(visibleCount, viewportRows - 1)));
1663
- } else {
1664
- buffer.push(cursorUp(Math.min(previousVisible - 1, viewportRows - 1)));
1665
- }
1666
- for (let i = 0; i < visibleCount; i++) {
1667
- const isLastLine = i === visibleCount - 1;
1668
- if (nextLines[i] === previousLines[i]) {
1669
- if (!isLastLine || hasTrailingNewline) {
1670
- buffer.push(cursorNextLine());
1671
- }
1672
- continue;
1673
- }
1674
- buffer.push(
1675
- cursorTo(0) + nextLines[i] + eraseLineEnd + (isLastLine && !hasTrailingNewline ? "" : "\n")
1676
- );
1677
- }
1678
- const cursorSuffix = buildCursorSuffix(visibleCount, activeCursor);
1679
- buffer.push(cursorSuffix);
1680
- stream.write(buffer.join(""));
1681
- cursorWasShown = activeCursor !== void 0;
1682
- previousCursorPosition = activeCursor ? { ...activeCursor } : void 0;
1683
- previousOutput = string_;
1684
- previousLines = nextLines;
1685
- return true;
1686
- };
1687
- render.clear = () => {
1688
- const prefix = buildReturnToBottomPrefix(cursorWasShown, previousLines.length, previousCursorPosition);
1689
- stream.write(prefix + eraseLines(clampToViewport(previousLines.length, stream)));
1690
- previousOutput = "";
1691
- previousLines = [];
1692
- previousCursorPosition = void 0;
1693
- cursorWasShown = false;
1694
- };
1695
- render.done = () => {
1696
- previousOutput = "";
1697
- previousLines = [];
1698
- previousCursorPosition = void 0;
1699
- cursorWasShown = false;
1700
- if (!showCursor) {
1701
- stream.write(cursorShow);
1702
- hasHiddenCursor = false;
1703
- }
1704
- };
1705
- render.reset = () => {
1706
- previousOutput = "";
1707
- previousLines = [];
1708
- previousCursorPosition = void 0;
1709
- cursorWasShown = false;
1710
- };
1711
- render.sync = (string_) => {
1712
- const activeCursor = cursorDirty ? cursorPosition : void 0;
1713
- cursorDirty = false;
1714
- const lines = string_.split("\n");
1715
- previousOutput = string_;
1716
- previousLines = lines;
1717
- if (!activeCursor && cursorWasShown) {
1718
- stream.write(cursorHide);
1719
- }
1720
- if (activeCursor) {
1721
- stream.write(buildCursorSuffix(visibleLineCount(lines, string_), activeCursor));
1722
- }
1723
- previousCursorPosition = activeCursor ? { ...activeCursor } : void 0;
1724
- cursorWasShown = activeCursor !== void 0;
1725
- };
1726
- render.setCursorPosition = (position) => {
1727
- cursorPosition = position;
1728
- cursorDirty = true;
1729
- };
1730
- render.isCursorDirty = () => cursorDirty;
1731
- render.willRender = (string_) => hasChanges(string_, getActiveCursor());
1732
- return render;
1733
- };
1734
- const create = (stream, { incremental = false, showCursor = false } = {}) => {
1735
- if (incremental) {
1736
- return createIncremental(stream, { showCursor });
1737
- }
1738
- return createStandard(stream, { showCursor });
1739
- };
1740
- const logUpdate = { create };
1741
-
1742
- const SynchronizedOutputMode = createDecMode(2026);
1743
- const bsu = setMode(SynchronizedOutputMode);
1744
- const esu = resetMode(SynchronizedOutputMode);
1745
- function shouldSynchronize(stream, interactive) {
1746
- return "isTTY" in stream && stream.isTTY && (interactive ?? !isInCi);
1747
- }
1748
-
1749
- let cachedRendererClass;
1750
- const getRendererClass = () => {
1751
- if (cachedRendererClass === false) {
1752
- return void 0;
1753
- }
1754
- if (cachedRendererClass !== void 0) {
1755
- return cachedRendererClass;
1756
- }
1757
- try {
1758
- const binding = require("../../index.js");
1759
- cachedRendererClass = binding.Renderer;
1760
- return cachedRendererClass;
1761
- } catch {
1762
- cachedRendererClass = false;
1763
- return void 0;
1764
- }
1765
- };
1766
- const createNative = (stream) => {
1767
- const RendererClass = getRendererClass();
1768
- if (!RendererClass) {
1769
- return void 0;
1770
- }
1771
- let renderer;
1772
- let currentWidth = 0;
1773
- let currentHeight = 0;
1774
- const ensureRenderer = (width, height) => {
1775
- if (!renderer || currentWidth !== width || currentHeight !== height) {
1776
- if (renderer) {
1777
- renderer.resize(width, height);
1778
- } else {
1779
- renderer = new RendererClass(width, height);
1780
- }
1781
- currentWidth = width;
1782
- currentHeight = height;
1783
- }
1784
- };
1785
- return {
1786
- clear() {
1787
- if (renderer) {
1788
- const blank = new Uint32Array(currentWidth * currentHeight * 2);
1789
- const defaultAttribute = 0 << 16 | 255 << 8 | 255;
1790
- for (let index = 0; index < blank.length; index += 2) {
1791
- blank[index] = 32;
1792
- blank[index + 1] = defaultAttribute;
1793
- }
1794
- renderer.render(blank);
1795
- }
1796
- },
1797
- destroy() {
1798
- renderer = void 0;
1799
- },
1800
- render(buffer, width, height) {
1801
- ensureRenderer(width, height);
1802
- if (!renderer) {
1803
- return;
1804
- }
1805
- if (stream.isTTY) {
1806
- renderer.writeRaw(bsu);
1807
- }
1808
- try {
1809
- renderer.render(buffer);
1810
- } finally {
1811
- if (stream.isTTY) {
1812
- renderer.writeRaw(esu);
1813
- }
1814
- }
1815
- },
1816
- resize(width, height) {
1817
- ensureRenderer(width, height);
1818
- }
1819
- };
1820
- };
1821
-
1822
- if (!console.Console) {
1823
- console.Console = Console;
1824
- }
1825
- const noop = () => {
1826
- };
1827
- const yieldImmediate = async () => new Promise((resolve) => {
1828
- setImmediate(resolve);
1829
- });
1830
- const kittyQueryEscapeByte = 27;
1831
- const kittyQueryOpenBracketByte = 91;
1832
- const kittyQueryQuestionMarkByte = 63;
1833
- const kittyQueryLetterByte = 117;
1834
- const zeroByte = 48;
1835
- const nineByte = 57;
1836
- const isDigitByte = (byte) => byte >= zeroByte && byte <= nineByte;
1837
- const matchKittyQueryResponse = (buffer, startIndex) => {
1838
- if (buffer[startIndex] !== kittyQueryEscapeByte || buffer[startIndex + 1] !== kittyQueryOpenBracketByte || buffer[startIndex + 2] !== kittyQueryQuestionMarkByte) {
1839
- return void 0;
1840
- }
1841
- let index = startIndex + 3;
1842
- const digitsStartIndex = index;
1843
- while (index < buffer.length && isDigitByte(buffer[index])) {
1844
- index++;
1845
- }
1846
- if (index === digitsStartIndex) {
1847
- return void 0;
1848
- }
1849
- if (index === buffer.length) {
1850
- return { state: "partial" };
1851
- }
1852
- if (buffer[index] === kittyQueryLetterByte) {
1853
- return { endIndex: index, state: "complete" };
1854
- }
1855
- return void 0;
1856
- };
1857
- const hasCompleteKittyQueryResponse = (buffer) => {
1858
- for (let index = 0; index < buffer.length; index++) {
1859
- const match = matchKittyQueryResponse(buffer, index);
1860
- if (match?.state === "complete") {
1861
- return true;
1862
- }
1863
- }
1864
- return false;
1865
- };
1866
- const stripKittyQueryResponsesAndTrailingPartial = (buffer) => {
1867
- const keptBytes = [];
1868
- let index = 0;
1869
- while (index < buffer.length) {
1870
- const match = matchKittyQueryResponse(buffer, index);
1871
- if (match?.state === "complete") {
1872
- index = match.endIndex + 1;
1873
- continue;
1874
- }
1875
- if (match?.state === "partial") {
1876
- break;
1877
- }
1878
- keptBytes.push(buffer[index]);
1879
- index++;
1880
- }
1881
- return keptBytes;
1882
- };
1883
- const shouldClearTerminalForFrame = ({
1884
- isTty,
1885
- isUnmounting,
1886
- nextOutputHeight,
1887
- previousOutputHeight,
1888
- viewportRows
1889
- }) => {
1890
- if (!isTty) {
1891
- return false;
1892
- }
1893
- const hadPreviousFrame = previousOutputHeight > 0;
1894
- const wasFullscreen = previousOutputHeight >= viewportRows;
1895
- const wasOverflowing = previousOutputHeight > viewportRows;
1896
- const isOverflowing = nextOutputHeight > viewportRows;
1897
- const isLeavingFullscreen = wasFullscreen && nextOutputHeight < viewportRows;
1898
- const shouldClearOnUnmount = isUnmounting && wasFullscreen;
1899
- return (
1900
- // Overflowing frames still need full clear fallback.
1901
- wasOverflowing || isOverflowing && hadPreviousFrame || isLeavingFullscreen || shouldClearOnUnmount
1902
- );
1903
- };
1904
- const isErrorInput = (value) => value instanceof Error || Object.prototype.toString.call(value) === "[object Error]";
1905
- const getWritableStreamState = (stdout) => {
1906
- const canWriteToStdout = !stdout.destroyed && !stdout.writableEnded && (stdout.writable ?? true);
1907
- const hasWritableState = stdout._writableState !== void 0 || stdout.writableLength !== void 0;
1908
- return {
1909
- canWriteToStdout,
1910
- hasWritableState
1911
- };
1912
- };
1913
- const settleThrottle = (throttled, canWriteToStdout) => {
1914
- if (!throttled || typeof throttled.flush !== "function") {
1915
- return;
1916
- }
1917
- const throttledValue = throttled;
1918
- if (canWriteToStdout) {
1919
- throttledValue.flush();
1920
- } else if (typeof throttledValue.cancel === "function") {
1921
- throttledValue.cancel();
1922
- }
1923
- };
1924
- class Ink {
1925
- /**
1926
- * Whether this instance is using concurrent rendering mode.
1927
- */
1928
- isConcurrent;
1929
- options;
1930
- log;
1931
- manualCursorPosition;
1932
- renderedCursorPosition;
1933
- renderedCursorRequested;
1934
- throttledLog;
1935
- isScreenReaderEnabled;
1936
- interactive;
1937
- renderThrottleMs;
1938
- alternateScreen;
1939
- // Ignore last render after unmounting a tree to prevent empty output before exit
1940
- isUnmounted;
1941
- isUnmounting;
1942
- lastOutput;
1943
- lastOutputToRender;
1944
- lastOutputHeight;
1945
- lastTerminalWidth;
1946
- nativeLog;
1947
- useNativeRenderer;
1948
- container;
1949
- rootNode;
1950
- // This variable is used only in debug mode to store full static output
1951
- // so that it's rerendered every time, not just new static parts, like in non-debug mode
1952
- fullStaticOutput;
1953
- exitPromise;
1954
- exitResult;
1955
- beforeExitHandler;
1956
- restoreConsole;
1957
- unsubscribeResize;
1958
- throttledOnRender;
1959
- hasPendingThrottledRender = false;
1960
- kittyProtocolEnabled = false;
1961
- cancelKittyDetection;
1962
- nextRenderCommit;
1963
- deferredInitDone = false;
1964
- constructor(options) {
1965
- this.options = options;
1966
- this.rootNode = createNode("ink-root");
1967
- this.rootNode.onComputeLayout = this.calculateLayout;
1968
- this.isScreenReaderEnabled = options.isScreenReaderEnabled ?? process$2.env["INK_SCREEN_READER"] === "true";
1969
- this.interactive = this.resolveInteractiveOption(options.interactive);
1970
- this.alternateScreen = false;
1971
- const unthrottled = options.debug || this.isScreenReaderEnabled;
1972
- const maxFps = options.maxFps ?? 30;
1973
- const renderThrottleMs = maxFps > 0 ? Math.max(1, Math.ceil(1e3 / maxFps)) : 0;
1974
- this.renderThrottleMs = unthrottled ? 0 : renderThrottleMs;
1975
- const baseOnRender = unthrottled ? this.onRender : (() => {
1976
- const throttled = throttle(this.onRender, renderThrottleMs, {
1977
- leading: true,
1978
- trailing: true
1979
- });
1980
- this.throttledOnRender = throttled;
1981
- return () => {
1982
- this.hasPendingThrottledRender = true;
1983
- throttled();
1984
- };
1985
- })();
1986
- if (unthrottled) {
1987
- this.throttledOnRender = void 0;
1988
- }
1989
- if (options.standardReactLayoutTiming) {
1990
- let isRenderScheduled = false;
1991
- const deferredRender = () => {
1992
- if (isRenderScheduled) {
1993
- return;
1994
- }
1995
- isRenderScheduled = true;
1996
- queueMicrotask(() => {
1997
- isRenderScheduled = false;
1998
- this.onRender();
1999
- });
2000
- };
2001
- this.rootNode.onRender = deferredRender;
2002
- this.rootNode.onImmediateRender = deferredRender;
2003
- } else {
2004
- this.rootNode.onRender = baseOnRender;
2005
- this.rootNode.onImmediateRender = this.onRender;
2006
- }
2007
- this.log = logUpdate.create(options.stdout, {
2008
- incremental: options.incrementalRendering
2009
- });
2010
- this.useNativeRenderer = options.useNativeRenderer ?? false;
2011
- if (this.useNativeRenderer) {
2012
- this.nativeLog = createNative(options.stdout);
2013
- if (!this.nativeLog) {
2014
- this.useNativeRenderer = false;
2015
- }
2016
- }
2017
- this.manualCursorPosition = void 0;
2018
- this.renderedCursorPosition = void 0;
2019
- this.renderedCursorRequested = false;
2020
- this.throttledLog = unthrottled ? this.log : throttle(
2021
- (output) => {
2022
- const shouldWrite = this.log.willRender(output);
2023
- const sync = this.shouldSync();
2024
- if (sync && shouldWrite) {
2025
- this.options.stdout.write(bsu);
2026
- }
2027
- this.log(output);
2028
- if (sync && shouldWrite) {
2029
- this.options.stdout.write(esu);
2030
- }
2031
- },
2032
- void 0,
2033
- {
2034
- leading: true,
2035
- trailing: true
2036
- }
2037
- );
2038
- this.isUnmounted = false;
2039
- this.isUnmounting = false;
2040
- this.isConcurrent = options.concurrent ?? false;
2041
- this.lastOutput = "";
2042
- this.lastOutputToRender = "";
2043
- this.lastOutputHeight = 0;
2044
- this.lastTerminalWidth = getWindowSize(this.options.stdout).columns;
2045
- this.fullStaticOutput = "";
2046
- const rootTag = options.concurrent ? ConcurrentRoot : LegacyRoot;
2047
- this.container = reconcilerInstance.createContainer(
2048
- this.rootNode,
2049
- rootTag,
2050
- null,
2051
- false,
2052
- null,
2053
- "id",
2054
- () => {
2055
- },
2056
- () => {
2057
- },
2058
- () => {
2059
- },
2060
- () => {
2061
- }
2062
- );
2063
- this.unsubscribeExit = onExit(this.unmount, { alwaysLast: false });
2064
- this.setAlternateScreen(Boolean(options.alternateScreen));
2065
- if (options.patchConsole) {
2066
- this.patchConsole();
2067
- }
2068
- if (this.interactive) {
2069
- options.stdout.on("resize", this.resized);
2070
- this.unsubscribeResize = () => {
2071
- options.stdout.off("resize", this.resized);
2072
- };
2073
- }
2074
- this.initImmediateKittyKeyboard();
2075
- if (process$2.env["DEV"] === "true") {
2076
- reconcilerInstance.injectIntoDevTools();
2077
- }
2078
- this.exitPromise = new Promise((resolve, reject) => {
2079
- this.resolveExitPromise = resolve;
2080
- this.rejectExitPromise = reject;
2081
- });
2082
- void this.exitPromise.catch(noop);
2083
- }
2084
- /**
2085
- * Perform deferred initialization on the first render frame.
2086
- * Kitty keyboard auto-detection is deferred here because the CSI ? u
2087
- * query sets up a synchronous stdin listener with a 200ms timeout.
2088
- * "enabled" mode runs immediately in the constructor (it's just a write).
2089
- */
2090
- runDeferredInit() {
2091
- if (this.deferredInitDone) {
2092
- return;
2093
- }
2094
- this.deferredInitDone = true;
2095
- this.initDeferredKittyKeyboard();
2096
- }
2097
- resized = () => {
2098
- const currentWidth = getWindowSize(this.options.stdout).columns;
2099
- if (currentWidth < this.lastTerminalWidth) {
2100
- this.log.clear();
2101
- this.lastOutput = "";
2102
- this.lastOutputToRender = "";
2103
- }
2104
- clearStyledLineCache();
2105
- this.calculateLayout();
2106
- this.onRender();
2107
- this.lastTerminalWidth = currentWidth;
2108
- };
2109
- resolveExitPromise = () => {
2110
- };
2111
- rejectExitPromise = () => {
2112
- };
2113
- unsubscribeExit = () => {
2114
- };
2115
- handleAppExit = (errorOrResult) => {
2116
- if (this.isUnmounted || this.isUnmounting) {
2117
- return;
2118
- }
2119
- if (isErrorInput(errorOrResult)) {
2120
- this.unmount(errorOrResult);
2121
- return;
2122
- }
2123
- this.exitResult = errorOrResult;
2124
- this.unmount();
2125
- };
2126
- getActiveCursorPosition = () => {
2127
- if (this.renderedCursorRequested) {
2128
- return this.renderedCursorPosition;
2129
- }
2130
- return this.manualCursorPosition;
2131
- };
2132
- setCursorPosition = (position) => {
2133
- this.manualCursorPosition = position;
2134
- this.log.setCursorPosition(this.getActiveCursorPosition());
2135
- };
2136
- restoreLastOutput = () => {
2137
- if (!this.interactive) {
2138
- return;
2139
- }
2140
- this.log.setCursorPosition(this.getActiveCursorPosition());
2141
- this.log(this.lastOutputToRender || `${this.lastOutput}
2142
- `);
2143
- };
2144
- calculateLayout = () => {
2145
- const flushLayoutObservers = (node) => {
2146
- const observerEntries = /* @__PURE__ */ new Map();
2147
- this.calculateScrollAndTriggerObservers(node, observerEntries);
2148
- for (const [observer, entries] of observerEntries) {
2149
- observer.internalTrigger(entries);
2150
- }
2151
- };
2152
- this.prepareYogaTree(this.rootNode, flushLayoutObservers);
2153
- const terminalWidth = getWindowSize(this.options.stdout).columns;
2154
- this.rootNode.yogaNode.setWidth(terminalWidth);
2155
- this.rootNode.yogaNode.calculateLayout(void 0, void 0, Yoga.DIRECTION_LTR);
2156
- flushLayoutObservers(this.rootNode);
2157
- };
2158
- calculateScrollAndTriggerObservers(node, observerEntries) {
2159
- if (node.nodeName === "ink-box") {
2160
- const { style } = node;
2161
- const overflow = style.overflow ?? "visible";
2162
- const overflowX = style.overflowX ?? overflow;
2163
- const overflowY = style.overflowY ?? overflow;
2164
- if (overflowX === "scroll" || overflowY === "scroll") {
2165
- calculateScroll(node);
2166
- } else if (node.internal_scrollState) {
2167
- delete node.internal_scrollState;
2168
- }
2169
- }
2170
- measureAndExtractObservers(node, observerEntries);
2171
- if (node.internal_static) {
2172
- return;
2173
- }
2174
- for (const child of node.childNodes) {
2175
- if (child.nodeName !== "#text") {
2176
- this.calculateScrollAndTriggerObservers(child, observerEntries);
2177
- }
2178
- }
2179
- }
2180
- /**
2181
- * Force a full layout recalculation by marking all text nodes dirty.
2182
- * Useful when the string width function changes or terminal font changes.
2183
- */
2184
- recalculateLayout() {
2185
- this.markAllTextNodesDirty(this.rootNode);
2186
- this.calculateLayout();
2187
- this.onRender();
2188
- }
2189
- /**
2190
- * Walks the DOM tree before Yoga layout to handle StaticRender nodes.
2191
- *
2192
- * - Re-attach Yoga children if a cached render was invalidated.
2193
- * - Pre-render ink-static-render nodes that don't have a cached render yet.
2194
- */
2195
- prepareYogaTree(node, flushLayoutObservers) {
2196
- if (node.isYogaTreeDetached && !node.cachedRender && node.yogaNode) {
2197
- node.yogaNode.setWidthAuto();
2198
- node.yogaNode.setHeightAuto();
2199
- styles(node.yogaNode, node.style);
2200
- while (node.yogaNode.getChildCount() > 0) {
2201
- node.yogaNode.getChild(0).remove();
2202
- }
2203
- let yogaIndex = 0;
2204
- for (const child of node.childNodes) {
2205
- const domChild = child;
2206
- if (child.nodeName !== "#text" && domChild.yogaNode) {
2207
- node.yogaNode.insertChild(domChild.yogaNode, yogaIndex);
2208
- yogaIndex++;
2209
- }
2210
- }
2211
- node.isYogaTreeDetached = false;
2212
- this.markAllTextNodesDirty(node);
2213
- }
2214
- for (const child of node.childNodes) {
2215
- if (child.nodeName !== "#text") {
2216
- this.prepareYogaTree(child, flushLayoutObservers);
2217
- }
2218
- }
2219
- if (node.nodeName === "ink-static-render" && !node.cachedRender) {
2220
- const terminalWidth = getWindowSize(this.options.stdout).columns;
2221
- const { width } = node.style;
2222
- if (node.yogaNode) {
2223
- node.yogaNode.setWidth(typeof width === "number" ? width : terminalWidth);
2224
- node.yogaNode.calculateLayout(void 0, void 0, Yoga.DIRECTION_LTR);
2225
- }
2226
- flushLayoutObservers(node);
2227
- renderToStatic(node, {
2228
- skipStaticElements: false});
2229
- node.internal_onRendered?.();
2230
- }
2231
- }
2232
- markAllTextNodesDirty(node) {
2233
- if (node.cachedRender) {
2234
- return;
2235
- }
2236
- if (node.nodeName === "ink-text" && node.yogaNode) {
2237
- node.yogaNode.markDirty();
2238
- }
2239
- for (const child of node.childNodes) {
2240
- if (child.nodeName !== "#text") {
2241
- this.markAllTextNodesDirty(child);
2242
- }
2243
- }
2244
- }
2245
- onRender = () => {
2246
- this.hasPendingThrottledRender = false;
2247
- if (this.isUnmounted) {
2248
- return;
2249
- }
2250
- if (!this.deferredInitDone) {
2251
- this.runDeferredInit();
2252
- }
2253
- if (this.nextRenderCommit) {
2254
- this.nextRenderCommit.resolve();
2255
- this.nextRenderCommit = void 0;
2256
- }
2257
- const renderResult = renderer(this.rootNode, this.isScreenReaderEnabled, {
2258
- useNativeRenderer: this.useNativeRenderer
2259
- });
2260
- const { cursorPosition, cursorRequested, output, outputBuffer, outputHeight, outputWidth, staticOutput } = renderResult;
2261
- this.renderedCursorRequested = cursorRequested;
2262
- this.renderedCursorPosition = cursorPosition;
2263
- if (this.useNativeRenderer && this.nativeLog && outputBuffer && outputWidth) {
2264
- if (staticOutput && staticOutput !== "\n") {
2265
- this.options.stdout.write(staticOutput);
2266
- }
2267
- this.nativeLog.render(outputBuffer, outputWidth, outputHeight);
2268
- this.lastOutputHeight = outputHeight;
2269
- return;
2270
- }
2271
- if (cursorRequested) {
2272
- this.log.setCursorPosition(this.getActiveCursorPosition());
2273
- }
2274
- const hasStaticOutput = staticOutput && staticOutput !== "\n";
2275
- if (this.options.debug) {
2276
- if (hasStaticOutput) {
2277
- this.fullStaticOutput += staticOutput;
2278
- }
2279
- this.lastOutput = output;
2280
- this.lastOutputToRender = output;
2281
- this.lastOutputHeight = outputHeight;
2282
- this.options.stdout.write(this.fullStaticOutput + output);
2283
- return;
2284
- }
2285
- if (!this.interactive) {
2286
- if (hasStaticOutput) {
2287
- this.options.stdout.write(staticOutput);
2288
- }
2289
- this.lastOutput = output;
2290
- this.lastOutputToRender = `${output}
2291
- `;
2292
- this.lastOutputHeight = outputHeight;
2293
- return;
2294
- }
2295
- if (this.isScreenReaderEnabled) {
2296
- const sync = this.shouldSync();
2297
- if (sync) {
2298
- this.options.stdout.write(bsu);
2299
- }
2300
- if (hasStaticOutput) {
2301
- const erase = this.lastOutputHeight > 0 ? eraseLines(this.lastOutputHeight) : "";
2302
- this.options.stdout.write(erase + staticOutput);
2303
- this.lastOutputHeight = 0;
2304
- }
2305
- if (output === this.lastOutput && !hasStaticOutput) {
2306
- if (sync) {
2307
- this.options.stdout.write(esu);
2308
- }
2309
- return;
2310
- }
2311
- const terminalWidth = getWindowSize(this.options.stdout).columns;
2312
- const wrappedOutput = wordWrap(output, {
2313
- trim: false,
2314
- width: terminalWidth,
2315
- wrapMode: "BREAK_WORDS"
2316
- }).replace(/\n$/, "");
2317
- if (hasStaticOutput) {
2318
- this.options.stdout.write(wrappedOutput);
2319
- } else {
2320
- const erase = this.lastOutputHeight > 0 ? eraseLines(this.lastOutputHeight) : "";
2321
- this.options.stdout.write(erase + wrappedOutput);
2322
- }
2323
- this.lastOutput = output;
2324
- this.lastOutputToRender = wrappedOutput;
2325
- this.lastOutputHeight = wrappedOutput === "" ? 0 : wrappedOutput.split("\n").length;
2326
- if (sync) {
2327
- this.options.stdout.write(esu);
2328
- }
2329
- return;
2330
- }
2331
- if (hasStaticOutput) {
2332
- this.fullStaticOutput += staticOutput;
2333
- }
2334
- this.renderInteractiveFrame(output, outputHeight, hasStaticOutput ? staticOutput : "");
2335
- };
2336
- // Cache AccessibilityContext value to avoid creating a new object
2337
- // on every render() call, which would force all consumers to re-render.
2338
- accessibilityContextValue;
2339
- render(node) {
2340
- this.accessibilityContextValue ??= { isScreenReaderEnabled: this.isScreenReaderEnabled };
2341
- const tree = jsx(accessibilityContext.Provider, { value: this.accessibilityContextValue, children: jsx(
2342
- App,
2343
- {
2344
- exitOnCtrlC: this.options.exitOnCtrlC,
2345
- interactive: this.interactive,
2346
- onExit: this.handleAppExit,
2347
- onWaitUntilRenderFlush: this.waitUntilRenderFlush,
2348
- renderThrottleMs: this.renderThrottleMs,
2349
- setCursorPosition: this.setCursorPosition,
2350
- stderr: this.options.stderr,
2351
- stdin: this.options.stdin,
2352
- stdout: this.options.stdout,
2353
- writeToStderr: this.writeToStderr,
2354
- writeToStdout: this.writeToStdout,
2355
- children: node
2356
- }
2357
- ) });
2358
- if (this.options.concurrent) {
2359
- reconcilerInstance.updateContainer(tree, this.container, null, noop);
2360
- } else {
2361
- reconcilerInstance.updateContainerSync(tree, this.container, null, noop);
2362
- reconcilerInstance.flushSyncWork();
2363
- }
2364
- }
2365
- writeToStdout = (data) => {
2366
- if (this.isUnmounted) {
2367
- return;
2368
- }
2369
- if (this.options.debug) {
2370
- this.options.stdout.write(data + this.fullStaticOutput + this.lastOutput);
2371
- return;
2372
- }
2373
- if (!this.interactive) {
2374
- this.options.stdout.write(data);
2375
- return;
2376
- }
2377
- const sync = this.shouldSync();
2378
- if (sync) {
2379
- this.options.stdout.write(bsu);
2380
- }
2381
- this.log.clear();
2382
- this.options.stdout.write(data);
2383
- this.restoreLastOutput();
2384
- if (sync) {
2385
- this.options.stdout.write(esu);
2386
- }
2387
- };
2388
- writeToStderr = (data) => {
2389
- if (this.isUnmounted) {
2390
- return;
2391
- }
2392
- if (this.options.debug) {
2393
- this.options.stderr.write(data);
2394
- this.options.stdout.write(this.fullStaticOutput + this.lastOutput);
2395
- return;
2396
- }
2397
- if (!this.interactive) {
2398
- this.options.stderr.write(data);
2399
- return;
2400
- }
2401
- const sync = this.shouldSync();
2402
- if (sync) {
2403
- this.options.stdout.write(bsu);
2404
- }
2405
- this.log.clear();
2406
- this.options.stderr.write(data);
2407
- this.restoreLastOutput();
2408
- if (sync) {
2409
- this.options.stdout.write(esu);
2410
- }
2411
- };
2412
- unmount = (error) => {
2413
- if (this.isUnmounted || this.isUnmounting) {
2414
- return;
2415
- }
2416
- this.isUnmounting = true;
2417
- if (this.beforeExitHandler) {
2418
- process$2.off("beforeExit", this.beforeExitHandler);
2419
- this.beforeExitHandler = void 0;
2420
- }
2421
- const stdout = this.options.stdout;
2422
- const { canWriteToStdout, hasWritableState } = getWritableStreamState(stdout);
2423
- settleThrottle(this.throttledOnRender, canWriteToStdout);
2424
- if (canWriteToStdout && !this.alternateScreen) {
2425
- const shouldRenderFinalFrame = !this.throttledOnRender || !this.hasPendingThrottledRender && this.fullStaticOutput === "";
2426
- if (shouldRenderFinalFrame) {
2427
- this.calculateLayout();
2428
- this.onRender();
2429
- }
2430
- }
2431
- this.isUnmounted = true;
2432
- this.unsubscribeExit();
2433
- settleThrottle(this.throttledLog, canWriteToStdout);
2434
- if (typeof this.restoreConsole === "function") {
2435
- this.restoreConsole();
2436
- }
2437
- const finishUnmount = () => {
2438
- if (typeof this.unsubscribeResize === "function") {
2439
- this.unsubscribeResize();
2440
- }
2441
- if (this.cancelKittyDetection) {
2442
- this.cancelKittyDetection();
2443
- }
2444
- if (canWriteToStdout) {
2445
- if (this.kittyProtocolEnabled) {
2446
- this.writeBestEffort(this.options.stdout, "\x1B[<u");
2447
- }
2448
- if (this.alternateScreen) {
2449
- this.log.clear();
2450
- this.log.done();
2451
- this.lastOutput = "";
2452
- this.lastOutputToRender = "";
2453
- this.lastOutputHeight = 0;
2454
- this.fullStaticOutput = "";
2455
- this.writeBestEffort(this.options.stdout, ALT_SCREEN_OFF);
2456
- this.writeBestEffort(this.options.stdout, cursorShow);
2457
- this.alternateScreen = false;
2458
- } else if (!this.interactive) {
2459
- this.options.stdout.write(this.options.debug ? "\n" : `${this.lastOutput}
2460
- `);
2461
- } else if (!this.options.debug) {
2462
- this.log.done();
2463
- }
2464
- }
2465
- this.kittyProtocolEnabled = false;
2466
- instances.delete(this.options.stdout);
2467
- const { exitResult } = this;
2468
- const resolveOrReject = () => {
2469
- if (isErrorInput(error)) {
2470
- this.rejectExitPromise(error);
2471
- } else {
2472
- this.resolveExitPromise(exitResult);
2473
- }
2474
- };
2475
- const isProcessExiting = error !== void 0 && !isErrorInput(error);
2476
- if (isProcessExiting) {
2477
- resolveOrReject();
2478
- } else if (canWriteToStdout && hasWritableState) {
2479
- this.options.stdout.write("", resolveOrReject);
2480
- } else {
2481
- setImmediate(resolveOrReject);
2482
- }
2483
- };
2484
- const concurrentReconciler = reconcilerInstance;
2485
- if (this.options.concurrent) {
2486
- reconcilerInstance.updateContainerSync(null, this.container, null, noop);
2487
- reconcilerInstance.flushSyncWork();
2488
- concurrentReconciler.flushPassiveEffects?.();
2489
- finishUnmount();
2490
- } else {
2491
- reconcilerInstance.updateContainerSync(null, this.container, null, noop);
2492
- reconcilerInstance.flushSyncWork();
2493
- finishUnmount();
2494
- }
2495
- };
2496
- async waitUntilExit() {
2497
- if (!this.beforeExitHandler) {
2498
- this.beforeExitHandler = () => {
2499
- this.unmount();
2500
- };
2501
- process$2.on("beforeExit", this.beforeExitHandler);
2502
- }
2503
- return this.exitPromise;
2504
- }
2505
- async waitUntilRenderFlush() {
2506
- if (this.isUnmounted || this.isUnmounting) {
2507
- await this.awaitExit();
2508
- return;
2509
- }
2510
- await yieldImmediate();
2511
- if (this.isUnmounted || this.isUnmounting) {
2512
- await this.awaitExit();
2513
- return;
2514
- }
2515
- if (this.isConcurrent && this.hasPendingConcurrentWork()) {
2516
- await Promise.race([this.awaitNextRender(), this.awaitExit()]);
2517
- if (this.isUnmounted || this.isUnmounting) {
2518
- this.nextRenderCommit = void 0;
2519
- await this.awaitExit();
2520
- return;
2521
- }
2522
- }
2523
- reconcilerInstance.flushSyncWork();
2524
- const stdout = this.options.stdout;
2525
- const { canWriteToStdout, hasWritableState } = getWritableStreamState(stdout);
2526
- settleThrottle(this.throttledOnRender, canWriteToStdout);
2527
- settleThrottle(this.throttledLog, canWriteToStdout);
2528
- if (canWriteToStdout && hasWritableState) {
2529
- await new Promise((resolve) => {
2530
- this.options.stdout.write("", () => {
2531
- resolve();
2532
- });
2533
- });
2534
- return;
2535
- }
2536
- await yieldImmediate();
2537
- }
2538
- clear() {
2539
- if (this.interactive && !this.options.debug) {
2540
- this.log.clear();
2541
- this.log.sync(this.lastOutputToRender || `${this.lastOutput}
2542
- `);
2543
- }
2544
- }
2545
- patchConsole() {
2546
- if (this.options.debug) {
2547
- return;
2548
- }
2549
- this.restoreConsole = patchConsole((stream, data) => {
2550
- if (stream === "stdout") {
2551
- this.writeToStdout(data);
2552
- }
2553
- if (stream === "stderr") {
2554
- const isReactMessage = data.startsWith("The above error occurred");
2555
- if (!isReactMessage) {
2556
- this.writeToStderr(data);
2557
- }
2558
- }
2559
- });
2560
- }
2561
- setAlternateScreen(enabled) {
2562
- this.alternateScreen = this.resolveAlternateScreenOption(enabled, this.interactive);
2563
- if (this.alternateScreen) {
2564
- this.writeBestEffort(this.options.stdout, ALT_SCREEN_ON);
2565
- this.writeBestEffort(this.options.stdout, cursorHide);
2566
- }
2567
- }
2568
- resolveInteractiveOption(interactive) {
2569
- return interactive ?? (!isInCi && Boolean(this.options.stdout.isTTY));
2570
- }
2571
- resolveAlternateScreenOption(alternateScreen, interactive) {
2572
- return Boolean(alternateScreen) && interactive && Boolean(this.options.stdout.isTTY);
2573
- }
2574
- shouldSync() {
2575
- return shouldSynchronize(this.options.stdout, this.interactive);
2576
- }
2577
- // Best-effort write: streams may already be destroyed during shutdown.
2578
- writeBestEffort(stream, data) {
2579
- try {
2580
- stream.write(data);
2581
- } catch {
2582
- }
2583
- }
2584
- // Waits for the exit promise to settle, suppressing any rejection.
2585
- // Errors are surfaced via waitUntilExit() instead.
2586
- async awaitExit() {
2587
- try {
2588
- await this.exitPromise;
2589
- } catch {
2590
- }
2591
- }
2592
- hasPendingConcurrentWork() {
2593
- const concurrentContainer = this.container;
2594
- return (concurrentContainer.pendingLanes ?? 0) !== 0 && concurrentContainer.callbackNode !== void 0 && concurrentContainer.callbackNode !== null;
2595
- }
2596
- async awaitNextRender() {
2597
- if (!this.nextRenderCommit) {
2598
- let resolveRender;
2599
- const promise = new Promise((resolve) => {
2600
- resolveRender = resolve;
2601
- });
2602
- this.nextRenderCommit = { promise, resolve: resolveRender };
2603
- }
2604
- return this.nextRenderCommit.promise;
2605
- }
2606
- renderInteractiveFrame(output, outputHeight, staticOutput) {
2607
- const hasStaticOutput = staticOutput !== "";
2608
- const isTty = this.options.stdout.isTTY;
2609
- const viewportRows = isTty ? getWindowSize(this.options.stdout).rows : 24;
2610
- const isFullscreen = isTty && outputHeight >= viewportRows;
2611
- const outputToRender = isFullscreen ? output : `${output}
2612
- `;
2613
- const shouldClearTerminal = shouldClearTerminalForFrame({
2614
- isTty,
2615
- isUnmounting: this.isUnmounting,
2616
- nextOutputHeight: outputHeight,
2617
- previousOutputHeight: this.lastOutputHeight,
2618
- viewportRows
2619
- });
2620
- if (shouldClearTerminal) {
2621
- if (this.options.incrementalRendering) {
2622
- if (hasStaticOutput) {
2623
- this.log.clear();
2624
- this.options.stdout.write(staticOutput);
2625
- }
2626
- if (output !== this.lastOutput || this.log.isCursorDirty() || hasStaticOutput) {
2627
- this.throttledLog(outputToRender);
2628
- }
2629
- this.lastOutput = output;
2630
- this.lastOutputToRender = outputToRender;
2631
- this.lastOutputHeight = outputHeight;
2632
- return;
2633
- }
2634
- const sync = this.shouldSync();
2635
- if (sync) {
2636
- this.options.stdout.write(bsu);
2637
- }
2638
- this.options.stdout.write(clearScreenAndHomeCursor + this.fullStaticOutput + output);
2639
- this.lastOutput = output;
2640
- this.lastOutputToRender = outputToRender;
2641
- this.lastOutputHeight = outputHeight;
2642
- this.log.sync(outputToRender);
2643
- if (sync) {
2644
- this.options.stdout.write(esu);
2645
- }
2646
- return;
2647
- }
2648
- if (hasStaticOutput) {
2649
- const sync = this.shouldSync();
2650
- if (sync) {
2651
- this.options.stdout.write(bsu);
2652
- }
2653
- this.log.clear();
2654
- this.options.stdout.write(staticOutput);
2655
- this.log(outputToRender);
2656
- if (sync) {
2657
- this.options.stdout.write(esu);
2658
- }
2659
- } else if (output !== this.lastOutput || this.log.isCursorDirty()) {
2660
- this.throttledLog(outputToRender);
2661
- }
2662
- this.lastOutput = output;
2663
- this.lastOutputToRender = outputToRender;
2664
- this.lastOutputHeight = outputHeight;
2665
- }
2666
- /**
2667
- * Handle kitty keyboard "enabled" mode immediately (just a stdout.write).
2668
- * Called from the constructor.
2669
- */
2670
- initImmediateKittyKeyboard() {
2671
- if (!this.options.kittyKeyboard) {
2672
- return;
2673
- }
2674
- const options = this.options.kittyKeyboard;
2675
- const mode = options.mode ?? "auto";
2676
- if (mode !== "enabled") {
2677
- return;
2678
- }
2679
- const flags = options.flags ?? ["disambiguateEscapeCodes"];
2680
- if (this.options.stdin.isTTY && this.options.stdout.isTTY) {
2681
- this.enableKittyProtocol(flags);
2682
- }
2683
- }
2684
- /**
2685
- * Handle kitty keyboard "auto" mode detection. Deferred to first render
2686
- * because the CSI ? u query sets up a stdin listener with a 200ms timeout.
2687
- */
2688
- initDeferredKittyKeyboard() {
2689
- if (!this.options.kittyKeyboard) {
2690
- return;
2691
- }
2692
- const options = this.options.kittyKeyboard;
2693
- const mode = options.mode ?? "auto";
2694
- if (mode !== "auto") {
2695
- return;
2696
- }
2697
- const flags = options.flags ?? ["disambiguateEscapeCodes"];
2698
- if (!this.interactive || !this.options.stdin.isTTY || !this.options.stdout.isTTY) {
2699
- return;
2700
- }
2701
- this.confirmKittySupport(flags);
2702
- }
2703
- confirmKittySupport(flags) {
2704
- const { stdin, stdout } = this.options;
2705
- let responseBuffer = [];
2706
- const cleanup = () => {
2707
- this.cancelKittyDetection = void 0;
2708
- clearTimeout(timer);
2709
- stdin.removeListener("data", onData);
2710
- const remaining = stripKittyQueryResponsesAndTrailingPartial(responseBuffer);
2711
- responseBuffer = [];
2712
- if (remaining.length > 0) {
2713
- stdin.unshift(Buffer.from(remaining));
2714
- }
2715
- };
2716
- const onData = (data) => {
2717
- const chunk = typeof data === "string" ? Buffer.from(data) : data;
2718
- for (const byte of chunk) {
2719
- responseBuffer.push(byte);
2720
- }
2721
- if (hasCompleteKittyQueryResponse(responseBuffer)) {
2722
- cleanup();
2723
- if (!this.isUnmounted) {
2724
- this.enableKittyProtocol(flags);
2725
- }
2726
- }
2727
- };
2728
- stdin.on("data", onData);
2729
- const timer = setTimeout(cleanup, 200);
2730
- this.cancelKittyDetection = cleanup;
2731
- stdout.write("\x1B[?u");
2732
- }
2733
- enableKittyProtocol(flags) {
2734
- this.options.stdout.write(`\x1B[>${resolveFlags(flags)}u`);
2735
- this.kittyProtocolEnabled = true;
2736
- }
2737
- }
2738
-
2739
- const render = (node, options) => {
2740
- const inkOptions = {
2741
- alternateScreen: false,
2742
- concurrent: false,
2743
- debug: false,
2744
- exitOnCtrlC: true,
2745
- incrementalRendering: false,
2746
- maxFps: 30,
2747
- patchConsole: true,
2748
- stderr: process$2.stderr,
2749
- stdin: process$2.stdin,
2750
- stdout: process$2.stdout,
2751
- ...getOptions(options)
2752
- };
2753
- const instance = getInstance(inkOptions.stdout, () => new Ink(inkOptions));
2754
- instance.render(node);
2755
- return {
2756
- cleanup() {
2757
- instance.unmount();
2758
- },
2759
- clear() {
2760
- instance.clear();
2761
- },
2762
- rerender(n) {
2763
- instance.render(n);
2764
- },
2765
- rootNode: instance.rootNode,
2766
- unmount() {
2767
- instance.unmount();
2768
- },
2769
- waitUntilExit() {
2770
- return instance.waitUntilExit();
2771
- },
2772
- waitUntilRenderFlush() {
2773
- return instance.waitUntilRenderFlush();
2774
- }
2775
- };
2776
- };
2777
- const getOptions = (stdout = {}) => {
2778
- if (stdout instanceof Stream) {
2779
- return {
2780
- stdin: process$2.stdin,
2781
- stdout
2782
- };
2783
- }
2784
- return stdout;
2785
- };
2786
- const getInstance = (stdout, createInstance) => {
2787
- const instance = instances.get(stdout);
2788
- if (instance === void 0) {
2789
- const newInstance = createInstance();
2790
- instances.set(stdout, newInstance);
2791
- return newInstance;
2792
- }
2793
- process$2.stderr.write(
2794
- "Warning: render() was called again for the same stdout before the previous Ink instance was unmounted. Reusing stdout across multiple render() calls is unsupported. Call unmount() first.\n"
2795
- );
2796
- return instance;
2797
- };
2798
-
2799
- export { render as default };