@visulima/tui 2.0.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## @visulima/tui [4.0.0](https://github.com/visulima/visulima/compare/%40visulima%2Ftui%403.0.0...%40visulima%2Ftui%404.0.0) (2026-08-08)
2
+
3
+
4
+ ### Dependencies
5
+
6
+ * **@visulima/colorize:** upgraded to 2.1.1
7
+ * **@visulima/boxen:** upgraded to 4.0.0
8
+
9
+ ## @visulima/tui [3.0.0](https://github.com/visulima/visulima/compare/%40visulima%2Ftui%402.0.1...%40visulima%2Ftui%403.0.0) (2026-08-02)
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * **@visulima/ansi:** upgraded to 4.1.0
15
+ * **@visulima/colorize:** upgraded to 2.1.0
16
+ * **@visulima/error:** upgraded to 6.1.0
17
+ * **@visulima/string:** upgraded to 3.1.0
18
+ * **@visulima/boxen:** upgraded to 3.1.0
19
+
1
20
  ## @visulima/tui [2.0.1](https://github.com/visulima/visulima/compare/%40visulima%2Ftui%402.0.0...%40visulima%2Ftui%402.0.1) (2026-07-27)
2
21
 
3
22
  ## @visulima/tui [2.0.0](https://github.com/visulima/visulima/compare/%40visulima%2Ftui%401.0.8...%40visulima%2Ftui%402.0.0) (2026-07-27)
@@ -1,4 +1,4 @@
1
- export { I as InlineLoop, a as InlineOptions, b as InlinePaintFn, c as InputParser, M as MouseEvent, T as TuiApp, d as createInlineLoop } from "../packem_shared/input.d-Bb8pWHvp.js";
1
+ export { I as InlineLoop, a as InlineOptions, b as InlinePaintFn, c as InputParser, M as MouseEvent, T as TuiApp, d as createInlineLoop } from "../packem_shared/input.d-CL_4MfL-.js";
2
2
  /**
3
3
  * 2×u32 per-cell back-buffer layout:
4
4
  * buffer[idx * 2] = charCode (Unicode codepoint, u32)
@@ -1 +1 @@
1
- import{TuiApp as o}from"../packem_shared/TuiApp-CCVaiKbf.js";import{Cell as t,StyleMasks as m}from"../packem_shared/Cell-BrXn3jxY.js";import{createInlineLoop as l}from"../packem_shared/createInlineLoop-DnEvE2eM.js";import{InputParser as f}from"../packem_shared/InputParser-CiBitCva.js";import{Renderer as x,TerminalGuard as s,terminalSize as u}from"../packem_shared/Renderer-BeS49FNq.js";export{t as Cell,f as InputParser,x as Renderer,m as StyleMasks,s as TerminalGuard,o as TuiApp,l as createInlineLoop,u as terminalSize};
1
+ import{TuiApp as o}from"../packem_shared/TuiApp-CCVaiKbf.js";import{Cell as t,StyleMasks as m}from"../packem_shared/Cell-BrXn3jxY.js";import{createInlineLoop as l}from"../packem_shared/createInlineLoop-BMDYJkRp.js";import{InputParser as f}from"../packem_shared/InputParser-CUAGWKQQ.js";import{Renderer as x,TerminalGuard as s,terminalSize as u}from"../packem_shared/Renderer-BeS49FNq.js";export{t as Cell,f as InputParser,x as Renderer,m as StyleMasks,s as TerminalGuard,o as TuiApp,l as createInlineLoop,u as terminalSize};
package/dist/ink/index.js CHANGED
@@ -1 +1 @@
1
- import{clearOsc52 as o,isOsc52Supported as r,writeOsc52 as a}from"../packem_shared/clearOsc52-BUpnQOav.js";import{COLOR_BLINDNESS_COMPENSATION as l,COLOR_BLINDNESS_SIMULATION as i,IDENTITY_MATRIX as n,applyColorMatrix as u,hexToRgb as f,rgbToHex as p,transformHexColor as c}from"../packem_shared/COLOR_BLINDNESS_COMPENSATION-Ilnoyeqc.js";import{g as d,i as x}from"../packem_shared/dom-rphpG0kf.js";import{IMECompositionBuffer as S,isIMEInput as h}from"../packem_shared/IMECompositionBuffer-VhC9HRCv.js";import{kittyFlags as M,kittyModifiers as O}from"../packem_shared/kittyFlags-g8ALyoCU.js";import{processLayout as I}from"../packem_shared/processLayout-I83k6vXE.js";import{c as b,a as C,b as E,g as R,d as N,e as B,f as P,h as H,i as v,j as W,k,l as A,R as _}from"../packem_shared/measure-element-D4M9iSYp.js";import{c as F,a as z,i as q,s as w,b as j,t as Q}from"../packem_shared/measure-text-B7juNq4Y.js";import{default as V}from"../packem_shared/render-CuCo-R-l.js";import{default as Y}from"../packem_shared/renderToString-B1LgWcJe.js";import{default as J,ResizeObserverEntry as K}from"../packem_shared/ResizeObserver-BI9bDy-j.js";import{calculateScroll as $,getScrollHeight as ee,getScrollLeft as te,getScrollTop as oe,getScrollWidth as re}from"../packem_shared/calculateScroll-D4Y_JR4H.js";import{Range as se,Selection as le,applySelectionToStyledLine as ie,comparePoints as ne}from"../packem_shared/Range-BsVYNWtg.js";import{squashTextNodesWithMap as fe}from"../packem_shared/squashTextNodesWithMap-BmUSBPfc.js";import{isTerminalPaletteQuerySupported as ce,queryTerminalPalette as me}from"../packem_shared/isTerminalPaletteQuerySupported-BYzmqq9-.js";import{wrapOrTruncateStyledLine as xe}from"../packem_shared/wrapOrTruncateStyledLine-46W8bTtv.js";import{default as Se}from"../packem_shared/Fullscreen-BRhuBLBh.js";import{default as Te}from"../packem_shared/MouseProvider-DOcWCRVq.js";import{default as Oe}from"../packem_shared/isIntersecting-Bo2npvMR.js";import{default as Ie}from"./mouse/use-mouse-action.js";import{default as be}from"./mouse/use-mouse.js";import{default as Ee}from"./mouse/use-mouse-position.js";import{default as Ne}from"./mouse/use-on-mouse-hover.js";import{default as Pe}from"./mouse/use-on-mouse-state.js";import{d as ve}from"../packem_shared/ansi-parser-DlgLtOYO.js";import{useElementDimensions as ke,useElementPosition as Ae}from"./mouse/use-element-position.js";import{useOnMouseClick as De}from"./mouse/use-on-mouse-click.js";export{l as COLOR_BLINDNESS_COMPENSATION,i as COLOR_BLINDNESS_SIMULATION,Se as Fullscreen,n as IDENTITY_MATRIX,S as IMECompositionBuffer,Te as MouseProvider,se as Range,J as ResizeObserver,K as ResizeObserverEntry,le as Selection,u as applyColorMatrix,ie as applySelectionToStyledLine,$ as calculateScroll,b as calculateScrollbarLayout,C as calculateScrollbarThumb,o as clearOsc52,F as clearStringWidthCache,z as clearStyledLineCache,E as collectSortedFragments,ne as comparePoints,R as getAddedScrollHeight,N as getBoundingBox,B as getHorizontalScrollbarBoundingBox,P as getInnerHeight,H as getInnerWidth,d as getPathToRoot,v as getRelativeLeft,W as getRelativeTop,ee as getScrollHeight,te as getScrollLeft,oe as getScrollTop,re as getScrollWidth,k as getText,A as getVerticalScrollbarBoundingBox,f as hexToRgb,q as inkCharacterWidth,h as isIMEInput,Oe as isIntersecting,x as isNodeSelectable,r as isOsc52Supported,ce as isTerminalPaletteQuerySupported,M as kittyFlags,O as kittyModifiers,_ as measureElement,ve as parseSgrMouse,I as processLayout,me as queryTerminalPalette,V as render,Y as renderToString,p as rgbToHex,w as setEnableStyledLineCache,j as setStringWidthFunction,fe as squashTextNodesWithMap,Q as toStyledLine,c as transformHexColor,ke as useElementDimensions,Ae as useElementPosition,Ie as useMouseAction,be as useMouseContext,Ee as useMousePosition,De as useOnMouseClick,Ne as useOnMouseHover,Pe as useOnMouseState,xe as wrapOrTruncateStyledLine,a as writeOsc52};
1
+ import{clearOsc52 as o,isOsc52Supported as r,writeOsc52 as a}from"../packem_shared/clearOsc52-BUpnQOav.js";import{COLOR_BLINDNESS_COMPENSATION as l,COLOR_BLINDNESS_SIMULATION as i,IDENTITY_MATRIX as n,applyColorMatrix as u,hexToRgb as f,rgbToHex as p,transformHexColor as c}from"../packem_shared/COLOR_BLINDNESS_COMPENSATION-Ilnoyeqc.js";import{g as d,i as x}from"../packem_shared/dom-rphpG0kf.js";import{IMECompositionBuffer as S,isIMEInput as h}from"../packem_shared/IMECompositionBuffer-VhC9HRCv.js";import{kittyFlags as M,kittyModifiers as O}from"../packem_shared/kittyFlags-g8ALyoCU.js";import{processLayout as I}from"../packem_shared/processLayout-I83k6vXE.js";import{c as b,a as C,b as E,g as R,d as N,e as B,f as P,h as H,i as v,j as W,k,l as A,R as _}from"../packem_shared/measure-element-D4M9iSYp.js";import{c as F,a as z,i as q,s as w,b as j,t as Q}from"../packem_shared/measure-text-B7juNq4Y.js";import{default as V}from"../packem_shared/render-CvhjGwOg.js";import{default as Y}from"../packem_shared/renderToString-B1LgWcJe.js";import{default as J,ResizeObserverEntry as K}from"../packem_shared/ResizeObserver-BI9bDy-j.js";import{calculateScroll as $,getScrollHeight as ee,getScrollLeft as te,getScrollTop as oe,getScrollWidth as re}from"../packem_shared/calculateScroll-D4Y_JR4H.js";import{Range as se,Selection as le,applySelectionToStyledLine as ie,comparePoints as ne}from"../packem_shared/Range-BsVYNWtg.js";import{squashTextNodesWithMap as fe}from"../packem_shared/squashTextNodesWithMap-BmUSBPfc.js";import{isTerminalPaletteQuerySupported as ce,queryTerminalPalette as me}from"../packem_shared/isTerminalPaletteQuerySupported-BYzmqq9-.js";import{wrapOrTruncateStyledLine as xe}from"../packem_shared/wrapOrTruncateStyledLine-46W8bTtv.js";import{default as Se}from"../packem_shared/Fullscreen-BRhuBLBh.js";import{default as Te}from"../packem_shared/MouseProvider-DOcWCRVq.js";import{default as Oe}from"../packem_shared/isIntersecting-Bo2npvMR.js";import{default as Ie}from"./mouse/use-mouse-action.js";import{default as be}from"./mouse/use-mouse.js";import{default as Ee}from"./mouse/use-mouse-position.js";import{default as Ne}from"./mouse/use-on-mouse-hover.js";import{default as Pe}from"./mouse/use-on-mouse-state.js";import{d as ve}from"../packem_shared/ansi-parser-DlgLtOYO.js";import{useElementDimensions as ke,useElementPosition as Ae}from"./mouse/use-element-position.js";import{useOnMouseClick as De}from"./mouse/use-on-mouse-click.js";export{l as COLOR_BLINDNESS_COMPENSATION,i as COLOR_BLINDNESS_SIMULATION,Se as Fullscreen,n as IDENTITY_MATRIX,S as IMECompositionBuffer,Te as MouseProvider,se as Range,J as ResizeObserver,K as ResizeObserverEntry,le as Selection,u as applyColorMatrix,ie as applySelectionToStyledLine,$ as calculateScroll,b as calculateScrollbarLayout,C as calculateScrollbarThumb,o as clearOsc52,F as clearStringWidthCache,z as clearStyledLineCache,E as collectSortedFragments,ne as comparePoints,R as getAddedScrollHeight,N as getBoundingBox,B as getHorizontalScrollbarBoundingBox,P as getInnerHeight,H as getInnerWidth,d as getPathToRoot,v as getRelativeLeft,W as getRelativeTop,ee as getScrollHeight,te as getScrollLeft,oe as getScrollTop,re as getScrollWidth,k as getText,A as getVerticalScrollbarBoundingBox,f as hexToRgb,q as inkCharacterWidth,h as isIMEInput,Oe as isIntersecting,x as isNodeSelectable,r as isOsc52Supported,ce as isTerminalPaletteQuerySupported,M as kittyFlags,O as kittyModifiers,_ as measureElement,ve as parseSgrMouse,I as processLayout,me as queryTerminalPalette,V as render,Y as renderToString,p as rgbToHex,w as setEnableStyledLineCache,j as setStringWidthFunction,fe as squashTextNodesWithMap,Q as toStyledLine,c as transformHexColor,ke as useElementDimensions,Ae as useElementPosition,Ie as useMouseAction,be as useMouseContext,Ee as useMousePosition,De as useOnMouseClick,Ne as useOnMouseHover,Pe as useOnMouseState,xe as wrapOrTruncateStyledLine,a as writeOsc52};
@@ -1 +1 @@
1
- import{jsxs as l,jsx as u}from"react/jsx-runtime";import{useState as p,useRef as s,useEffect as h}from"react";import{useWindowSize as x,useTuiContext as w}from"./TuiContext-BNmP0lMY.js";import{_Box as i,_Spacer as S,_Text as D}from"./render-DtQd8qQq.js";function T(){const{app:r}=w(),[t,c]=p(0),e=s(0),n=s(Date.now()),o=s(null);return h(()=>{const m=()=>{o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{c(0),e.current=0,n.current=Date.now()},2e3),e.current++;const d=Date.now(),f=d-n.current;f>=500&&(c(Math.round(e.current/f*1e3)),e.current=0,n.current=d)},a=r.onBeforeFlush(()=>{m()});return()=>{a(),o.current&&clearTimeout(o.current)}},[r]),t}const b=({fps:r})=>{const t=r===0?"--":String(r);return u(i,{borderColor:"gray",borderStyle:"round",paddingX:1,children:l(D,{dim:!0,children:[t," ","updates/sec"]})})},B=({children:r,enabled:t=!0})=>{const c=T(),{columns:e,rows:n}=x();return l(i,{flexDirection:"column",height:n,width:e,children:[u(i,{flexGrow:1,children:r}),t&&l(i,{flexDirection:"row",flexShrink:0,children:[u(S,{}),u(b,{fps:c})]})]})};export{B as DevTools};
1
+ import{jsxs as l,jsx as u}from"react/jsx-runtime";import{useState as p,useRef as s,useEffect as h}from"react";import{useWindowSize as x,useTuiContext as w}from"./TuiContext-BNmP0lMY.js";import{_Box as i,_Spacer as S,_Text as D}from"./render-CPVY5vpQ.js";function T(){const{app:r}=w(),[t,c]=p(0),e=s(0),n=s(Date.now()),o=s(null);return h(()=>{const m=()=>{o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{c(0),e.current=0,n.current=Date.now()},2e3),e.current++;const d=Date.now(),f=d-n.current;f>=500&&(c(Math.round(e.current/f*1e3)),e.current=0,n.current=d)},a=r.onBeforeFlush(()=>{m()});return()=>{a(),o.current&&clearTimeout(o.current)}},[r]),t}const b=({fps:r})=>{const t=r===0?"--":String(r);return u(i,{borderColor:"gray",borderStyle:"round",paddingX:1,children:l(D,{dim:!0,children:[t," ","updates/sec"]})})},B=({children:r,enabled:t=!0})=>{const c=T(),{columns:e,rows:n}=x();return l(i,{flexDirection:"column",height:n,width:e,children:[u(i,{flexGrow:1,children:r}),t&&l(i,{flexDirection:"row",flexShrink:0,children:[u(S,{}),u(b,{fps:c})]})]})};export{B as DevTools};
@@ -0,0 +1 @@
1
+ import E,{createContext as R,useRef as S,useState as I,useCallback as s,useMemo as P,useContext as C,useEffect as p}from"react";const m=R({activate(){},activeId:void 0,add(){},deactivate(){},disableFocus(){},enableFocus(){},focus(){},focusNext(){},focusPrevious(){},remove(){}});m.displayName="TuiFocusContext";const y=({children:i})=>{const u=S([]),[a,o]=I(void 0),[n,v]=I(!0),f=s((t,e)=>{if(u.current.some(r=>r.id===t))return;const d={autoFocus:e.autoFocus,id:t,isActive:!0};u.current=[...u.current,d],o(r=>e.autoFocus&&r===void 0||u.current.filter(M=>M.isActive).length===1&&r===void 0?t:r)},[]),l=s(t=>{u.current=u.current.filter(e=>e.id!==t),o(e=>e===t?void 0:e)},[]),F=s(t=>{u.current=u.current.map(e=>e.id===t?{...e,isActive:!0}:e)},[]),c=s(t=>{u.current=u.current.map(e=>e.id===t?{...e,isActive:!1}:e),o(e=>e===t?void 0:e)},[]),x=s(()=>v(!0),[]),b=s(()=>{v(!1),o(void 0)},[]),g=s(()=>{if(!n)return;const t=u.current.filter(e=>e.isActive);t.length!==0&&o(e=>{if(e===void 0)return t[0]?.id;const d=t.findIndex(r=>r.id===e);return t[(d+1)%t.length]?.id??t[0]?.id})},[n]),h=s(()=>{if(!n)return;const t=u.current.filter(e=>e.isActive);t.length!==0&&o(e=>{if(e===void 0)return t.at(-1)?.id;const d=t.findIndex(r=>r.id===e);return t[(d-1+t.length)%t.length]?.id??t.at(-1)?.id})},[n]),A=s(t=>{n&&u.current.some(e=>e.id===t&&e.isActive)&&o(t)},[n]),N=P(()=>({activate:F,activeId:a,add:f,deactivate:c,disableFocus:b,enableFocus:x,focus:A,focusNext:g,focusPrevious:h,remove:l}),[a,f,l,F,c,x,b,g,h,A]);return E.createElement(m.Provider,{value:N},i)},T=({autoFocus:i=!1,id:u,isActive:a=!0}={})=>{const{activate:o,activeId:n,add:v,deactivate:f,focus:l,remove:F}=C(m),c=P(()=>u??Math.random().toString(36).slice(2,7),[u]);return p(()=>(v(c,{autoFocus:i}),()=>{F(c)}),[c,i]),p(()=>{a?o(c):f(c)},[a,c]),{focus:l,isFocused:!!c&&n===c}},j=()=>{const i=C(m);return{activeId:i.activeId,disableFocus:i.disableFocus,enableFocus:i.enableFocus,focus:i.focus,focusNext:i.focusNext,focusPrevious:i.focusPrevious}};export{m as FocusContext,y as FocusProvider,T as useFocus,j as useFocusManager};
@@ -0,0 +1,2 @@
1
+ import{l as c}from"./index-Dl9I2_QH.js";const u="\x1B[200~",o="\x1B[201~",p=1024*1024;class w extends c.EventEmitter{constructor(t){super(),this.stdin=t}stdin;_boundHandleData=null;_pasteBuffer=null;start(){typeof this.stdin.setRawMode=="function"&&this.stdin.setRawMode(!0),this.stdin.resume(),this.stdin.setEncoding("utf8"),this._boundHandleData=this.handleData.bind(this),this.stdin.on("data",this._boundHandleData)}stop(){typeof this.stdin.setRawMode=="function"&&this.stdin.setRawMode(!1),this.stdin.pause(),this._boundHandleData&&(this.stdin.removeListener("data",this._boundHandleData),this._boundHandleData=null)}handleData(t){if(t===""){this.emit("exit");return}if(this._pasteBuffer!==null||t.includes(u)){let e=t;if(this._pasteBuffer===null){const s=e.indexOf(u),d=e.slice(0,s);d.length>0&&this.handleData(d),this._pasteBuffer="",e=e.slice(s+u.length)}const i=e.indexOf(o);if(i===-1){const s=this._pasteBuffer+e;if(s.length>p){this._pasteBuffer=null,this.emit("data",s);return}this._pasteBuffer=s;return}const r=this._pasteBuffer+e.slice(0,i),a=e.slice(i+o.length);this._pasteBuffer=null,this.emit("paste",r),this.listenerCount("paste")===0&&this.emit("data",r),a.length>0&&this.handleData(a);return}if(t.length===1){const e=t.charCodeAt(0);if(e>=1&&e<=26&&e!==3&&e!==9&&e!==10&&e!==13){const i=String.fromCharCode(e+96);this.emit("ctrl",i),this.emit("data",t,{ctrl:!0});return}}if(t==="\x1B[A"){this.emit("keydown","up");return}if(t==="\x1B[B"){this.emit("keydown","down");return}if(t==="\x1B[C"){this.emit("keydown","right");return}if(t==="\x1B[D"){this.emit("keydown","left");return}if(t===" "){this.emit("keydown","tab");return}if(t==="\x1B[Z"){this.emit("keydown","shift-tab");return}if(t==="\x1B"){this.emit("keydown","escape");return}if(t==="\r"||t===`
2
+ `){this.emit("keydown","enter");return}if(t===""){this.emit("keydown","backspace");return}if(t==="\x1B[3~"){this.emit("keydown","delete");return}if(t==="\x1B[5~"){this.emit("keydown","pageUp");return}if(t==="\x1B[6~"){this.emit("keydown","pageDown");return}if(t==="\x1B[H"||t==="\x1B[1~"){this.emit("keydown","home");return}if(t==="\x1B[F"||t==="\x1B[4~"){this.emit("keydown","end");return}if(t.length===2&&t[0]==="\x1B"){this.emit("meta",t[1]),this.emit("data",t,{meta:!0});return}if(t.startsWith("\x1B[<")){const e=t.match(/\u001B\[<(\d+);(\d+);(\d+)(M)/i);if(e){const i=Number.parseInt(e[1]),r=Number.parseInt(e[2])-1,a=Number.parseInt(e[3])-1,s=e[4]==="m",d=(i&4)!==0,l=(i&8)!==0,f=(i&16)!==0,h=i&-29;let n=null;if(h===0&&!s?n="left":h===1&&!s?n="middle":h===2&&!s?n="right":h===64?n="scrollUp":h===65&&(n="scrollDown"),n){const m={button:n,ctrl:f,meta:l,shift:d,x:r,y:a};this.emit("mouse",m),n==="left"&&this.emit("click",{x:r,y:a})}}return}this.emit("data",t)}}export{w as InputParser};
@@ -0,0 +1,2 @@
1
+ import{createDecMode as G,setMode as w,resetMode as T,BracketedPasteMode as M,cursorHide as Y,REQUEST_CURSOR_POSITION as b,cursorPosition as u,eraseLine as g,cursorShow as A,cursorUp as B,cursorToColumn1 as C}from"@visulima/ansi";import{terminalSize as D,Renderer as L}from"./Renderer-BeS49FNq.js";const R=G(2026),_=w(R),k=T(R),z=w(M),H=T(M);function q(S,c={}){const E=c.rows??10,O=c.fps??60,h=c.onExit??"preserve",{onStop:y}=c;let i=null,r=null,l=null,a=80,t=10,N=0,n=1,f=!1,o=null;function e(s){r.writeRaw(s)}function p(){l.fill(0),S(l,a,t,N++),e(_);try{r.render(l)}finally{e(k)}}function P(s){n=s-t,e(B(t)+C),r.setRowOffset(n),p(),i=setInterval(()=>{p()},Math.round(1e3/O))}function U(){const s=D();a=s.cols;const v=s.rows;t=Math.min(E,v),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.setEncoding("utf8"),r=new L(a,t),l=new Uint32Array(a*t*2),e(Y),e(z),e(`
2
+ `.repeat(t)),e(b),process.on("SIGINT",d);let m="";o=x=>{m+=x;const I=m.match(/\u001B\[(\d+);(\d+)R/);I&&(o&&(process.stdin.off("data",o),o=null),P(Number.parseInt(I[1],10)))},process.stdin.on("data",o)}function d(){if(!f){if(f=!0,i&&(clearInterval(i),i=null),process.off("SIGINT",d),o&&(process.stdin.off("data",o),o=null),r){if(h==="destroy"){for(let s=0;s<t;s++)e(u(n+1+s,1)+g);e(u(n+1,1))}else e(u(n+t+1,1));e(H),e(A)}process.stdin.isTTY&&process.stdin.setRawMode(!1),process.stdin.pause(),y?.()}}return{start:U,stop:d}}export{q as createInlineLoop};
@@ -139,6 +139,12 @@ interface InlineOptions {
139
139
  * - 'destroy' — content is cleared, terminal looks untouched
140
140
  */
141
141
  onExit?: "preserve" | "destroy";
142
+ /**
143
+ * Invoked once after the loop has stopped and the terminal has been
144
+ * restored. Lets a host tear down its own state (unmount a React tree,
145
+ * resolve a promise) without the loop terminating the process itself.
146
+ */
147
+ onStop?: () => void;
142
148
  /** Number of terminal rows to reserve. Default: 10 */
143
149
  rows?: number;
144
150
  }
@@ -0,0 +1 @@
1
+ import{createContext as C}from"react";import y from"react-reconciler";import{NoEventPriority as h,DiscreteEventPriority as v,DefaultEventPriority as b}from"react-reconciler/constants.js";import{unstable_shouldYield as T,unstable_scheduleCallback as x,unstable_now as k,unstable_cancelCallback as I}from"scheduler";import{LayoutNode as c}from"./LayoutNode-LPYsuzBg.js";import{applyStyles as m,resolveColor as f}from"./NAMED_COLORS-82DpREQV.js";import{g as P}from"./text-width-e49vlbQH.js";const u=new WeakMap;function M(e,t){u.set(e,t)}function H(e){u.delete(e)}let d=h;function p(e){const t=f(e.fg===void 0?e.color===void 0?void 0:e.color:e.fg),n=f(e.bg===void 0?e.backgroundColor===void 0?void 0:e.backgroundColor:e.bg);let r;return e.styles===void 0?(r=0,e.bold&&(r|=1),(e.dim||e.dimColor)&&(r|=2),e.italic&&(r|=4),e.underline&&(r|=8),e.blink&&(r|=16),e.inverse&&(r|=32),e.hidden&&(r|=64),e.strikethrough&&(r|=128)):r=e.styles,{bg:n,fg:t,styles:r}}const S={afterActiveInstanceBlur:()=>{},appendChild(e,t){e.insertChild(t,e.children.length)},appendChildToContainer(e,t){e.insertChild(t,e.children.length)},appendInitialChild(e,t){e.insertChild(t,e.children.length)},beforeActiveInstanceBlur:()=>{},cancelCallback:I,cancelTimeout:clearTimeout,clearContainer(e){},commitTextUpdate(e,t,n){e.text=n,e.yogaNode.markDirty()},commitUpdate(e,t,n,r,s){m(e.yogaNode,r);const{bg:o,fg:i,styles:a}=p(r);e.fg=i,e.bg=o,e.styles=a,e._style=r,e.transform=typeof r.transform=="function"?r.transform:void 0},createInstance(e,t,n,r,s){const o=new c,i={...t};i.flexDirection===void 0&&(i.flexDirection="row"),i.flexShrink===void 0&&(i.flexShrink=1),m(o.yogaNode,i);const{bg:a,fg:l,styles:g}=p(t);return o.fg=l,o.bg=a,o.styles=g,o._style=t,typeof t.transform=="function"&&(o.transform=t.transform),o},createTextInstance(e,t,n,r){const s=new c;return s.text=e,s.yogaNode.setWidth(P(e)),s.yogaNode.setHeight(1),s},detachDeletedInstance:e=>{e.destroy()},finalizeInitialChildren(e,t,n,r,s){return!1},getChildHostContext(e,t,n){return{isInsideText:t==="text"}},getCurrentEventPriority:()=>v,getCurrentUpdatePriority:()=>d,getInstanceFromNode:()=>null,getPublicInstance(e){return e},getRootHostContext(e){return{isInsideText:!1}},hideInstance(e){e._hidden=!0},hideTextInstance(e){e._hidden=!0},HostTransitionContext:C(null),insertBefore(e,t,n){t.parent&&t.remove();const r=e.children.indexOf(n);e.insertChild(t,r)},isPrimaryRenderer:!0,maySuspendCommit:()=>!0,noTimeout:-1,NotPendingTransition:void 0,now:k,preloadInstance:()=>!0,prepareForCommit(e){return null},preparePortalMount:()=>{},prepareScopeUpdate:()=>{},prepareUpdate(e,t,n,r,s,o){if(n===r)return null;let i=0;for(const l of Object.keys(n))l!=="children"&&(i+=1);let a=0;for(const l of Object.keys(r))if(l!=="children"&&(a+=1,n[l]!==r[l]))return!0;return i===a?null:!0},removeChild(e,t){t.remove()},removeChildFromContainer(e,t){t.remove()},requestPostPaintCallback:()=>{},resetAfterCommit(e){const t=u.get(e);if(typeof t=="function"){t();return}},resolveEventTimeStamp:()=>-1.1,resolveEventType:()=>null,resolveUpdatePriority(){return d!==h?d:b},scheduleCallback:x,scheduleMicrotask:queueMicrotask,scheduleTimeout:setTimeout,setCurrentUpdatePriority(e){d=e},shouldAttemptEagerTransition:()=>!1,shouldSetTextContent(e,t){return!1},shouldYield:T,startSuspendingCommit:()=>{},supportsHydration:!1,supportsMicrotasks:!0,supportsMutation:!0,supportsPersistence:!1,suspendInstance:()=>{},trackSchedulerEvent:()=>{},unhideInstance(e,t){e._hidden=!1},unhideTextInstance(e,t){e._hidden=!1},waitForCommitToBeReady:()=>null,warnsIfNotActing:!0},B=y(S);export{B as T,M as r,H as u};
@@ -0,0 +1 @@
1
+ import u from"react";import{FocusProvider as N,useFocusManager as z}from"./FocusContext-BWFqf9kb.js";import{TuiContext as v,useInput as L}from"./TuiContext-BNmP0lMY.js";import{LayoutNode as I}from"./LayoutNode-LPYsuzBg.js";import{T as d,r as T,u as F}from"./reconciler-D4fi5NfR.js";import{renderTreeToBuffer as P}from"./renderTreeToBuffer-BpSD0sBJ.js";import{TuiApp as A}from"./TuiApp-CCVaiKbf.js";import{InputParser as b}from"./InputParser-CUAGWKQQ.js";import{terminalSize as G}from"./Renderer-BeS49FNq.js";import{createInlineLoop as M}from"./createInlineLoop-BMDYJkRp.js";const R=l=>u.createElement("box",l,l.children),Q=l=>u.createElement("text",l,l.children),V=()=>u.createElement(R,{flexGrow:1}),H=({children:l})=>{const{disableFocus:c,enableFocus:t,focusNext:a,focusPrevious:r}=z();return L((w,s)=>{s.tab&&!s.shift&&a(),s.tab&&s.shift&&r(),s.escape&&(c(),t())}),u.createElement(u.Fragment,null,l)};function X(l,c){const t=new A,a=new b(process.stdin),r=new I,{height:w,width:s}=t.getSize();r.yogaNode.setWidth(s),r.yogaNode.setHeight(w);const i=d.createContainer(r,0,null,!1,null,"",e=>console.error(e),null),m=e=>u.createElement(v.Provider,{value:{app:t,input:a,writeStderr:n=>t.writeStderr(n),writeStdout:n=>t.writeStdout(n)}},u.createElement(N,null,u.createElement(H,null,e)));d.updateContainer(m(l),i,null,()=>{});const h=(e,n)=>r.calculateLayout(e,n),g=(e,n,W)=>P(r,e,n,W),f=()=>t.paintNow(h,g);let x=!1;T(r,()=>{x=!0});const C=Math.round(1e3/(c?.maxFps??60)),E=setInterval(()=>{x&&(x=!1,f())},C);let S;const y=new Promise(e=>{S=e}),p=()=>{clearInterval(E),F(r),d.updateContainer(null,i,null,()=>{}),r.destroy(),t.stop(),a.stop(),process.off("SIGWINCH",o),S()};a.on("exit",()=>{p(),process.exit(0)}),t.on("quit",()=>{p(),process.exit(0)}),a.start(),t.start();const o=()=>{const e=process.stdout.columns||80,n=process.stdout.rows||24;t.resize(e,n),r.yogaNode.setWidth(e),r.yogaNode.setHeight(n),t.emit("resize"),f()};return process.on("SIGWINCH",o),f(),{app:t,input:a,rerender(e){d.updateContainer(m(e),i,null,()=>{})},unmount(){p()},waitUntilExit(){return y}}}function Y(l,c){const t=G(),a=c?.rows??10,{cols:r}=t,w=Math.min(a,t.rows),s=new b(process.stdin),i=new I;i.yogaNode.setWidth(r),i.yogaNode.setHeight(w);const m=[],h=[],g={quit:()=>p.stop(),writeStderr:o=>h.push(o),writeStdout:o=>m.push(o)},f=d.createContainer(i,0,null,!1,null,"",o=>console.error(o),null),x=o=>u.createElement(v.Provider,{value:{app:g,input:s,writeStderr:g.writeStderr,writeStdout:g.writeStdout}},u.createElement(N,null,u.createElement(H,null,o)));d.updateContainer(x(l),f,null,()=>{}),T(i,()=>{});let C;const E=new Promise(o=>{C=o});let S=!1;const y=()=>{S||(S=!0,F(i),d.updateContainer(null,f,null,()=>{}),i.destroy(),s.stop(),m.length>0&&process.stdout.write(m.join("")),h.length>0&&process.stderr.write(h.join("")),C())},p=M((o,e,n)=>{i.calculateLayout(e,n),P(i,o,e,n)},{...c,fps:c?.maxFps??c?.fps??60,onStop:y,rows:w});return s.on("exit",()=>p.stop()),p.start(),s.start(),{unmount(){p.stop()},waitUntilExit(){return E}}}export{R as _Box,V as _Spacer,Q as _Text,X as render,Y as renderInline};
@@ -0,0 +1,24 @@
1
+ import{createRequire as Le}from"node:module";import{jsx as M}from"react/jsx-runtime";import{cursorShow as nt,setMode as de,BracketedPasteMode as ce,resetMode as he,eraseLines as F,cursorHide as ut,cursorUp as Xt,cursorNextLine as $e,cursorTo as Ae,eraseLineEnd as Be,createDecMode as He,ALT_SCREEN_ON as Jt,clearScreenAndHomeCursor as Fe,ALT_SCREEN_OFF as Qt}from"@visulima/ansi";import{wordWrap as Ge}from"@visulima/string";import{ConcurrentRoot as Ye,LegacyRoot as Ke}from"react-reconciler/constants.js";import $ from"yoga-layout";import{a as je}from"./accessibility-context-DDyHTwmA.js";import{useState as ht,useRef as I,useCallback as v,useEffect as ft,useMemo as B}from"react";import{e as ze}from"./animation-context-DW3p-vpk.js";import{e as Ve}from"./app-context-DTm1_XBA.js";import{o as Xe}from"./cursor-context-CFviBqPX.js";import Je from"../components/error-boundary.js";import{o as Qe}from"./focus-context-CsT69klR.js";import{t as Ze}from"./stderr-context-CR2LLec6.js";import{e as ti}from"./stdin-context-BjMA9Sbi.js";import{t as ei}from"./stdout-context-DAAlQct2.js";import{I as ii,_ as si,r as ri,H as oi}from"./renderer-Cs0KEr1o.js";import{c as ni,e as ui}from"./dom-rphpG0kf.js";import{resolveFlags as Zt}from"./kittyFlags-g8ALyoCU.js";import{buildReturnToBottomPrefix as gt,buildCursorSuffix as rt,buildCursorOnlySequence as fe,cursorPositionChanged as wt,buildCursorShapeSequence as te}from"./buildCursorOnlySequence-CerkmjWt.js";import{p as ai}from"./load-native-root-binding-CxJnHcac.js";import{a as li}from"./measure-text-B7juNq4Y.js";import{j as L,c as di}from"./reconciler-DkwOtC5B.js";import{measureAndExtractObservers as ci}from"./ResizeObserver-BI9bDy-j.js";import{calculateScroll as hi}from"./calculateScroll-D4Y_JR4H.js";import{g as q}from"./utils-CVgM8kTn.js";let De;const Me=i=>(De??=Le(import.meta.url))(i),X=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,bt=i=>{if(typeof X<"u"&&X.versions&&X.versions.node){const[t,e]=X.versions.node.split(".").map(Number);if(t>22||t===22&&e>=3||t===20&&e>=16)return X.getBuiltinModule(i)}return Me(i)},k=X,{env:xt}=k,{PassThrough:zt,Stream:Ue}=bt("node:stream"),{Buffer:Vt}=bt("node:buffer"),{Console:We}=bt("node:console"),{EventEmitter:qe}=bt("node:events"),ee=i=>i in xt&&xt[i]!=="0"&&xt[i]!=="false",pe=ee("CI")||ee("CONTINUOUS_INTEGRATION"),ie=["assert","count","countReset","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","table","time","timeEnd","timeLog","trace","warn"];let Tt={};const fi=i=>{const t=new zt,e=new zt;t.write=r=>{i("stdout",r)},e.write=r=>{i("stderr",r)};const s=new console.Console(t,e);for(const r of ie)Tt[r]=console[r],console[r]=s[r];return()=>{for(const r of ie)console[r]=Tt[r];Tt={}}},J=[];J.push("SIGHUP","SIGINT","SIGTERM");process.platform!=="win32"&&J.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&J.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT");const mt=i=>!!i&&!0&&typeof i.removeListener=="function"&&typeof i.emit=="function"&&typeof i.reallyExit=="function"&&typeof i.listeners=="function"&&typeof i.kill=="function"&&typeof i.pid=="number"&&typeof i.on=="function",St=Symbol.for("signal-exit emitter"),Rt=globalThis,pi=Object.defineProperty.bind(Object);let mi=class{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(Rt[St])return Rt[St];pi(Rt,St,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(t,e){this.listeners[t].push(e)}removeListener(t,e){const s=this.listeners[t],r=s.indexOf(e);r!==-1&&(r===0&&s.length===1?s.length=0:s.splice(r,1))}emit(t,e,s){if(this.emitted[t])return!1;this.emitted[t]=!0;let r=!1;for(const n of this.listeners[t])r=n(e,s)===!0||r;return t==="exit"&&(r=this.emit("afterExit",e,s)||r),r}},me=class{};const gi=i=>({onExit(t,e){return i.onExit(t,e)},load(){return i.load()},unload(){return i.unload()}});class wi extends me{onExit(){return()=>{}}load(){}unload(){}}let vi=class extends me{#n=Ot.platform==="win32"?"SIGINT":"SIGHUP";#e=new mi;#t;#r;#o;#s={};#i=!1;constructor(t){super(),this.#t=t,this.#s={};for(const e of J)this.#s[e]=()=>{const s=this.#t.listeners(e);let{count:r}=this.#e;const n=t;if(typeof n.__signal_exit_emitter__=="object"&&typeof n.__signal_exit_emitter__.count=="number"&&(r+=n.__signal_exit_emitter__.count),s.length===r){this.unload();const a=this.#e.emit("exit",null,e),o=e==="SIGHUP"?this.#n:e;a||t.kill(t.pid,o)}};this.#o=t.reallyExit,this.#r=t.emit}onExit(t,e){if(!mt(this.#t))return()=>{};this.#i===!1&&this.load();const s=e?.alwaysLast?"afterExit":"exit";return this.#e.on(s,t),()=>{this.#e.removeListener(s,t),this.#e.listeners.exit.length===0&&this.#e.listeners.afterExit.length===0&&this.unload()}}load(){if(!this.#i){this.#i=!0,this.#e.count+=1;for(const t of J)try{const e=this.#s[t];e&&this.#t.on(t,e)}catch{}this.#t.emit=(t,...e)=>this.#a(t,...e),this.#t.reallyExit=t=>this.#u(t)}}unload(){this.#i&&(this.#i=!1,J.forEach(t=>{const e=this.#s[t];if(!e)throw new Error("Listener not defined for signal: "+t);try{this.#t.removeListener(t,e)}catch{}}),this.#t.emit=this.#r,this.#t.reallyExit=this.#o,this.#e.count-=1)}#u(t){return mt(this.#t)?(this.#t.exitCode=t||0,this.#e.emit("exit",this.#t.exitCode,null),this.#o.call(this.#t,this.#t.exitCode)):0}#a(t,...e){const s=this.#r;if(t==="exit"&&mt(this.#t)){typeof e[0]=="number"&&(this.#t.exitCode=e[0]);const r=s.call(this.#t,t,...e);return this.#e.emit("exit",this.#t.exitCode,null),r}else return s.call(this.#t,t,...e)}};const Ot=globalThis.process,{onExit:bi}=gi(mt(Ot)?new vi(Ot):new wi),ge="\x1B[200~",se="\x1B[201~",yi=i=>i>=48&&i<=63,xi=i=>i>=32&&i<=47,we=i=>i>=64&&i<=126,Ti=(i,t,e)=>{const s=t+e+1;let r=s;for(;r<i.length;r++){const n=i.codePointAt(r);if(n===void 0)return"pending";if(!(yi(n)||xi(n))&&!(n===91&&r===s))return we(n)?{nextIndex:r+1,sequence:i.slice(t,r+1)}:void 0}return"pending"},Si=(i,t,e)=>{const s=t+e+2;if(s>i.length)return"pending";const r=i.codePointAt(s-1);if(!(r===void 0||!we(r)))return{nextIndex:s,sequence:i.slice(t,s)}},re=(i,t,e)=>{const s=i[t+e];if(s===void 0)return"pending";if(s==="[")return Ti(i,t,e);if(s==="O")return Si(i,t,e)},Ri=(i,t)=>{const e=i.codePointAt(t+1),s=e!==void 0&&e>65535?2:1,r=t+1+s;return{nextIndex:r,sequence:i.slice(t,r)}},Ci=(i,t)=>{if(t===i.length-1)return"pending";if(i[t+1]==="\x1B"){if(t+2>=i.length)return"pending";const s=re(i,t,2);return s==="pending"?"pending":s||{nextIndex:t+2,sequence:i.slice(t,t+2)}}const e=re(i,t,1);return e==="pending"?"pending":e||Ri(i,t)},oe=(i,t)=>{let e=0;for(let s=0;s<i.length;s++){const r=i[s];(r===""||r==="\b")&&(s>e&&t.push(i.slice(e,s)),t.push(r),e=s+1)}e<i.length&&t.push(i.slice(e))},Ei=i=>{const t=[];let e=0;const s=r=>({events:t,pending:i.slice(r)});for(;e<i.length;){const r=i.indexOf("\x1B",e);if(r===-1)return oe(i.slice(e),t),{events:t,pending:""};r>e&&oe(i.slice(e,r),t);const n=Ci(i,r);if(n==="pending")return s(r);if(n.sequence===ge){const a=n.nextIndex,o=i.indexOf(se,a);if(o===-1)return s(r);t.push({paste:i.slice(a,o)}),e=o+se.length;continue}t.push(n.sequence),e=n.nextIndex}return{events:t,pending:""}},Oi=()=>{let i="";return{flushPendingEscape(){if(!i.startsWith("\x1B"))return;const t=i;return i="",t},hasPendingEscape(){return i.startsWith("\x1B")&&!i.startsWith(ge)&&i!=="\x1B[200"},push(t){const e=Ei(i+t);return i=e.pending,e.events},reset(){i=""}}},Pi=" ",Ni="\x1B[Z",Ii="\x1B",ne=de(ce),Ct=he(ce),ve=({children:i,exitOnCtrlC:t,interactive:e,onExit:s,onRegisterInputControl:r,onSuspendTerminal:n,onWaitUntilRenderFlush:a,renderThrottleMs:o,setCursorPosition:u,stderr:f,stdin:h,stdout:m,writeToStderr:w,writeToStdout:d})=>{const[c,b]=ht(!0),[y,S]=ht(void 0),[,R]=ht([]),U=I(0),C=I([]),W=I(new Map),P=I(void 0),N=I(0),_=I(!1),T=I(0),[E]=ht(()=>{const l=new qe;return l.setMaxListeners(1/0),l}),Q=I(void 0),Z=I(void 0);Z.current??=Oi();const tt=I(void 0),Nt=I(!1),Se=20,G=v(()=>{tt.current&&(clearTimeout(tt.current),tt.current=void 0)},[]),Y=v(()=>{P.current&&(clearTimeout(P.current),P.current=void 0)},[]),at=v(()=>{if(Y(),W.current.size===0)return;let l=Number.POSITIVE_INFINITY;for(const p of W.current.values())l=Math.min(l,p.nextDueTime);const g=Math.max(0,l-performance.now());P.current=setTimeout(()=>{P.current=void 0;const p=performance.now(),x=[...W.current.values()];for(const O of x){if(p<O.nextDueTime)continue;O.callback(p);const ke=p-O.startTime,_e=Math.floor(ke/O.interval)+1;O.nextDueTime=O.startTime+_e*O.interval}at()},g)},[Y]),It=v((l,g)=>{const p=performance.now();return W.current.set(l,{callback:l,interval:g,nextDueTime:p+g,startTime:p}),at(),{startTime:p,unsubscribe(){if(W.current.delete(l),W.current.size===0){Y();return}at()}}},[Y,at]);ft(()=>()=>{Y()},[Y]);const D=h.isTTY,kt=v(()=>{Q.current&&(h.removeListener("readable",Q.current),Q.current=void 0)},[h]),K=v(()=>{Z.current?.reset(),G(),kt()},[G,kt]),j=v(()=>{_.current=!1,h.setRawMode(!1),h.unref(),N.current=0,K()},[h,K]),et=v(l=>{D&&(N.current>0||_.current)&&j(),s(l)},[D,j,s]),_t=v(l=>{if(l.includes("")&&t){et();return}l===Ii&&c&&S(g=>{if(!g)return g})},[t,et,c]),it=v(l=>{_t(l),E.emit("input",l)},[_t,E]),Lt=v(()=>{G(),tt.current=setTimeout(()=>{tt.current=void 0;const l=Z.current.flushPendingEscape();l&&it(l)},Se)},[G,it]),yt=v(()=>{G();let l;for(;(l=h.read())!==null;){const g=Z.current.push(l);for(const p of g)if(typeof p=="string")it(p);else{if(E.listenerCount("paste")===0){Nt.current||(Nt.current=!0,w(`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().
2
+ `)),it(p.paste);continue}E.emit("paste",p.paste)}}Z.current.hasPendingEscape()&&Lt()},[h,it,G,Lt,w,E]),lt=v(()=>{Q.current||(Q.current=yt,h.addListener("readable",yt))},[h,yt]),Dt=v(l=>{if(!D)throw h===k.stdin?new Error(`Raw mode is not supported on the current process.stdin, which Ink uses as input stream by default.
3
+ Read about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported`):new Error(`Raw mode is not supported on the stdin provided to Ink.
4
+ Read about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported`);if(h.setEncoding("utf8"),l){if(N.current===0){const g=_.current;_.current=!1,g||(h.ref(),h.setRawMode(!0)),lt()}N.current++;return}N.current!==0&&--N.current===0&&(K(),_.current=!0,queueMicrotask(()=>{_.current&&j()}))},[D,h,lt,K,j]),Mt=v(l=>{if(m.isTTY){if(l){T.current===0&&m.write(ne),T.current++;return}T.current!==0&&--T.current===0&&m.write(Ct)}},[m]),Ut=I({bracketedPaste:!1,rawMode:!1}),Wt=v(()=>{const l=D&&(N.current>0||_.current),g=T.current>0;Ut.current={bracketedPaste:g,rawMode:l},g&&m.isTTY&&m.write(Ct),l&&(_.current=!1,K(),h.setRawMode(!1),h.unref())},[D,m,h,K]),$t=v(()=>{const{bracketedPaste:l,rawMode:g}=Ut.current;g&&(h.ref(),h.setRawMode(!0),h.setEncoding("utf8"),lt()),l&&m.isTTY&&m.write(ne)},[h,m,lt]);ft(()=>{r(Wt,$t)},[r,Wt,$t]);const At=v((l,g)=>{const p=l.findIndex(x=>x.id===g);for(let x=p+1;x<l.length;x++){const O=l[x];if(O?.isActive)return O.id}},[]),Bt=v((l,g)=>{const p=l.findIndex(x=>x.id===g);for(let x=p-1;x>=0;x--){const O=l[x];if(O?.isActive)return O.id}},[]),dt=v(()=>{const l=C.current;S(g=>{const p=l.find(x=>x.isActive)?.id;return At(l,g)??p})},[At]),ct=v(()=>{const l=C.current;S(g=>{const p=l.findLast(x=>x.isActive)?.id;return Bt(l,g)??p})},[Bt]);ft(()=>{const l=p=>{!c||U.current===0||(p===Pi&&dt(),p===Ni&&ct())};E.on("input",l);const g=E;return()=>{g.off("input",l)}},[c,dt,ct,E]);const Ht=v(()=>{b(!0)},[]),Ft=v(()=>{b(!1)},[]),Gt=v(l=>{C.current.some(g=>g?.id===l)&&S(l)},[]),Yt=v((l,{autoFocus:g})=>{const p=[...C.current,{id:l,isActive:!0}];U.current=p.length,C.current=p,R(p),g&&S(x=>x||l)},[]),Kt=v(l=>{S(p=>{if(p!==l)return p});const g=C.current.filter(p=>p.id!==l);U.current=g.length,C.current=g,R(g)},[]),jt=v(l=>{const g=C.current.map(p=>p.id!==l?p:{id:l,isActive:!0});C.current=g,R(g)},[]),qt=v(l=>{S(p=>{if(p!==l)return p});const g=C.current.map(p=>p.id!==l?p:{id:l,isActive:!1});C.current=g,R(g)},[]);ft(()=>()=>{const l=!m.destroyed&&!m.writableEnded;e&&l&&m.write(nt),D&&(N.current>0||_.current)&&j(),T.current>0&&(m.isTTY&&l&&m.write(Ct),T.current=0)},[m,D,j,e]);const Re=B(()=>({exit:et,suspendTerminal:n,waitUntilRenderFlush:a}),[et,n,a]),Ce=B(()=>({internal_eventEmitter:E,internal_exitOnCtrlC:t,isRawModeSupported:D,setBracketedPasteMode:Mt,setRawMode:Dt,stdin:h}),[h,Dt,Mt,D,t,E]),Ee=B(()=>({stdout:m,write:d}),[m,d]),Oe=B(()=>({stderr:f,write:w}),[f,w]),Pe=B(()=>({setCursorPosition:u}),[u]),Ne=B(()=>({activate:jt,activeId:y,add:Yt,deactivate:qt,disableFocus:Ft,enableFocus:Ht,focus:Gt,focusNext:dt,focusPrevious:ct,remove:Kt}),[y,Yt,Kt,jt,qt,Ht,Ft,dt,ct,Gt]),Ie=B(()=>({renderThrottleMs:o,subscribe:It}),[It,o]);return M(Ve.Provider,{value:Re,children:M(ti.Provider,{value:Ce,children:M(ei.Provider,{value:Ee,children:M(Ze.Provider,{value:Oe,children:M(Qe.Provider,{value:Ne,children:M(ze.Provider,{value:Ie,children:M(Xe.Provider,{value:Pe,children:M(Je,{onError:et,children:i})})})})})})})})};ve.displayName="InternalApp";const ki=(i,t,e)=>{if(e<=0||!i.yogaNode)return"";const{yogaNode:s}=i,r=s.getComputedBorder($.EDGE_LEFT),n=s.getComputedBorder($.EDGE_RIGHT),a=s.getComputedBorder($.EDGE_TOP),o=s.getComputedPadding($.EDGE_LEFT),u=s.getComputedPadding($.EDGE_RIGHT),f=s.getComputedPadding($.EDGE_TOP),h=Math.round(s.getComputedWidth()-r-n-o-u);if(h<=0)return"";const m=new ii({height:e,width:h}),w=-(i.internal_scrollState?.scrollLeft??0)-r-o,d=-t-a-f;for(const c of i.childNodes)si(c,m,{absoluteOffsetX:w,absoluteOffsetY:d,offsetX:w,offsetY:d,skipStaticElements:!1});return m.get().output},Pt=new WeakMap,z=i=>i??"default",be=()=>{let i,t;return{consumeDelta:()=>{if(z(t)===z(i))return"";const e=z(t);return i=t,te(e)},consumeRestoreOnDone:()=>{const e=z(i)!=="default";return i=void 0,t=void 0,e?te("default"):""},isDirty:()=>z(t)!==z(i),setPending:e=>{t=e}}},ot=(i,t)=>t.endsWith(`
5
+ `)?i.length-1:i.length,ye=i=>i.rows||1/0,vt=(i,t)=>Math.min(i,ye(t)),_i=(i,{showCursor:t=!1}={})=>{let e=0,s="",r=!1,n,a=!1,o,u=!1;const f=be(),h=()=>a?n:void 0,m=(d,c)=>{const b=wt(c,o);return d!==s||b||f.isDirty()},w=d=>{!t&&!r&&(i.write(ut),r=!0);const c=h();a=!1;const b=wt(c,o);if(!m(d,c))return!1;const y=f.consumeDelta(),S=d.split(`
6
+ `),R=ot(S,d),U=rt(R,c);if(d===s&&b)i.write(y+fe({cursorPosition:c,cursorWasShown:u,previousCursorPosition:o,previousLineCount:e,visibleLineCount:R}));else if(d===s&&y!=="")i.write(y);else{s=d;const C=gt(u,e,o);i.write(y+C+F(vt(e,i))+d+U),e=S.length}return o=c?{...c}:void 0,u=c!==void 0,!0};return w.clear=()=>{const d=gt(u,e,o);i.write(d+F(vt(e,i))),s="",e=0,o=void 0,u=!1},w.done=()=>{s="",e=0,o=void 0,u=!1;const d=f.consumeRestoreOnDone();d!==""&&i.write(d),t||(i.write(nt),r=!1)},w.reset=()=>{s="",e=0,o=void 0,u=!1},w.sync=d=>{const c=a?n:void 0;a=!1;const b=d.split(`
7
+ `);s=d,e=b.length;const y=f.consumeDelta();y!==""&&i.write(y),!c&&u&&i.write(ut),c&&i.write(rt(ot(b,d),c)),o=c?{...c}:void 0,u=c!==void 0},w.setCursorPosition=d=>{n=d,a=!0},w.setCursorShape=f.setPending,w.isCursorDirty=()=>a||f.isDirty(),w.willRender=d=>m(d,h()),w},Li=(i,{showCursor:t=!1}={})=>{let e=[],s="",r=!1,n,a=!1,o,u=!1;const f=be(),h=()=>a?n:void 0,m=(d,c)=>{const b=wt(c,o);return d!==s||b||f.isDirty()},w=d=>{!t&&!r&&(i.write(ut),r=!0);const c=h();a=!1;const b=wt(c,o);if(!m(d,c))return!1;const y=f.consumeDelta(),S=d.split(`
8
+ `),R=ot(S,d),U=ot(e,s);if(d===s&&b)return i.write(y+fe({cursorPosition:c,cursorWasShown:u,previousCursorPosition:o,previousLineCount:e.length,visibleLineCount:R})),o=c?{...c}:void 0,u=c!==void 0,!0;if(d===s&&y!=="")return i.write(y),!0;const C=gt(u,e.length,o);if(d===`
9
+ `||s.length===0){const T=rt(R,c);return i.write(y+C+F(vt(e.length,i))+d+T),u=c!==void 0,o=c?{...c}:void 0,s=d,e=S,!0}const W=d.endsWith(`
10
+ `),P=[y,C],N=ye(i);if(R<U){const T=s.endsWith(`
11
+ `)?1:0;P.push(F(Math.min(U-R+T,N)),Xt(Math.min(R,N-1)))}else P.push(Xt(Math.min(U-1,N-1)));for(let T=0;T<R;T++){const E=T===R-1;if(S[T]===e[T]){(!E||W)&&P.push($e());continue}P.push(Ae(0)+S[T]+Be+(E&&!W?"":`
12
+ `))}const _=rt(R,c);return P.push(_),i.write(P.join("")),u=c!==void 0,o=c?{...c}:void 0,s=d,e=S,!0};return w.clear=()=>{const d=gt(u,e.length,o);i.write(d+F(vt(e.length,i))),s="",e=[],o=void 0,u=!1},w.done=()=>{s="",e=[],o=void 0,u=!1;const d=f.consumeRestoreOnDone();d!==""&&i.write(d),t||(i.write(nt),r=!1)},w.reset=()=>{s="",e=[],o=void 0,u=!1},w.sync=d=>{const c=a?n:void 0;a=!1;const b=d.split(`
13
+ `);s=d,e=b;const y=f.consumeDelta();y!==""&&i.write(y),!c&&u&&i.write(ut),c&&i.write(rt(ot(b,d),c)),o=c?{...c}:void 0,u=c!==void 0},w.setCursorPosition=d=>{n=d,a=!0},w.setCursorShape=f.setPending,w.isCursorDirty=()=>a||f.isDirty(),w.willRender=d=>m(d,h()),w},Di=(i,{incremental:t=!1,showCursor:e=!1}={})=>t?Li(i,{showCursor:e}):_i(i,{showCursor:e}),Mi={create:Di},xe=He(2026),H=de(xe),A=he(xe);function Ui(i,t){return"isTTY"in i&&i.isTTY&&(t??!pe)}let V;const Wi=()=>{if(V!==!1){if(V!==void 0)return V;try{return V=ai(import.meta.url).Renderer,V}catch{V=!1;return}}},$i=i=>{const t=Wi();if(!t)return;let e,s=0,r=0;const n=(a,o)=>{(!e||s!==a||r!==o)&&(e?e.resize(a,o):e=new t(a,o),s=a,r=o)};return{clear(){if(e){const a=new Uint32Array(s*r*2),o=65535;for(let u=0;u<a.length;u+=2)a[u]=32,a[u+1]=o;e.render(a)}},destroy(){e=void 0},render(a,o,u){if(n(o,u),!!e){i.isTTY&&e.writeRaw(H);try{e.render(a)}finally{i.isTTY&&e.writeRaw(A)}}},resize(a,o){n(a,o)}}};function ue(i,t=0,e={}){const s=e.leading??!0,r=e.trailing??!0;let n,a,o,u;const f=()=>{if(a===void 0)return;const c=a;a=void 0,u=i(...c)},h=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},m=()=>{n=void 0,r&&f(),a=void 0,o=void 0},w=()=>{h(),n=setTimeout(m,t)},d=function(...c){const b=Date.now();if(o??=b,b-o>=t)return a=c,f(),o=b,w(),u;a=c;const y=n===void 0;return w(),s&&y&&f(),u};return d.cancel=()=>{h(),a=void 0,o=void 0},d.flush=()=>(h(),f(),o=void 0,u),d}console.Console||(console.Console=We);const st=()=>{},ae=async()=>new Promise(i=>{setImmediate(i)}),Ai=27,Bi=91,Hi=63,Fi=117,Gi=48,Yi=57,Ki=i=>i>=Gi&&i<=Yi,Te=(i,t)=>{if(i[t]!==Ai||i[t+1]!==Bi||i[t+2]!==Hi)return;let e=t+3;const s=e;for(;e<i.length&&Ki(i[e]);)e++;if(e!==s){if(e===i.length)return{state:"partial"};if(i[e]===Fi)return{endIndex:e,state:"complete"}}},ji=i=>{for(let t=0;t<i.length;t++)if(Te(i,t)?.state==="complete")return!0;return!1},qi=i=>{const t=[];let e=0;for(;e<i.length;){const s=Te(i,e);if(s?.state==="complete"){e=s.endIndex+1;continue}if(s?.state==="partial")break;t.push(i[e]),e++}return t},zi=({isTty:i,isUnmounting:t,isWindows:e,nextOutputHeight:s,previousOutputHeight:r,viewportRows:n})=>{if(!i)return!1;const a=r>0,o=r>=n,u=s>=n,f=r>n,h=s>n,m=o&&s<n;return f||h&&a||m||t&&o||e&&(u||o)},Et=i=>i instanceof Error||Object.prototype.toString.call(i)==="[object Error]",le=i=>{const t=!i.destroyed&&!i.writableEnded&&(i.writable??!0),e=i._writableState!==void 0||i.writableLength!==void 0;return{canWriteToStdout:t,hasWritableState:e}},pt=(i,t)=>{if(!i||typeof i.flush!="function")return;const e=i;t?e.flush():typeof e.cancel=="function"&&e.cancel()};class Vi{isConcurrent;options;log;manualCursorPosition;renderedCursorPosition;renderedCursorRequested;throttledLog;isScreenReaderEnabled;interactive;renderThrottleMs;alternateScreen;isUnmounted;isUnmounting;lastOutput;lastOutputToRender;lastOutputHeight;lastTerminalWidth;nativeLog;useNativeRenderer;container;rootNode;fullStaticOutput;backbufferNode;backbufferMultiWarned=!1;exitPromise;exitResult;beforeExitHandler;restoreConsole;unsubscribeResize;throttledOnRender;hasPendingThrottledRender=!1;kittyProtocolEnabled=!1;kittyFlags;isSuspended=!1;pauseInput;resumeInput;cancelKittyDetection;nextRenderCommit;deferredInitDone=!1;constructor(t){this.options=t,this.rootNode=ni("ink-root"),this.rootNode.onComputeLayout=this.calculateLayout,this.isScreenReaderEnabled=t.isScreenReaderEnabled??k.env.INK_SCREEN_READER==="true",this.interactive=this.resolveInteractiveOption(t.interactive),this.alternateScreen=!1;const e=t.debug||this.isScreenReaderEnabled,s=t.maxFps??30,r=s>0?Math.max(1,Math.ceil(1e3/s)):0;this.renderThrottleMs=e?0:r;const n=e?this.onRender:(()=>{const o=ue(this.onRender,r,{leading:!0,trailing:!0});return this.throttledOnRender=o,()=>{this.hasPendingThrottledRender=!0,o()}})();if(e&&(this.throttledOnRender=void 0),t.standardReactLayoutTiming){let o=!1;const u=()=>{o||(o=!0,queueMicrotask(()=>{o=!1,this.onRender()}))};this.rootNode.onRender=u,this.rootNode.onImmediateRender=u}else this.rootNode.onRender=n,this.rootNode.onImmediateRender=this.onRender;this.rootNode.onStaticChange=this.handleStaticChange,this.log=Mi.create(t.stdout,{incremental:t.incrementalRendering}),this.useNativeRenderer=t.useNativeRenderer??!1,this.useNativeRenderer&&(this.nativeLog=$i(t.stdout),this.nativeLog||(this.useNativeRenderer=!1)),this.manualCursorPosition=void 0,this.renderedCursorPosition=void 0,this.renderedCursorRequested=!1,this.throttledLog=e?this.log:ue(o=>{const u=this.log.willRender(o),f=this.shouldSync();f&&u&&this.options.stdout.write(H),this.log(o),f&&u&&this.options.stdout.write(A)},void 0,{leading:!0,trailing:!0}),this.isUnmounted=!1,this.isUnmounting=!1,this.isConcurrent=t.concurrent??!1,this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.lastTerminalWidth=q(this.options.stdout).columns,this.fullStaticOutput="";const a=t.concurrent?Ye:Ke;this.container=L.createContainer(this.rootNode,a,null,!1,null,"id",()=>{},()=>{},()=>{},()=>{}),this.unsubscribeExit=bi(this.unmount,{alwaysLast:!1}),this.setAlternateScreen(!!t.alternateScreen),t.patchConsole&&this.patchConsole(),this.interactive&&(t.stdout.on("resize",this.resized),this.unsubscribeResize=()=>{t.stdout.off("resize",this.resized)}),this.initImmediateKittyKeyboard(),k.env.DEV==="true"&&L.injectIntoDevTools(),this.exitPromise=new Promise((o,u)=>{this.resolveExitPromise=o,this.rejectExitPromise=u}),this.exitPromise.catch(st)}runDeferredInit(){this.deferredInitDone||(this.deferredInitDone=!0,this.initDeferredKittyKeyboard())}resized=()=>{const t=q(this.options.stdout).columns;t<this.lastTerminalWidth&&(this.log.clear(),this.lastOutput="",this.lastOutputToRender=""),li(),this.calculateLayout(),ui(this.rootNode),this.onRender(),this.lastTerminalWidth=t};resolveExitPromise=()=>{};rejectExitPromise=()=>{};unsubscribeExit=()=>{};handleAppExit=t=>{if(!(this.isUnmounted||this.isUnmounting)){if(Et(t)){this.unmount(t);return}this.exitResult=t,this.unmount()}};getActiveCursorPosition=()=>this.renderedCursorRequested?this.renderedCursorPosition:this.manualCursorPosition;setCursorPosition=t=>{this.manualCursorPosition=t,this.log.setCursorPosition(this.getActiveCursorPosition())};restoreLastOutput=()=>{this.interactive&&(this.log.setCursorPosition(this.getActiveCursorPosition()),this.log(this.lastOutputToRender||`${this.lastOutput}
14
+ `))};calculateLayout=()=>{const t=s=>{const r=new Map;this.calculateScrollAndTriggerObservers(s,r);for(const[n,a]of r)n.internalTrigger(a)};this.backbufferNode=void 0,this.prepareYogaTree(this.rootNode,t);const e=q(this.options.stdout).columns;this.rootNode.yogaNode.setWidth(e),this.rootNode.yogaNode.calculateLayout(void 0,void 0,$.DIRECTION_LTR),t(this.rootNode)};calculateScrollAndTriggerObservers(t,e){if(t.nodeName==="ink-box"){const{style:s}=t,r=s.overflow??"visible",n=s.overflowX??r,a=s.overflowY??r;n==="scroll"||a==="scroll"?(hi(t),s.overflowToBackbuffer&&(this.backbufferNode&&this.backbufferNode!==t&&!this.backbufferMultiWarned&&(this.backbufferMultiWarned=!0,console.warn("[@visulima/tui] Multiple scrollable regions have `overflowToBackbuffer` enabled; only one is supported. The last one in render order wins.")),this.backbufferNode=t)):t.internal_scrollState&&delete t.internal_scrollState}if(ci(t,e),!t.internal_static)for(const s of t.childNodes)s.nodeName!=="#text"&&this.calculateScrollAndTriggerObservers(s,e)}recalculateLayout(){this.markAllTextNodesDirty(this.rootNode),this.calculateLayout(),this.onRender()}prepareYogaTree(t,e){if(t.isYogaTreeDetached&&!t.cachedRender&&t.yogaNode){for(t.yogaNode.setWidthAuto(),t.yogaNode.setHeightAuto(),di(t.yogaNode,t.style);t.yogaNode.getChildCount()>0;)t.yogaNode.getChild(0).remove();let s=0;for(const r of t.childNodes){const n=r;r.nodeName!=="#text"&&n.yogaNode&&(t.yogaNode.insertChild(n.yogaNode,s),s++)}t.isYogaTreeDetached=!1,this.markAllTextNodesDirty(t)}for(const s of t.childNodes)s.nodeName!=="#text"&&this.prepareYogaTree(s,e);if(t.nodeName==="ink-static-render"&&!t.cachedRender){const s=q(this.options.stdout).columns,{width:r}=t.style;t.yogaNode&&(t.yogaNode.setWidth(typeof r=="number"?r:s),t.yogaNode.calculateLayout(void 0,void 0,$.DIRECTION_LTR)),e(t),ri(t,{skipStaticElements:!1}),t.internal_onRendered?.()}}markAllTextNodesDirty(t){if(!t.cachedRender){t.nodeName==="ink-text"&&t.yogaNode&&t.yogaNode.markDirty();for(const e of t.childNodes)e.nodeName!=="#text"&&this.markAllTextNodesDirty(e)}}handleStaticChange=()=>{this.fullStaticOutput=""};computeBackbufferOutput(){const t=this.backbufferNode;if(!t?.internal_scrollState||!this.interactive||!this.options.stdout.isTTY||this.alternateScreen||this.isScreenReaderEnabled||this.options.debug)return"";const e=Math.round(t.internal_scrollState.scrollTop),s=t.yogaNode?.getComputedPadding($.EDGE_TOP)??0,r=Math.max(0,e-Math.round(s)),n=t.internal_maxPushedScrollTop??0,{maxScrollbackLength:a}=t.style,o=a===void 0?n:Math.max(n,r-Math.max(0,a)),u=r-o;if(u<=0)return"";const f=ki(t,o,u);return f===""?"":(t.internal_maxPushedScrollTop=r,`${f}\x1B[0m
15
+ `)}onRender=()=>{if(this.hasPendingThrottledRender=!1,this.isUnmounted)return;this.deferredInitDone||this.runDeferredInit(),this.nextRenderCommit&&(this.nextRenderCommit.resolve(),this.nextRenderCommit=void 0);const t=oi(this.rootNode,this.isScreenReaderEnabled,{useNativeRenderer:this.useNativeRenderer}),{cursorPosition:e,cursorRequested:s,cursorShape:r,output:n,outputBuffer:a,outputHeight:o,outputWidth:u,staticOutput:f}=t;this.renderedCursorRequested=s,this.renderedCursorPosition=e,this.log.setCursorShape(s?r:void 0);const h=this.computeBackbufferOutput();if(this.useNativeRenderer&&this.nativeLog&&a&&u){f&&f!==`
16
+ `&&this.options.stdout.write(f),h&&this.options.stdout.write(h),this.nativeLog.render(a,u,o),this.lastOutputHeight=o;return}s&&this.log.setCursorPosition(this.getActiveCursorPosition());const m=f&&f!==`
17
+ `;if(this.options.debug){m&&(this.fullStaticOutput+=f),this.lastOutput=n,this.lastOutputToRender=n,this.lastOutputHeight=o,this.options.stdout.write(this.fullStaticOutput+n);return}if(!this.interactive){m&&this.options.stdout.write(f),this.lastOutput=n,this.lastOutputToRender=`${n}
18
+ `,this.lastOutputHeight=o;return}if(this.isScreenReaderEnabled){const w=this.shouldSync();if(w&&this.options.stdout.write(H),m){const b=this.lastOutputHeight>0?F(this.lastOutputHeight):"";this.options.stdout.write(b+f),this.lastOutputHeight=0}if(n===this.lastOutput&&!m){w&&this.options.stdout.write(A);return}const d=q(this.options.stdout).columns,c=Ge(n,{trim:!1,width:d,wrapMode:"BREAK_WORDS"}).replace(/\n$/,"");if(m)this.options.stdout.write(c);else{const b=this.lastOutputHeight>0?F(this.lastOutputHeight):"";this.options.stdout.write(b+c)}this.lastOutput=n,this.lastOutputToRender=c,this.lastOutputHeight=c===""?0:c.split(`
19
+ `).length,w&&this.options.stdout.write(A);return}m&&(this.fullStaticOutput+=f),this.renderInteractiveFrame(n,o,m?f:"",h)};accessibilityContextValue;render(t){this.accessibilityContextValue??={isScreenReaderEnabled:this.isScreenReaderEnabled};const e=M(je.Provider,{value:this.accessibilityContextValue,children:M(ve,{exitOnCtrlC:this.options.exitOnCtrlC,interactive:this.interactive,onExit:this.handleAppExit,onRegisterInputControl:this.registerInputControl,onSuspendTerminal:this.suspendTerminal,onWaitUntilRenderFlush:this.waitUntilRenderFlush,renderThrottleMs:this.renderThrottleMs,setCursorPosition:this.setCursorPosition,stderr:this.options.stderr,stdin:this.options.stdin,stdout:this.options.stdout,writeToStderr:this.writeToStderr,writeToStdout:this.writeToStdout,children:t})});this.options.concurrent?L.updateContainer(e,this.container,null,st):(L.updateContainerSync(e,this.container,null,st),L.flushSyncWork())}writeToStdout=t=>{if(this.isUnmounted)return;if(this.options.debug){this.options.stdout.write(t+this.fullStaticOutput+this.lastOutput);return}if(!this.interactive){this.options.stdout.write(t);return}const e=this.shouldSync();e&&this.options.stdout.write(H),this.log.clear(),this.options.stdout.write(t),this.restoreLastOutput(),e&&this.options.stdout.write(A)};writeToStderr=t=>{if(this.isUnmounted)return;if(this.options.debug){this.options.stderr.write(t),this.options.stdout.write(this.fullStaticOutput+this.lastOutput);return}if(!this.interactive){this.options.stderr.write(t);return}const e=this.shouldSync();e&&this.options.stdout.write(H),this.log.clear(),this.options.stderr.write(t),this.restoreLastOutput(),e&&this.options.stdout.write(A)};unmount=t=>{if(this.isUnmounted||this.isUnmounting)return;this.isUnmounting=!0,this.beforeExitHandler&&(k.off("beforeExit",this.beforeExitHandler),this.beforeExitHandler=void 0);const e=this.options.stdout,{canWriteToStdout:s,hasWritableState:r}=le(e);pt(this.throttledOnRender,s),s&&!this.alternateScreen&&(!this.throttledOnRender||!this.hasPendingThrottledRender&&this.fullStaticOutput==="")&&(this.calculateLayout(),this.onRender()),this.isUnmounted=!0,this.unsubscribeExit(),pt(this.throttledLog,s),typeof this.restoreConsole=="function"&&this.restoreConsole();const n=()=>{typeof this.unsubscribeResize=="function"&&this.unsubscribeResize(),this.cancelKittyDetection&&this.cancelKittyDetection(),s&&(this.kittyProtocolEnabled&&this.writeBestEffort(this.options.stdout,"\x1B[<u"),this.alternateScreen?(this.log.clear(),this.log.done(),this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.fullStaticOutput="",this.writeBestEffort(this.options.stdout,Qt),this.writeBestEffort(this.options.stdout,nt),this.alternateScreen=!1):this.interactive?this.options.debug||this.log.done():this.options.stdout.write(this.options.debug?`
20
+ `:`${this.lastOutput}
21
+ `)),this.kittyProtocolEnabled=!1,Pt.delete(this.options.stdout);const{exitResult:o}=this,u=()=>{Et(t)?this.rejectExitPromise(t):this.resolveExitPromise(o)};t!==void 0&&!Et(t)?u():s&&r?this.options.stdout.write("",u):setImmediate(u)},a=L;this.options.concurrent?(L.updateContainerSync(null,this.container,null,st),L.flushSyncWork(),a.flushPassiveEffects?.(),n()):(L.updateContainerSync(null,this.container,null,st),L.flushSyncWork(),n())};async waitUntilExit(){return this.beforeExitHandler||(this.beforeExitHandler=()=>{this.unmount()},k.on("beforeExit",this.beforeExitHandler)),this.exitPromise}async waitUntilRenderFlush(){if(this.isUnmounted||this.isUnmounting){await this.awaitExit();return}if(await ae(),this.isUnmounted||this.isUnmounting){await this.awaitExit();return}if(this.isConcurrent&&this.hasPendingConcurrentWork()&&(await Promise.race([this.awaitNextRender(),this.awaitExit()]),this.isUnmounted||this.isUnmounting)){this.nextRenderCommit=void 0,await this.awaitExit();return}L.flushSyncWork();const t=this.options.stdout,{canWriteToStdout:e,hasWritableState:s}=le(t);if(pt(this.throttledOnRender,e),pt(this.throttledLog,e),e&&s){await new Promise(r=>{this.options.stdout.write("",()=>{r()})});return}await ae()}clear(){this.interactive&&!this.options.debug&&(this.log.clear(),this.log.sync(this.lastOutputToRender||`${this.lastOutput}
22
+ `))}patchConsole(){this.options.debug||(this.restoreConsole=fi((t,e)=>{t==="stdout"&&this.writeToStdout(e),t==="stderr"&&(e.startsWith("The above error occurred")||this.writeToStderr(e))}))}setAlternateScreen(t){this.alternateScreen=this.resolveAlternateScreenOption(t,this.interactive),this.alternateScreen&&(this.writeBestEffort(this.options.stdout,Jt),this.writeBestEffort(this.options.stdout,ut))}resolveInteractiveOption(t){return t??(!pe&&!!this.options.stdout.isTTY)}resolveAlternateScreenOption(t,e){return!!t&&e&&!!this.options.stdout.isTTY}shouldSync(){return Ui(this.options.stdout,this.interactive)}writeBestEffort(t,e){try{t.write(e)}catch{}}async awaitExit(){try{await this.exitPromise}catch{}}hasPendingConcurrentWork(){const t=this.container;return(t.pendingLanes??0)!==0&&t.callbackNode!==void 0&&t.callbackNode!==null}async awaitNextRender(){if(!this.nextRenderCommit){let t;const e=new Promise(s=>{t=s});this.nextRenderCommit={promise:e,resolve:t}}return this.nextRenderCommit.promise}renderInteractiveFrame(t,e,s,r=""){const n=s+r,a=n!=="",o=this.options.stdout.isTTY,u=o?q(this.options.stdout).rows:24,f=o&&e>=u,h=f?t:`${t}
23
+ `,m=k.platform==="win32",w=o&&m&&(f||this.lastOutputHeight>=u);if(zi({isTty:o,isUnmounting:this.isUnmounting,isWindows:m,nextOutputHeight:e,previousOutputHeight:this.lastOutputHeight,viewportRows:u})){if(this.options.incrementalRendering&&!w){a&&(this.log.clear(),this.options.stdout.write(n)),(t!==this.lastOutput||this.log.isCursorDirty()||a)&&this.throttledLog(h),this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e;return}const d=this.shouldSync();d&&this.options.stdout.write(H),this.options.stdout.write(Fe+this.fullStaticOutput+r+h),this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e,this.log.sync(h),d&&this.options.stdout.write(A);return}if(a){const d=this.shouldSync();d&&this.options.stdout.write(H),this.log.clear(),this.options.stdout.write(n),this.log(h),d&&this.options.stdout.write(A)}else(t!==this.lastOutput||this.log.isCursorDirty())&&this.throttledLog(h);this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e}initImmediateKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="enabled")return;const e=t.flags??["disambiguateEscapeCodes"];this.options.stdin.isTTY&&this.options.stdout.isTTY&&this.enableKittyProtocol(e)}initDeferredKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="auto")return;const e=t.flags??["disambiguateEscapeCodes"];!this.interactive||!this.options.stdin.isTTY||!this.options.stdout.isTTY||this.confirmKittySupport(e)}confirmKittySupport(t){const{stdin:e,stdout:s}=this.options;let r=[];const n=()=>{this.cancelKittyDetection=void 0,clearTimeout(o),e.removeListener("data",a);const u=qi(r);r=[],u.length>0&&e.unshift(Vt.from(u))},a=u=>{const f=typeof u=="string"?Vt.from(u):u;for(const h of f)r.push(h);ji(r)&&(n(),this.isUnmounted||this.enableKittyProtocol(t))};e.on("data",a);const o=setTimeout(n,200);this.cancelKittyDetection=n,s.write("\x1B[?u")}registerInputControl=(t,e)=>{this.pauseInput=t,this.resumeInput=e};suspendTerminal=(async t=>{if(this.beginSuspend(),t){try{await t()}finally{await this.endSuspend()}return}const e=async()=>{await this.endSuspend()};return{resume:e,[Symbol.asyncDispose]:e}});beginSuspend(){if(this.isSuspended)throw new Error("The terminal is already suspended. Resume the current suspension before suspending again.");if(this.isSuspended=!0,!(!this.interactive||this.isUnmounted||this.isUnmounting))try{this.log.clear(),this.log.done(),this.kittyProtocolEnabled&&this.writeBestEffort(this.options.stdout,"\x1B[<u"),this.alternateScreen&&(this.writeBestEffort(this.options.stdout,Qt),this.writeBestEffort(this.options.stdout,nt)),this.pauseInput?.()}catch(t){this.isSuspended=!1;try{this.resumeInput?.()}catch{}throw t}}async endSuspend(){if(this.isSuspended&&(this.isSuspended=!1,this.resumeInput?.(),!(!this.interactive||this.isUnmounted||this.isUnmounting))){this.alternateScreen&&this.writeBestEffort(this.options.stdout,Jt),this.kittyProtocolEnabled&&this.kittyFlags&&this.writeBestEffort(this.options.stdout,`\x1B[>${Zt(this.kittyFlags)}u`),this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.log.reset();try{this.calculateLayout(),this.onRender(),await this.waitUntilRenderFlush()}catch{}}}enableKittyProtocol(t){this.kittyFlags=t,this.options.stdout.write(`\x1B[>${Zt(t)}u`),this.kittyProtocolEnabled=!0}}const Os=(i,t)=>{const e={alternateScreen:!1,concurrent:!1,debug:!1,exitOnCtrlC:!0,incrementalRendering:!1,maxFps:30,patchConsole:!0,stderr:k.stderr,stdin:k.stdin,stdout:k.stdout,...Xi(t)},s=Ji(e.stdout,()=>new Vi(e));return s.render(i),{cleanup(){s.unmount()},clear(){s.clear()},rerender(r){s.render(r)},rootNode:s.rootNode,unmount(){s.unmount()},waitUntilExit(){return s.waitUntilExit()},waitUntilRenderFlush(){return s.waitUntilRenderFlush()}}},Xi=(i={})=>i instanceof Ue?{stdin:k.stdin,stdout:i}:i,Ji=(i,t)=>{const e=Pt.get(i);if(e===void 0){const s=t();return Pt.set(i,s),s}return k.stderr.write(`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.
24
+ `),e};export{Os as default};
@@ -1,2 +1,2 @@
1
- import s from"react";import{FocusProvider as S}from"./FocusContext-C2Sosxa4.js";import{TuiContext as h}from"./TuiContext-BNmP0lMY.js";import{LayoutNode as T}from"./LayoutNode-LPYsuzBg.js";import{T as l}from"./reconciler-ClpU7Y-V.js";import{renderTreeToBuffer as C}from"./renderTreeToBuffer-BpSD0sBJ.js";import{Cell as w}from"./Cell-BrXn3jxY.js";function P(p,u){const r=u?.columns??80,o=u?.rows??24,e=new T;e.yogaNode.setWidth(r),e.yogaNode.setHeight(o);const d={app:null,input:null,writeStderr:n=>{},writeStdout:n=>{}},y=s.createElement(h.Provider,{value:d},s.createElement(S,null,p)),a=l.createContainer(e,0,null,!1,null,"renderToString",()=>{},null);l.updateContainerSync(y,a,null,()=>{}),l.flushSyncWork(),e.calculateLayout(r,o);const c=new Uint32Array(r*o*2);C(e,c,r,o);const t=[];for(let n=0;n<o;n++){let m="";for(let i=0;i<r;i++){const g=c[(n*r+i)*2],f=w.getChar(g);m+=f===""?" ":f}t.push(m.trimEnd())}for(;t.length>0&&t.at(-1)==="";)t.pop();return l.updateContainerSync(null,a,null,()=>{}),l.flushSyncWork(),e.destroy(),t.join(`
1
+ import s from"react";import{FocusProvider as S}from"./FocusContext-BWFqf9kb.js";import{TuiContext as h}from"./TuiContext-BNmP0lMY.js";import{LayoutNode as T}from"./LayoutNode-LPYsuzBg.js";import{T as l}from"./reconciler-D4fi5NfR.js";import{renderTreeToBuffer as C}from"./renderTreeToBuffer-BpSD0sBJ.js";import{Cell as w}from"./Cell-BrXn3jxY.js";function P(p,i){const r=i?.columns??80,o=i?.rows??24,e=new T;e.yogaNode.setWidth(r),e.yogaNode.setHeight(o);const d={app:null,input:null,writeStderr:n=>{},writeStdout:n=>{}},y=s.createElement(h.Provider,{value:d},s.createElement(S,null,p)),a=l.createContainer(e,0,null,!1,null,"renderToString",()=>{},null);l.updateContainerSync(y,a,null,()=>{}),l.flushSyncWork(),e.calculateLayout(r,o);const c=new Uint32Array(r*o*2);C(e,c,r,o);const t=[];for(let n=0;n<o;n++){let m="";for(let u=0;u<r;u++){const g=c[(n*r+u)*2],f=w.getChar(g);m+=f===""?" ":f}t.push(m.trimEnd())}for(;t.length>0&&t.at(-1)==="";)t.pop();return l.updateContainerSync(null,a,null,()=>{}),l.flushSyncWork(),e.destroy(),t.join(`
2
2
  `)}export{P as renderToString};
@@ -1,5 +1,5 @@
1
1
  import React, { Context, RefObject, ReactNode } from 'react';
2
- import { M as MouseEvent, T as TuiApp, c as InputParser, a as InlineOptions } from "../packem_shared/input.d-Bb8pWHvp.js";
2
+ import { M as MouseEvent, T as TuiApp, c as InputParser, a as InlineOptions } from "../packem_shared/input.d-CL_4MfL-.js";
3
3
  import Yoga from 'yoga-layout';
4
4
  interface DevToolsProps {
5
5
  children: React.ReactNode;
@@ -1 +1 @@
1
- import{DevTools as o}from"../packem_shared/DevTools-BxD3PYAN.js";import{FocusContext as u,FocusProvider as s,useFocus as n,useFocusManager as p}from"../packem_shared/FocusContext-C2Sosxa4.js";import{TuiContext as d,measureElement as f,useApp as l,useBoxMetrics as m,useCursor as a,useInput as i,useIsScreenReaderEnabled as S,useMouse as c,usePaste as T,useScrollable as C,useStderr as F,useStdin as I,useStdout as M,useTextInput as v,useTuiContext as y,useWindowSize as E}from"../packem_shared/TuiContext-BNmP0lMY.js";import{render as g,renderInline as A}from"../packem_shared/render-DtQd8qQq.js";import{renderToString as D}from"../packem_shared/renderToString-DkTmJPaS.js";import{Static as N}from"../packem_shared/Static-DSzsElz4.js";import{LayoutNode as P}from"../packem_shared/LayoutNode-LPYsuzBg.js";import{NAMED_COLORS as w,applyStyles as z,resolveColor as W}from"../packem_shared/NAMED_COLORS-82DpREQV.js";import{renderTreeToBuffer as h}from"../packem_shared/renderTreeToBuffer-BpSD0sBJ.js";export{o as DevTools,u as FocusContext,s as FocusProvider,P as LayoutNode,w as NAMED_COLORS,N as Static,d as TuiContext,z as applyStyles,f as measureElement,g as render,A as renderInline,D as renderToString,h as renderTreeToBuffer,W as resolveColor,l as useApp,m as useBoxMetrics,a as useCursor,n as useFocus,p as useFocusManager,i as useInput,S as useIsScreenReaderEnabled,c as useMouse,T as usePaste,C as useScrollable,F as useStderr,I as useStdin,M as useStdout,v as useTextInput,y as useTuiContext,E as useWindowSize};
1
+ import{DevTools as o}from"../packem_shared/DevTools-CZ-O0Ckm.js";import{FocusContext as u,FocusProvider as s,useFocus as n,useFocusManager as p}from"../packem_shared/FocusContext-BWFqf9kb.js";import{TuiContext as d,measureElement as f,useApp as l,useBoxMetrics as m,useCursor as a,useInput as i,useIsScreenReaderEnabled as S,useMouse as c,usePaste as T,useScrollable as C,useStderr as F,useStdin as I,useStdout as M,useTextInput as v,useTuiContext as y,useWindowSize as E}from"../packem_shared/TuiContext-BNmP0lMY.js";import{render as g,renderInline as A}from"../packem_shared/render-CPVY5vpQ.js";import{renderToString as D}from"../packem_shared/renderToString-Df6HST7u.js";import{Static as N}from"../packem_shared/Static-DSzsElz4.js";import{LayoutNode as P}from"../packem_shared/LayoutNode-LPYsuzBg.js";import{NAMED_COLORS as w,applyStyles as z,resolveColor as W}from"../packem_shared/NAMED_COLORS-82DpREQV.js";import{renderTreeToBuffer as h}from"../packem_shared/renderTreeToBuffer-BpSD0sBJ.js";export{o as DevTools,u as FocusContext,s as FocusProvider,P as LayoutNode,w as NAMED_COLORS,N as Static,d as TuiContext,z as applyStyles,f as measureElement,g as render,A as renderInline,D as renderToString,h as renderTreeToBuffer,W as resolveColor,l as useApp,m as useBoxMetrics,a as useCursor,n as useFocus,p as useFocusManager,i as useInput,S as useIsScreenReaderEnabled,c as useMouse,T as usePaste,C as useScrollable,F as useStderr,I as useStdin,M as useStdout,v as useTextInput,y as useTuiContext,E as useWindowSize};
@@ -1 +1 @@
1
- import{createRequire as _}from"node:module";import x from"../packem_shared/render-CuCo-R-l.js";import{createKeySender as y}from"../packem_shared/KEY-C--kOw41.js";import{KEY as Y}from"../packem_shared/KEY-C--kOw41.js";import{createScreen as T}from"../packem_shared/createScreen-DoYpyL0V.js";import{waitFor as b}from"../packem_shared/waitFor-CTAki32d.js";let g;const w=t=>(g??=_(import.meta.url))(t),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,F=t=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[e,n]=a.versions.node.split(".").map(Number);if(e>22||e===22&&n>=3||e===20&&n>=16)return a.getBuiltinModule(t)}return w(t)},m=F("node:events");class j extends m{columns;_lastFrame;_frames=[];constructor(e=100){super(),this.columns=e}get frames(){return this._frames}lastFrame(){return this._lastFrame}write=e=>(this._frames.push(e),this._lastFrame=e,!0)}class v extends m{columns;_lastFrame;_frames=[];constructor(e=100){super(),this.columns=e}get frames(){return this._frames}lastFrame(){return this._lastFrame}write=e=>(this._frames.push(e),this._lastFrame=e,!0)}class R extends m{isTTY=!0;pendingData;write=e=>(this.pendingData=e,this.emit("readable"),this.emit("data",e),!0);read(){const{pendingData:e}=this;return this.pendingData=void 0,e}setEncoding(){return this}setRawMode(){return this}resume(){return this}pause(){return this}ref(){return this}unref(){return this}}const u=[],S=(t,e={})=>{const{columns:n,options:d}=e,s=new j(n),c=new v(n),o=new R,i=x(t,{debug:!0,exitOnCtrlC:!1,patchConsole:!1,stderr:c,stdin:o,stdout:s,...d});u.push(i);const l=T(()=>s.lastFrame(),s.frames),p=y(r=>o.write(r)),f=async()=>{await new Promise(r=>{setTimeout(r,0)}),await new Promise(r=>{setTimeout(r,0)})};return{cleanup:i.cleanup,flush:f,get frames(){return s.frames},keys:p,lastFrame:()=>s.lastFrame(),rerender:i.rerender,screen:l,stderr:c,stdin:o,stdout:s,unmount:i.unmount,async waitFor(r,h){await b(r,()=>l.text(),h)}}},B=()=>{for(const t of u)t.cleanup();u.length=0};export{Y as KEY,B as cleanup,y as createKeySender,T as createScreen,S as render,b as waitFor};
1
+ import{createRequire as _}from"node:module";import x from"../packem_shared/render-CvhjGwOg.js";import{createKeySender as y}from"../packem_shared/KEY-C--kOw41.js";import{KEY as Y}from"../packem_shared/KEY-C--kOw41.js";import{createScreen as T}from"../packem_shared/createScreen-DoYpyL0V.js";import{waitFor as b}from"../packem_shared/waitFor-CTAki32d.js";let g;const w=t=>(g??=_(import.meta.url))(t),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,F=t=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[e,n]=a.versions.node.split(".").map(Number);if(e>22||e===22&&n>=3||e===20&&n>=16)return a.getBuiltinModule(t)}return w(t)},m=F("node:events");class j extends m{columns;_lastFrame;_frames=[];constructor(e=100){super(),this.columns=e}get frames(){return this._frames}lastFrame(){return this._lastFrame}write=e=>(this._frames.push(e),this._lastFrame=e,!0)}class v extends m{columns;_lastFrame;_frames=[];constructor(e=100){super(),this.columns=e}get frames(){return this._frames}lastFrame(){return this._lastFrame}write=e=>(this._frames.push(e),this._lastFrame=e,!0)}class R extends m{isTTY=!0;pendingData;write=e=>(this.pendingData=e,this.emit("readable"),this.emit("data",e),!0);read(){const{pendingData:e}=this;return this.pendingData=void 0,e}setEncoding(){return this}setRawMode(){return this}resume(){return this}pause(){return this}ref(){return this}unref(){return this}}const u=[],S=(t,e={})=>{const{columns:n,options:d}=e,s=new j(n),c=new v(n),o=new R,i=x(t,{debug:!0,exitOnCtrlC:!1,patchConsole:!1,stderr:c,stdin:o,stdout:s,...d});u.push(i);const l=T(()=>s.lastFrame(),s.frames),p=y(r=>o.write(r)),f=async()=>{await new Promise(r=>{setTimeout(r,0)}),await new Promise(r=>{setTimeout(r,0)})};return{cleanup:i.cleanup,flush:f,get frames(){return s.frames},keys:p,lastFrame:()=>s.lastFrame(),rerender:i.rerender,screen:l,stderr:c,stdin:o,stdout:s,unmount:i.unmount,async waitFor(r,h){await b(r,()=>l.text(),h)}}},B=()=>{for(const t of u)t.cleanup();u.length=0};export{Y as KEY,B as cleanup,y as createKeySender,T as createScreen,S as render,b as waitFor};
package/index.js CHANGED
@@ -82,7 +82,7 @@ function requireNative() {
82
82
  const binding = require('@visulima/tui-binding-android-arm64')
83
83
  const bindingPackageVersion = require('@visulima/tui-binding-android-arm64/package.json').version
84
84
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
85
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
85
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
86
86
  }
87
87
  return binding
88
88
  } catch (e) {
@@ -98,7 +98,7 @@ function requireNative() {
98
98
  const binding = require('@visulima/tui-binding-android-arm-eabi')
99
99
  const bindingPackageVersion = require('@visulima/tui-binding-android-arm-eabi/package.json').version
100
100
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
101
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
101
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
102
102
  }
103
103
  return binding
104
104
  } catch (e) {
@@ -119,7 +119,7 @@ function requireNative() {
119
119
  const binding = require('@visulima/tui-binding-win32-x64-gnu')
120
120
  const bindingPackageVersion = require('@visulima/tui-binding-win32-x64-gnu/package.json').version
121
121
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
122
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
122
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
123
123
  }
124
124
  return binding
125
125
  } catch (e) {
@@ -135,7 +135,7 @@ function requireNative() {
135
135
  const binding = require('@visulima/tui-binding-win32-x64-msvc')
136
136
  const bindingPackageVersion = require('@visulima/tui-binding-win32-x64-msvc/package.json').version
137
137
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
138
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
138
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
139
139
  }
140
140
  return binding
141
141
  } catch (e) {
@@ -152,7 +152,7 @@ function requireNative() {
152
152
  const binding = require('@visulima/tui-binding-win32-ia32-msvc')
153
153
  const bindingPackageVersion = require('@visulima/tui-binding-win32-ia32-msvc/package.json').version
154
154
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
155
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
155
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
156
156
  }
157
157
  return binding
158
158
  } catch (e) {
@@ -168,7 +168,7 @@ function requireNative() {
168
168
  const binding = require('@visulima/tui-binding-win32-arm64-msvc')
169
169
  const bindingPackageVersion = require('@visulima/tui-binding-win32-arm64-msvc/package.json').version
170
170
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
171
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
171
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
172
172
  }
173
173
  return binding
174
174
  } catch (e) {
@@ -187,7 +187,7 @@ function requireNative() {
187
187
  const binding = require('@visulima/tui-binding-darwin-universal')
188
188
  const bindingPackageVersion = require('@visulima/tui-binding-darwin-universal/package.json').version
189
189
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
190
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
190
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
191
191
  }
192
192
  return binding
193
193
  } catch (e) {
@@ -203,7 +203,7 @@ function requireNative() {
203
203
  const binding = require('@visulima/tui-binding-darwin-x64')
204
204
  const bindingPackageVersion = require('@visulima/tui-binding-darwin-x64/package.json').version
205
205
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
206
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
206
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
207
207
  }
208
208
  return binding
209
209
  } catch (e) {
@@ -219,7 +219,7 @@ function requireNative() {
219
219
  const binding = require('@visulima/tui-binding-darwin-arm64')
220
220
  const bindingPackageVersion = require('@visulima/tui-binding-darwin-arm64/package.json').version
221
221
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
222
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
222
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
223
223
  }
224
224
  return binding
225
225
  } catch (e) {
@@ -239,7 +239,7 @@ function requireNative() {
239
239
  const binding = require('@visulima/tui-binding-freebsd-x64')
240
240
  const bindingPackageVersion = require('@visulima/tui-binding-freebsd-x64/package.json').version
241
241
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
242
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
242
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
243
243
  }
244
244
  return binding
245
245
  } catch (e) {
@@ -255,7 +255,7 @@ function requireNative() {
255
255
  const binding = require('@visulima/tui-binding-freebsd-arm64')
256
256
  const bindingPackageVersion = require('@visulima/tui-binding-freebsd-arm64/package.json').version
257
257
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
258
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
258
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
259
259
  }
260
260
  return binding
261
261
  } catch (e) {
@@ -276,7 +276,7 @@ function requireNative() {
276
276
  const binding = require('@visulima/tui-binding-linux-x64-musl')
277
277
  const bindingPackageVersion = require('@visulima/tui-binding-linux-x64-musl/package.json').version
278
278
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
279
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
279
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
280
280
  }
281
281
  return binding
282
282
  } catch (e) {
@@ -292,7 +292,7 @@ function requireNative() {
292
292
  const binding = require('@visulima/tui-binding-linux-x64-gnu')
293
293
  const bindingPackageVersion = require('@visulima/tui-binding-linux-x64-gnu/package.json').version
294
294
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
295
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
295
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
296
296
  }
297
297
  return binding
298
298
  } catch (e) {
@@ -310,7 +310,7 @@ function requireNative() {
310
310
  const binding = require('@visulima/tui-binding-linux-arm64-musl')
311
311
  const bindingPackageVersion = require('@visulima/tui-binding-linux-arm64-musl/package.json').version
312
312
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
313
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
313
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
314
314
  }
315
315
  return binding
316
316
  } catch (e) {
@@ -326,7 +326,7 @@ function requireNative() {
326
326
  const binding = require('@visulima/tui-binding-linux-arm64-gnu')
327
327
  const bindingPackageVersion = require('@visulima/tui-binding-linux-arm64-gnu/package.json').version
328
328
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
329
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
329
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
330
330
  }
331
331
  return binding
332
332
  } catch (e) {
@@ -344,7 +344,7 @@ function requireNative() {
344
344
  const binding = require('@visulima/tui-binding-linux-arm-musleabihf')
345
345
  const bindingPackageVersion = require('@visulima/tui-binding-linux-arm-musleabihf/package.json').version
346
346
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
347
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
347
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
348
348
  }
349
349
  return binding
350
350
  } catch (e) {
@@ -360,7 +360,7 @@ function requireNative() {
360
360
  const binding = require('@visulima/tui-binding-linux-arm-gnueabihf')
361
361
  const bindingPackageVersion = require('@visulima/tui-binding-linux-arm-gnueabihf/package.json').version
362
362
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
363
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
363
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
364
364
  }
365
365
  return binding
366
366
  } catch (e) {
@@ -378,7 +378,7 @@ function requireNative() {
378
378
  const binding = require('@visulima/tui-binding-linux-loong64-musl')
379
379
  const bindingPackageVersion = require('@visulima/tui-binding-linux-loong64-musl/package.json').version
380
380
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
381
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
381
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
382
382
  }
383
383
  return binding
384
384
  } catch (e) {
@@ -394,7 +394,7 @@ function requireNative() {
394
394
  const binding = require('@visulima/tui-binding-linux-loong64-gnu')
395
395
  const bindingPackageVersion = require('@visulima/tui-binding-linux-loong64-gnu/package.json').version
396
396
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
397
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
397
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
398
398
  }
399
399
  return binding
400
400
  } catch (e) {
@@ -412,7 +412,7 @@ function requireNative() {
412
412
  const binding = require('@visulima/tui-binding-linux-riscv64-musl')
413
413
  const bindingPackageVersion = require('@visulima/tui-binding-linux-riscv64-musl/package.json').version
414
414
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
415
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
415
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
416
416
  }
417
417
  return binding
418
418
  } catch (e) {
@@ -428,7 +428,7 @@ function requireNative() {
428
428
  const binding = require('@visulima/tui-binding-linux-riscv64-gnu')
429
429
  const bindingPackageVersion = require('@visulima/tui-binding-linux-riscv64-gnu/package.json').version
430
430
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
431
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
431
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
432
432
  }
433
433
  return binding
434
434
  } catch (e) {
@@ -445,7 +445,7 @@ function requireNative() {
445
445
  const binding = require('@visulima/tui-binding-linux-ppc64-gnu')
446
446
  const bindingPackageVersion = require('@visulima/tui-binding-linux-ppc64-gnu/package.json').version
447
447
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
448
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
448
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
449
449
  }
450
450
  return binding
451
451
  } catch (e) {
@@ -461,7 +461,7 @@ function requireNative() {
461
461
  const binding = require('@visulima/tui-binding-linux-s390x-gnu')
462
462
  const bindingPackageVersion = require('@visulima/tui-binding-linux-s390x-gnu/package.json').version
463
463
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
464
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
464
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
465
465
  }
466
466
  return binding
467
467
  } catch (e) {
@@ -481,7 +481,7 @@ function requireNative() {
481
481
  const binding = require('@visulima/tui-binding-openharmony-arm64')
482
482
  const bindingPackageVersion = require('@visulima/tui-binding-openharmony-arm64/package.json').version
483
483
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
484
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
484
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
485
485
  }
486
486
  return binding
487
487
  } catch (e) {
@@ -497,7 +497,7 @@ function requireNative() {
497
497
  const binding = require('@visulima/tui-binding-openharmony-x64')
498
498
  const bindingPackageVersion = require('@visulima/tui-binding-openharmony-x64/package.json').version
499
499
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
500
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
500
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
501
501
  }
502
502
  return binding
503
503
  } catch (e) {
@@ -513,7 +513,7 @@ function requireNative() {
513
513
  const binding = require('@visulima/tui-binding-openharmony-arm')
514
514
  const bindingPackageVersion = require('@visulima/tui-binding-openharmony-arm/package.json').version
515
515
  if (bindingPackageVersion !== '2.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
516
- throw new Error(`Native binding package version mismatch, expected 2.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
516
+ throw new Error(`Native binding package version mismatch, expected 4.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
517
517
  }
518
518
  return binding
519
519
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/tui",
3
- "version": "2.0.1",
3
+ "version": "4.0.0",
4
4
  "description": "React-based TUI library powered by a native Rust diff engine, drop-in Ink-compatible API",
5
5
  "keywords": [
6
6
  "cli",
@@ -286,10 +286,10 @@
286
286
  "MIGRATION-GUIDE.md"
287
287
  ],
288
288
  "dependencies": {
289
- "@visulima/ansi": "4.0.0",
290
- "@visulima/colorize": "2.0.1",
291
- "@visulima/error": "6.0.0",
292
- "@visulima/string": "3.0.0",
289
+ "@visulima/ansi": "4.1.0",
290
+ "@visulima/colorize": "2.1.1",
291
+ "@visulima/error": "6.1.0",
292
+ "@visulima/string": "3.1.0",
293
293
  "scheduler": "^0.27.0",
294
294
  "yoga-layout": "~3.2.1"
295
295
  },
@@ -316,14 +316,14 @@
316
316
  }
317
317
  },
318
318
  "optionalDependencies": {
319
- "@visulima/tui-binding-darwin-arm64": "2.0.1",
320
- "@visulima/tui-binding-darwin-x64": "2.0.1",
321
- "@visulima/tui-binding-linux-arm64-gnu": "2.0.1",
322
- "@visulima/tui-binding-linux-x64-gnu": "2.0.1",
323
- "@visulima/tui-binding-linux-arm64-musl": "2.0.1",
324
- "@visulima/tui-binding-linux-x64-musl": "2.0.1",
325
- "@visulima/tui-binding-win32-arm64-msvc": "2.0.1",
326
- "@visulima/tui-binding-win32-x64-msvc": "2.0.1"
319
+ "@visulima/tui-binding-darwin-arm64": "4.0.0",
320
+ "@visulima/tui-binding-darwin-x64": "4.0.0",
321
+ "@visulima/tui-binding-linux-arm64-gnu": "4.0.0",
322
+ "@visulima/tui-binding-linux-x64-gnu": "4.0.0",
323
+ "@visulima/tui-binding-linux-arm64-musl": "4.0.0",
324
+ "@visulima/tui-binding-linux-x64-musl": "4.0.0",
325
+ "@visulima/tui-binding-win32-x64-msvc": "4.0.0",
326
+ "@visulima/tui-binding-win32-arm64-msvc": "4.0.0"
327
327
  },
328
328
  "engines": {
329
329
  "node": "^22.14.0 || >=24.10.0"
@@ -1 +0,0 @@
1
- import E,{createContext as R,useRef as S,useState as I,useCallback as s,useMemo as P,useContext as C,useEffect as p}from"react";const m=R({activate(){},activeId:void 0,add(){},deactivate(){},disableFocus(){},enableFocus(){},focus(){},focusNext(){},focusPrevious(){},remove(){}});m.displayName="TuiFocusContext";const y=({children:u})=>{const i=S([]),[a,o]=I(void 0),[n,v]=I(!0),f=s((t,e)=>{if(i.current.some(r=>r.id===t))return;const d={autoFocus:e.autoFocus,id:t,isActive:!0};i.current=[...i.current,d],o(r=>e.autoFocus&&r===void 0||i.current.filter(M=>M.isActive).length===1&&r===void 0?t:r)},[]),l=s(t=>{i.current=i.current.filter(e=>e.id!==t),o(e=>e===t?void 0:e)},[]),F=s(t=>{i.current=i.current.map(e=>e.id===t?{...e,isActive:!0}:e)},[]),c=s(t=>{i.current=i.current.map(e=>e.id===t?{...e,isActive:!1}:e),o(e=>e===t?void 0:e)},[]),x=s(()=>v(!0),[]),b=s(()=>{v(!1),o(void 0)},[]),g=s(()=>{if(!n)return;const t=i.current.filter(e=>e.isActive);t.length!==0&&o(e=>{if(e===void 0)return t[0]?.id;const d=t.findIndex(r=>r.id===e);return t[(d+1)%t.length]?.id??t[0]?.id})},[n]),h=s(()=>{if(!n)return;const t=i.current.filter(e=>e.isActive);t.length!==0&&o(e=>{if(e===void 0)return t.at(-1)?.id;const d=t.findIndex(r=>r.id===e);return t[(d-1+t.length)%t.length]?.id??t.at(-1)?.id})},[n]),A=s(t=>{n&&i.current.some(e=>e.id===t&&e.isActive)&&o(t)},[n]),N=P(()=>({activate:F,activeId:a,add:f,deactivate:c,disableFocus:b,enableFocus:x,focus:A,focusNext:g,focusPrevious:h,remove:l}),[a,f,l,F,c,x,b,g,h,A]);return E.createElement(m.Provider,{value:N},u)},T=({autoFocus:u=!1,id:i,isActive:a=!0}={})=>{const{activate:o,activeId:n,add:v,deactivate:f,focus:l,remove:F}=C(m),c=P(()=>i??Math.random().toString(36).slice(2,7),[i]);return p(()=>(v(c,{autoFocus:u}),()=>{F(c)}),[c,u]),p(()=>{a?o(c):f(c)},[a,c]),{focus:l,isFocused:!!c&&n===c}},$=()=>{const u=C(m);return{activeId:u.activeId,disableFocus:u.disableFocus,enableFocus:u.enableFocus,focus:u.focus,focusNext:u.focusNext,focusPrevious:u.focusPrevious}};export{m as FocusContext,y as FocusProvider,T as useFocus,$ as useFocusManager};
@@ -1,2 +0,0 @@
1
- import{l}from"./index-Dl9I2_QH.js";class B extends l.EventEmitter{constructor(t){super(),this.stdin=t}stdin;_boundHandleData=null;_pasteBuffer=null;start(){typeof this.stdin.setRawMode=="function"&&this.stdin.setRawMode(!0),this.stdin.resume(),this.stdin.setEncoding("utf8"),this._boundHandleData=this.handleData.bind(this),this.stdin.on("data",this._boundHandleData)}stop(){typeof this.stdin.setRawMode=="function"&&this.stdin.setRawMode(!1),this.stdin.pause(),this._boundHandleData&&(this.stdin.removeListener("data",this._boundHandleData),this._boundHandleData=null)}handleData(t){if(t===""){this.emit("exit");return}if(t.includes("\x1B[200~")||this._pasteBuffer!==null){if(this._pasteBuffer===null?this._pasteBuffer=t.replace("\x1B[200~",""):this._pasteBuffer+=t,this._pasteBuffer.includes("\x1B[201~")){const e=this._pasteBuffer.replace("\x1B[201~","");this._pasteBuffer=null,this.emit("paste",e),this.listenerCount("paste")===0&&this.emit("data",e)}return}if(t.length===1){const e=t.charCodeAt(0);if(e>=1&&e<=26&&e!==3&&e!==9&&e!==10&&e!==13){const s=String.fromCharCode(e+96);this.emit("ctrl",s),this.emit("data",t,{ctrl:!0});return}}if(t==="\x1B[A"){this.emit("keydown","up");return}if(t==="\x1B[B"){this.emit("keydown","down");return}if(t==="\x1B[C"){this.emit("keydown","right");return}if(t==="\x1B[D"){this.emit("keydown","left");return}if(t===" "){this.emit("keydown","tab");return}if(t==="\x1B[Z"){this.emit("keydown","shift-tab");return}if(t==="\x1B"){this.emit("keydown","escape");return}if(t==="\r"||t===`
2
- `){this.emit("keydown","enter");return}if(t===""){this.emit("keydown","backspace");return}if(t==="\x1B[3~"){this.emit("keydown","delete");return}if(t==="\x1B[5~"){this.emit("keydown","pageUp");return}if(t==="\x1B[6~"){this.emit("keydown","pageDown");return}if(t==="\x1B[H"||t==="\x1B[1~"){this.emit("keydown","home");return}if(t==="\x1B[F"||t==="\x1B[4~"){this.emit("keydown","end");return}if(t.length===2&&t[0]==="\x1B"){this.emit("meta",t[1]),this.emit("data",t,{meta:!0});return}if(t.startsWith("\x1B[<")){const e=t.match(/\u001B\[<(\d+);(\d+);(\d+)(M)/i);if(e){const s=Number.parseInt(e[1]),a=Number.parseInt(e[2])-1,d=Number.parseInt(e[3])-1,r=e[4]==="m",h=(s&4)!==0,u=(s&8)!==0,o=(s&16)!==0,n=s&-29;let i=null;if(n===0&&!r?i="left":n===1&&!r?i="middle":n===2&&!r?i="right":n===64?i="scrollUp":n===65&&(i="scrollDown"),i){const f={button:i,ctrl:o,meta:u,shift:h,x:a,y:d};this.emit("mouse",f),i==="left"&&this.emit("click",{x:a,y:d})}}return}this.emit("data",t)}}export{B as InputParser};
@@ -1,2 +0,0 @@
1
- import{createDecMode as P,setMode as w,resetMode as M,BracketedPasteMode as R,cursorUp as U,cursorToColumn1 as L,cursorHide as b,REQUEST_CURSOR_POSITION as z,cursorPosition as u,eraseLine as A,cursorShow as B}from"@visulima/ansi";import{terminalSize as C,Renderer as Y}from"./Renderer-BeS49FNq.js";const T=P(2026),_=w(T),g=M(T),k=w(R),D=M(R);function Q(I,d={}){const S=d.rows??10,E=d.fps??60,O=d.onExit??"preserve";let n=null,o=null,c=null,i=80,t=10,h=0,r=1;function e(s){o.writeRaw(s)}function a(){c.fill(0),I(c,i,t,h++),e(_);try{o.render(c)}finally{e(g)}}function v(s){r=s-t,e(U(t)+L),o.setRowOffset(r),a(),n=setInterval(()=>{a()},Math.round(1e3/E))}function x(){const s=C();i=s.cols;const y=s.rows;t=Math.min(S,y),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.setEncoding("utf8"),o=new Y(i,t),c=new Uint32Array(i*t*2),e(b),e(k),e(`
2
- `.repeat(t)),e(z),process.on("SIGINT",l);let p="";const f=N=>{p+=N;const m=p.match(/\u001B\[(\d+);(\d+)R/);m&&(process.stdin.off("data",f),v(Number.parseInt(m[1],10)))};process.stdin.on("data",f)}function l(){if(n&&(clearInterval(n),n=null),o){if(O==="destroy"){for(let s=0;s<t;s++)e(u(r+1+s,1)+A);e(u(r+1,1))}else e(u(r+t+1,1));e(D),e(B)}process.stdin.isTTY&&process.stdin.setRawMode(!1),process.stdin.pause(),process.exit(0)}return{start:x,stop:l}}export{Q as createInlineLoop};
@@ -1 +0,0 @@
1
- import{createContext as C}from"react";import y from"react-reconciler";import{NoEventPriority as h,DiscreteEventPriority as v,DefaultEventPriority as b}from"react-reconciler/constants.js";import{unstable_shouldYield as T,unstable_scheduleCallback as x,unstable_now as k,unstable_cancelCallback as I}from"scheduler";import{LayoutNode as c}from"./LayoutNode-LPYsuzBg.js";import{applyStyles as m,resolveColor as f}from"./NAMED_COLORS-82DpREQV.js";import{g as P}from"./text-width-e49vlbQH.js";let u=null;function H(e){u=e}let d=h;function p(e){const t=f(e.fg===void 0?e.color===void 0?void 0:e.color:e.fg),n=f(e.bg===void 0?e.backgroundColor===void 0?void 0:e.backgroundColor:e.bg);let r;return e.styles===void 0?(r=0,e.bold&&(r|=1),(e.dim||e.dimColor)&&(r|=2),e.italic&&(r|=4),e.underline&&(r|=8),e.blink&&(r|=16),e.inverse&&(r|=32),e.hidden&&(r|=64),e.strikethrough&&(r|=128)):r=e.styles,{bg:n,fg:t,styles:r}}const N={afterActiveInstanceBlur:()=>{},appendChild(e,t){e.insertChild(t,e.children.length)},appendChildToContainer(e,t){e.insertChild(t,e.children.length)},appendInitialChild(e,t){e.insertChild(t,e.children.length)},beforeActiveInstanceBlur:()=>{},cancelCallback:I,cancelTimeout:clearTimeout,clearContainer(e){},commitTextUpdate(e,t,n){e.text=n,e.yogaNode.markDirty()},commitUpdate(e,t,n,r,s){m(e.yogaNode,r);const{bg:o,fg:i,styles:a}=p(r);e.fg=i,e.bg=o,e.styles=a,e._style=r,e.transform=typeof r.transform=="function"?r.transform:void 0},createInstance(e,t,n,r,s){const o=new c,i={...t};i.flexDirection===void 0&&(i.flexDirection="row"),i.flexShrink===void 0&&(i.flexShrink=1),m(o.yogaNode,i);const{bg:a,fg:l,styles:g}=p(t);return o.fg=l,o.bg=a,o.styles=g,o._style=t,typeof t.transform=="function"&&(o.transform=t.transform),o},createTextInstance(e,t,n,r){const s=new c;return s.text=e,s.yogaNode.setWidth(P(e)),s.yogaNode.setHeight(1),s},detachDeletedInstance:e=>{e.destroy()},finalizeInitialChildren(e,t,n,r,s){return!1},getChildHostContext(e,t,n){return{isInsideText:t==="text"}},getCurrentEventPriority:()=>v,getCurrentUpdatePriority:()=>d,getInstanceFromNode:()=>null,getPublicInstance(e){return e},getRootHostContext(e){return{isInsideText:!1}},hideInstance(e){e._hidden=!0},hideTextInstance(e){e._hidden=!0},HostTransitionContext:C(null),insertBefore(e,t,n){t.parent&&t.remove();const r=e.children.indexOf(n);e.insertChild(t,r)},isPrimaryRenderer:!0,maySuspendCommit:()=>!0,noTimeout:-1,NotPendingTransition:void 0,now:k,preloadInstance:()=>!0,prepareForCommit(e){return null},preparePortalMount:()=>{},prepareScopeUpdate:()=>{},prepareUpdate(e,t,n,r,s,o){if(n===r)return null;let i=0;for(const l of Object.keys(n))l!=="children"&&(i+=1);let a=0;for(const l of Object.keys(r))if(l!=="children"&&(a+=1,n[l]!==r[l]))return!0;return i===a?null:!0},removeChild(e,t){t.remove()},removeChildFromContainer(e,t){t.remove()},requestPostPaintCallback:()=>{},resetAfterCommit(e){typeof u=="function"&&u()},resolveEventTimeStamp:()=>-1.1,resolveEventType:()=>null,resolveUpdatePriority(){return d!==h?d:b},scheduleCallback:x,scheduleMicrotask:queueMicrotask,scheduleTimeout:setTimeout,setCurrentUpdatePriority(e){d=e},shouldAttemptEagerTransition:()=>!1,shouldSetTextContent(e,t){return!1},shouldYield:T,startSuspendingCommit:()=>{},supportsHydration:!1,supportsMicrotasks:!0,supportsMutation:!0,supportsPersistence:!1,suspendInstance:()=>{},trackSchedulerEvent:()=>{},unhideInstance(e,t){e._hidden=!1},unhideTextInstance(e,t){e._hidden=!1},waitForCommitToBeReady:()=>null,warnsIfNotActing:!0},M=y(N);export{M as T,H as s};
@@ -1,24 +0,0 @@
1
- import{createRequire as Le}from"node:module";import{jsx as _}from"react/jsx-runtime";import{cursorShow as ot,setMode as le,BracketedPasteMode as de,resetMode as ce,eraseLines as G,cursorHide as nt,cursorUp as Vt,cursorNextLine as We,cursorTo as $e,eraseLineEnd as Ae,createDecMode as Be,ALT_SCREEN_ON as Xt,clearScreenAndHomeCursor as He,ALT_SCREEN_OFF as Jt}from"@visulima/ansi";import{wordWrap as Ge}from"@visulima/string";import{ConcurrentRoot as Ke,LegacyRoot as Ye}from"react-reconciler/constants.js";import U from"yoga-layout";import{a as Fe}from"./accessibility-context-DDyHTwmA.js";import{useState as ct,useRef as I,useCallback as v,useEffect as ht,useMemo as B}from"react";import{e as qe}from"./animation-context-DW3p-vpk.js";import{e as ze}from"./app-context-DTm1_XBA.js";import{o as Ve}from"./cursor-context-CFviBqPX.js";import Xe from"../components/error-boundary.js";import{o as Je}from"./focus-context-CsT69klR.js";import{t as Qe}from"./stderr-context-CR2LLec6.js";import{e as Ze}from"./stdin-context-BjMA9Sbi.js";import{t as ti}from"./stdout-context-DAAlQct2.js";import{I as ei,_ as ii,r as si,H as ri}from"./renderer-Cs0KEr1o.js";import{c as oi,e as ni}from"./dom-rphpG0kf.js";import{resolveFlags as Qt}from"./kittyFlags-g8ALyoCU.js";import{buildReturnToBottomPrefix as mt,buildCursorSuffix as st,buildCursorOnlySequence as he,cursorPositionChanged as gt,buildCursorShapeSequence as Zt}from"./buildCursorOnlySequence-CerkmjWt.js";import{p as ui}from"./load-native-root-binding-CxJnHcac.js";import{a as ai}from"./measure-text-B7juNq4Y.js";import{j as k,c as li}from"./reconciler-DkwOtC5B.js";import{measureAndExtractObservers as di}from"./ResizeObserver-BI9bDy-j.js";import{calculateScroll as ci}from"./calculateScroll-D4Y_JR4H.js";import{g as q}from"./utils-CVgM8kTn.js";let _e;const De=i=>(_e??=Le(import.meta.url))(i),X=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,vt=i=>{if(typeof X<"u"&&X.versions&&X.versions.node){const[t,e]=X.versions.node.split(".").map(Number);if(t>22||t===22&&e>=3||t===20&&e>=16)return X.getBuiltinModule(i)}return De(i)},P=X,{env:yt}=P,{PassThrough:qt,Stream:Me}=vt("node:stream"),{Buffer:zt}=vt("node:buffer"),{Console:Ue}=vt("node:console"),{EventEmitter:je}=vt("node:events"),te=i=>i in yt&&yt[i]!=="0"&&yt[i]!=="false",fe=te("CI")||te("CONTINUOUS_INTEGRATION"),ee=["assert","count","countReset","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","table","time","timeEnd","timeLog","trace","warn"];let xt={};const hi=i=>{const t=new qt,e=new qt;t.write=r=>{i("stdout",r)},e.write=r=>{i("stderr",r)};const s=new console.Console(t,e);for(const r of ee)xt[r]=console[r],console[r]=s[r];return()=>{for(const r of ee)console[r]=xt[r];xt={}}},J=[];J.push("SIGHUP","SIGINT","SIGTERM");process.platform!=="win32"&&J.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&J.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT");const pt=i=>!!i&&!0&&typeof i.removeListener=="function"&&typeof i.emit=="function"&&typeof i.reallyExit=="function"&&typeof i.listeners=="function"&&typeof i.kill=="function"&&typeof i.pid=="number"&&typeof i.on=="function",Tt=Symbol.for("signal-exit emitter"),St=globalThis,fi=Object.defineProperty.bind(Object);let pi=class{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(St[Tt])return St[Tt];fi(St,Tt,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(t,e){this.listeners[t].push(e)}removeListener(t,e){const s=this.listeners[t],r=s.indexOf(e);r!==-1&&(r===0&&s.length===1?s.length=0:s.splice(r,1))}emit(t,e,s){if(this.emitted[t])return!1;this.emitted[t]=!0;let r=!1;for(const n of this.listeners[t])r=n(e,s)===!0||r;return t==="exit"&&(r=this.emit("afterExit",e,s)||r),r}},pe=class{};const mi=i=>({onExit(t,e){return i.onExit(t,e)},load(){return i.load()},unload(){return i.unload()}});class gi extends pe{onExit(){return()=>{}}load(){}unload(){}}let wi=class extends pe{#n=Et.platform==="win32"?"SIGINT":"SIGHUP";#e=new pi;#t;#r;#o;#s={};#i=!1;constructor(t){super(),this.#t=t,this.#s={};for(const e of J)this.#s[e]=()=>{const s=this.#t.listeners(e);let{count:r}=this.#e;const n=t;if(typeof n.__signal_exit_emitter__=="object"&&typeof n.__signal_exit_emitter__.count=="number"&&(r+=n.__signal_exit_emitter__.count),s.length===r){this.unload();const l=this.#e.emit("exit",null,e),o=e==="SIGHUP"?this.#n:e;l||t.kill(t.pid,o)}};this.#o=t.reallyExit,this.#r=t.emit}onExit(t,e){if(!pt(this.#t))return()=>{};this.#i===!1&&this.load();const s=e?.alwaysLast?"afterExit":"exit";return this.#e.on(s,t),()=>{this.#e.removeListener(s,t),this.#e.listeners.exit.length===0&&this.#e.listeners.afterExit.length===0&&this.unload()}}load(){if(!this.#i){this.#i=!0,this.#e.count+=1;for(const t of J)try{const e=this.#s[t];e&&this.#t.on(t,e)}catch{}this.#t.emit=(t,...e)=>this.#a(t,...e),this.#t.reallyExit=t=>this.#u(t)}}unload(){this.#i&&(this.#i=!1,J.forEach(t=>{const e=this.#s[t];if(!e)throw new Error("Listener not defined for signal: "+t);try{this.#t.removeListener(t,e)}catch{}}),this.#t.emit=this.#r,this.#t.reallyExit=this.#o,this.#e.count-=1)}#u(t){return pt(this.#t)?(this.#t.exitCode=t||0,this.#e.emit("exit",this.#t.exitCode,null),this.#o.call(this.#t,this.#t.exitCode)):0}#a(t,...e){const s=this.#r;if(t==="exit"&&pt(this.#t)){typeof e[0]=="number"&&(this.#t.exitCode=e[0]);const r=s.call(this.#t,t,...e);return this.#e.emit("exit",this.#t.exitCode,null),r}else return s.call(this.#t,t,...e)}};const Et=globalThis.process,{onExit:vi}=mi(pt(Et)?new wi(Et):new gi),me="\x1B[200~",ie="\x1B[201~",bi=i=>i>=48&&i<=63,yi=i=>i>=32&&i<=47,ge=i=>i>=64&&i<=126,xi=(i,t,e)=>{const s=t+e+1;let r=s;for(;r<i.length;r++){const n=i.codePointAt(r);if(n===void 0)return"pending";if(!(bi(n)||yi(n))&&!(n===91&&r===s))return ge(n)?{nextIndex:r+1,sequence:i.slice(t,r+1)}:void 0}return"pending"},Ti=(i,t,e)=>{const s=t+e+2;if(s>i.length)return"pending";const r=i.codePointAt(s-1);if(!(r===void 0||!ge(r)))return{nextIndex:s,sequence:i.slice(t,s)}},se=(i,t,e)=>{const s=i[t+e];if(s===void 0)return"pending";if(s==="[")return xi(i,t,e);if(s==="O")return Ti(i,t,e)},Si=(i,t)=>{const e=i.codePointAt(t+1),s=e!==void 0&&e>65535?2:1,r=t+1+s;return{nextIndex:r,sequence:i.slice(t,r)}},Ri=(i,t)=>{if(t===i.length-1)return"pending";if(i[t+1]==="\x1B"){if(t+2>=i.length)return"pending";const s=se(i,t,2);return s==="pending"?"pending":s||{nextIndex:t+2,sequence:i.slice(t,t+2)}}const e=se(i,t,1);return e==="pending"?"pending":e||Si(i,t)},re=(i,t)=>{let e=0;for(let s=0;s<i.length;s++){const r=i[s];(r===""||r==="\b")&&(s>e&&t.push(i.slice(e,s)),t.push(r),e=s+1)}e<i.length&&t.push(i.slice(e))},Ci=i=>{const t=[];let e=0;const s=r=>({events:t,pending:i.slice(r)});for(;e<i.length;){const r=i.indexOf("\x1B",e);if(r===-1)return re(i.slice(e),t),{events:t,pending:""};r>e&&re(i.slice(e,r),t);const n=Ri(i,r);if(n==="pending")return s(r);if(n.sequence===me){const l=n.nextIndex,o=i.indexOf(ie,l);if(o===-1)return s(r);t.push({paste:i.slice(l,o)}),e=o+ie.length;continue}t.push(n.sequence),e=n.nextIndex}return{events:t,pending:""}},Ei=()=>{let i="";return{flushPendingEscape(){if(!i.startsWith("\x1B"))return;const t=i;return i="",t},hasPendingEscape(){return i.startsWith("\x1B")&&!i.startsWith(me)&&i!=="\x1B[200"},push(t){const e=Ci(i+t);return i=e.pending,e.events},reset(){i=""}}},Oi=" ",Pi="\x1B[Z",Ni="\x1B",oe=le(de),Rt=ce(de),we=({children:i,exitOnCtrlC:t,interactive:e,onExit:s,onRegisterInputControl:r,onSuspendTerminal:n,onWaitUntilRenderFlush:l,renderThrottleMs:o,setCursorPosition:a,stderr:f,stdin:h,stdout:m,writeToStderr:w,writeToStdout:d})=>{const[c,b]=ct(!0),[y,R]=ct(void 0),[,T]=ct([]),D=I(0),N=I(new Map),W=I(void 0),C=I(0),E=I(!1),M=I(0),[x]=ct(()=>{const u=new je;return u.setMaxListeners(1/0),u}),$=I(void 0),Q=I(void 0);Q.current??=Ei();const Z=I(void 0),Pt=I(!1),Te=20,K=v(()=>{Z.current&&(clearTimeout(Z.current),Z.current=void 0)},[]),Y=v(()=>{W.current&&(clearTimeout(W.current),W.current=void 0)},[]),ut=v(()=>{if(Y(),N.current.size===0)return;let u=Number.POSITIVE_INFINITY;for(const g of N.current.values())u=Math.min(u,g.nextDueTime);const p=Math.max(0,u-performance.now());W.current=setTimeout(()=>{W.current=void 0;const g=performance.now(),S=[...N.current.values()];for(const O of S){if(g<O.nextDueTime)continue;O.callback(g);const Ie=g-O.startTime,ke=Math.floor(Ie/O.interval)+1;O.nextDueTime=O.startTime+ke*O.interval}ut()},p)},[Y]),Nt=v((u,p)=>{const g=performance.now();return N.current.set(u,{callback:u,interval:p,nextDueTime:g+p,startTime:g}),ut(),{startTime:g,unsubscribe(){if(N.current.delete(u),N.current.size===0){Y();return}ut()}}},[Y,ut]);ht(()=>()=>{Y()},[Y]);const L=h.isTTY,It=v(()=>{$.current&&(h.removeListener("readable",$.current),$.current=void 0)},[h]),F=v(()=>{Q.current?.reset(),K(),It()},[K,It]),j=v(()=>{E.current=!1,h.setRawMode(!1),h.unref(),C.current=0,F()},[h,F]),tt=v(u=>{L&&(C.current>0||E.current)&&j(),s(u)},[L,j,s]),kt=v(u=>{if(u.includes("")&&t){tt();return}u===Ni&&c&&R(p=>{if(!p)return p})},[t,tt,c]),et=v(u=>{kt(u),x.emit("input",u)},[kt,x]),Lt=v(()=>{K(),Z.current=setTimeout(()=>{Z.current=void 0;const u=Q.current.flushPendingEscape();u&&et(u)},Te)},[K,et]),bt=v(()=>{K();let u;for(;(u=h.read())!==null;){const p=Q.current.push(u);for(const g of p)if(typeof g=="string")et(g);else{if(x.listenerCount("paste")===0){Pt.current||(Pt.current=!0,w(`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().
2
- `)),et(g.paste);continue}x.emit("paste",g.paste)}}Q.current.hasPendingEscape()&&Lt()},[h,et,K,Lt,w,x]),at=v(()=>{$.current||($.current=bt,h.addListener("readable",bt))},[h,bt]),_t=v(u=>{if(!L)throw h===P.stdin?new Error(`Raw mode is not supported on the current process.stdin, which Ink uses as input stream by default.
3
- Read about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported`):new Error(`Raw mode is not supported on the stdin provided to Ink.
4
- Read about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported`);if(h.setEncoding("utf8"),u){if(C.current===0){const p=E.current;E.current=!1,p||(h.ref(),h.setRawMode(!0)),at()}C.current++;return}C.current!==0&&--C.current===0&&(F(),E.current=!0,queueMicrotask(()=>{E.current&&j()}))},[L,h,at,F,j]),Dt=v(u=>{if(m.isTTY){if(u){M.current===0&&m.write(oe),M.current++;return}M.current!==0&&--M.current===0&&m.write(Rt)}},[m]),Mt=I({bracketedPaste:!1,rawMode:!1}),Ut=v(()=>{const u=L&&(C.current>0||E.current),p=M.current>0;Mt.current={bracketedPaste:p,rawMode:u},p&&m.isTTY&&m.write(Rt),u&&(E.current=!1,F(),h.setRawMode(!1),h.unref())},[L,m,h,F]),Wt=v(()=>{const{bracketedPaste:u,rawMode:p}=Mt.current;p&&(h.ref(),h.setRawMode(!0),h.setEncoding("utf8"),at()),u&&m.isTTY&&m.write(oe)},[h,m,at]);ht(()=>{r(Ut,Wt)},[r,Ut,Wt]);const $t=v((u,p)=>{const g=u.findIndex(S=>S.id===p);for(let S=g+1;S<u.length;S++){const O=u[S];if(O?.isActive)return O.id}},[]),At=v((u,p)=>{const g=u.findIndex(S=>S.id===p);for(let S=g-1;S>=0;S--){const O=u[S];if(O?.isActive)return O.id}},[]),lt=v(()=>{T(u=>(R(p=>{const g=u.find(S=>S.isActive)?.id;return $t(u,p)??g}),u))},[$t]),dt=v(()=>{T(u=>(R(p=>{const g=u.findLast(S=>S.isActive)?.id;return At(u,p)??g}),u))},[At]);ht(()=>{const u=g=>{!c||D.current===0||(g===Oi&&lt(),g===Pi&&dt())};x.on("input",u);const p=x;return()=>{p.off("input",u)}},[c,lt,dt,x]);const Bt=v(()=>{b(!0)},[]),Ht=v(()=>{b(!1)},[]),Gt=v(u=>{T(p=>(p.some(g=>g?.id===u)&&R(u),p))},[]),Kt=v((u,{autoFocus:p})=>{T(g=>(D.current=g.length+1,[...g,{id:u,isActive:!0}])),p&&R(g=>g||u)},[]),Yt=v(u=>{R(p=>{if(p!==u)return p}),T(p=>{const g=p.filter(S=>S.id!==u);return D.current=g.length,g})},[]),Ft=v(u=>{T(p=>p.map(g=>g.id!==u?g:{id:u,isActive:!0}))},[]),jt=v(u=>{R(p=>{if(p!==u)return p}),T(p=>p.map(g=>g.id!==u?g:{id:u,isActive:!1}))},[]);ht(()=>()=>{const u=!m.destroyed&&!m.writableEnded;e&&u&&m.write(ot),L&&(C.current>0||E.current)&&j(),M.current>0&&(m.isTTY&&u&&m.write(Rt),M.current=0)},[m,L,j,e]);const Se=B(()=>({exit:tt,suspendTerminal:n,waitUntilRenderFlush:l}),[tt,n,l]),Re=B(()=>({internal_eventEmitter:x,internal_exitOnCtrlC:t,isRawModeSupported:L,setBracketedPasteMode:Dt,setRawMode:_t,stdin:h}),[h,_t,Dt,L,t,x]),Ce=B(()=>({stdout:m,write:d}),[m,d]),Ee=B(()=>({stderr:f,write:w}),[f,w]),Oe=B(()=>({setCursorPosition:a}),[a]),Pe=B(()=>({activate:Ft,activeId:y,add:Kt,deactivate:jt,disableFocus:Ht,enableFocus:Bt,focus:Gt,focusNext:lt,focusPrevious:dt,remove:Yt}),[y,Kt,Yt,Ft,jt,Bt,Ht,lt,dt,Gt]),Ne=B(()=>({renderThrottleMs:o,subscribe:Nt}),[Nt,o]);return _(ze.Provider,{value:Se,children:_(Ze.Provider,{value:Re,children:_(ti.Provider,{value:Ce,children:_(Qe.Provider,{value:Ee,children:_(Je.Provider,{value:Pe,children:_(qe.Provider,{value:Ne,children:_(Ve.Provider,{value:Oe,children:_(Xe,{onError:tt,children:i})})})})})})})})};we.displayName="InternalApp";const Ii=(i,t,e)=>{if(e<=0||!i.yogaNode)return"";const{yogaNode:s}=i,r=s.getComputedBorder(U.EDGE_LEFT),n=s.getComputedBorder(U.EDGE_RIGHT),l=s.getComputedBorder(U.EDGE_TOP),o=s.getComputedPadding(U.EDGE_LEFT),a=s.getComputedPadding(U.EDGE_RIGHT),f=s.getComputedPadding(U.EDGE_TOP),h=Math.round(s.getComputedWidth()-r-n-o-a);if(h<=0)return"";const m=new ei({height:e,width:h}),w=-(i.internal_scrollState?.scrollLeft??0)-r-o,d=-t-l-f;for(const c of i.childNodes)ii(c,m,{absoluteOffsetX:w,absoluteOffsetY:d,offsetX:w,offsetY:d,skipStaticElements:!1});return m.get().output},Ot=new WeakMap,z=i=>i??"default",ve=()=>{let i,t;return{consumeDelta:()=>{if(z(t)===z(i))return"";const e=z(t);return i=t,Zt(e)},consumeRestoreOnDone:()=>{const e=z(i)!=="default";return i=void 0,t=void 0,e?Zt("default"):""},isDirty:()=>z(t)!==z(i),setPending:e=>{t=e}}},rt=(i,t)=>t.endsWith(`
5
- `)?i.length-1:i.length,be=i=>i.rows||1/0,wt=(i,t)=>Math.min(i,be(t)),ki=(i,{showCursor:t=!1}={})=>{let e=0,s="",r=!1,n,l=!1,o,a=!1;const f=ve(),h=()=>l?n:void 0,m=(d,c)=>{const b=gt(c,o);return d!==s||b||f.isDirty()},w=d=>{!t&&!r&&(i.write(nt),r=!0);const c=h();l=!1;const b=gt(c,o);if(!m(d,c))return!1;const y=f.consumeDelta(),R=d.split(`
6
- `),T=rt(R,d),D=st(T,c);if(d===s&&b)i.write(y+he({cursorPosition:c,cursorWasShown:a,previousCursorPosition:o,previousLineCount:e,visibleLineCount:T}));else if(d===s&&y!=="")i.write(y);else{s=d;const N=mt(a,e,o);i.write(y+N+G(wt(e,i))+d+D),e=R.length}return o=c?{...c}:void 0,a=c!==void 0,!0};return w.clear=()=>{const d=mt(a,e,o);i.write(d+G(wt(e,i))),s="",e=0,o=void 0,a=!1},w.done=()=>{s="",e=0,o=void 0,a=!1;const d=f.consumeRestoreOnDone();d!==""&&i.write(d),t||(i.write(ot),r=!1)},w.reset=()=>{s="",e=0,o=void 0,a=!1},w.sync=d=>{const c=l?n:void 0;l=!1;const b=d.split(`
7
- `);s=d,e=b.length;const y=f.consumeDelta();y!==""&&i.write(y),!c&&a&&i.write(nt),c&&i.write(st(rt(b,d),c)),o=c?{...c}:void 0,a=c!==void 0},w.setCursorPosition=d=>{n=d,l=!0},w.setCursorShape=f.setPending,w.isCursorDirty=()=>l||f.isDirty(),w.willRender=d=>m(d,h()),w},Li=(i,{showCursor:t=!1}={})=>{let e=[],s="",r=!1,n,l=!1,o,a=!1;const f=ve(),h=()=>l?n:void 0,m=(d,c)=>{const b=gt(c,o);return d!==s||b||f.isDirty()},w=d=>{!t&&!r&&(i.write(nt),r=!0);const c=h();l=!1;const b=gt(c,o);if(!m(d,c))return!1;const y=f.consumeDelta(),R=d.split(`
8
- `),T=rt(R,d),D=rt(e,s);if(d===s&&b)return i.write(y+he({cursorPosition:c,cursorWasShown:a,previousCursorPosition:o,previousLineCount:e.length,visibleLineCount:T})),o=c?{...c}:void 0,a=c!==void 0,!0;if(d===s&&y!=="")return i.write(y),!0;const N=mt(a,e.length,o);if(d===`
9
- `||s.length===0){const x=st(T,c);return i.write(y+N+G(wt(e.length,i))+d+x),a=c!==void 0,o=c?{...c}:void 0,s=d,e=R,!0}const W=d.endsWith(`
10
- `),C=[y,N],E=be(i);if(T<D){const x=s.endsWith(`
11
- `)?1:0;C.push(G(Math.min(D-T+x,E)),Vt(Math.min(T,E-1)))}else C.push(Vt(Math.min(D-1,E-1)));for(let x=0;x<T;x++){const $=x===T-1;if(R[x]===e[x]){(!$||W)&&C.push(We());continue}C.push($e(0)+R[x]+Ae+($&&!W?"":`
12
- `))}const M=st(T,c);return C.push(M),i.write(C.join("")),a=c!==void 0,o=c?{...c}:void 0,s=d,e=R,!0};return w.clear=()=>{const d=mt(a,e.length,o);i.write(d+G(wt(e.length,i))),s="",e=[],o=void 0,a=!1},w.done=()=>{s="",e=[],o=void 0,a=!1;const d=f.consumeRestoreOnDone();d!==""&&i.write(d),t||(i.write(ot),r=!1)},w.reset=()=>{s="",e=[],o=void 0,a=!1},w.sync=d=>{const c=l?n:void 0;l=!1;const b=d.split(`
13
- `);s=d,e=b;const y=f.consumeDelta();y!==""&&i.write(y),!c&&a&&i.write(nt),c&&i.write(st(rt(b,d),c)),o=c?{...c}:void 0,a=c!==void 0},w.setCursorPosition=d=>{n=d,l=!0},w.setCursorShape=f.setPending,w.isCursorDirty=()=>l||f.isDirty(),w.willRender=d=>m(d,h()),w},_i=(i,{incremental:t=!1,showCursor:e=!1}={})=>t?Li(i,{showCursor:e}):ki(i,{showCursor:e}),Di={create:_i},ye=Be(2026),H=le(ye),A=ce(ye);function Mi(i,t){return"isTTY"in i&&i.isTTY&&(t??!fe)}let V;const Ui=()=>{if(V!==!1){if(V!==void 0)return V;try{return V=ui(import.meta.url).Renderer,V}catch{V=!1;return}}},Wi=i=>{const t=Ui();if(!t)return;let e,s=0,r=0;const n=(l,o)=>{(!e||s!==l||r!==o)&&(e?e.resize(l,o):e=new t(l,o),s=l,r=o)};return{clear(){if(e){const l=new Uint32Array(s*r*2),o=65535;for(let a=0;a<l.length;a+=2)l[a]=32,l[a+1]=o;e.render(l)}},destroy(){e=void 0},render(l,o,a){if(n(o,a),!!e){i.isTTY&&e.writeRaw(H);try{e.render(l)}finally{i.isTTY&&e.writeRaw(A)}}},resize(l,o){n(l,o)}}};function ne(i,t=0,e={}){const s=e.leading??!0,r=e.trailing??!0;let n,l,o,a;const f=()=>{if(l===void 0)return;const c=l;l=void 0,a=i(...c)},h=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},m=()=>{n=void 0,r&&f(),l=void 0,o=void 0},w=()=>{h(),n=setTimeout(m,t)},d=function(...c){const b=Date.now();if(o??=b,b-o>=t)return l=c,f(),o=b,w(),a;l=c;const y=n===void 0;return w(),s&&y&&f(),a};return d.cancel=()=>{h(),l=void 0,o=void 0},d.flush=()=>(h(),f(),o=void 0,a),d}console.Console||(console.Console=Ue);const it=()=>{},ue=async()=>new Promise(i=>{setImmediate(i)}),$i=27,Ai=91,Bi=63,Hi=117,Gi=48,Ki=57,Yi=i=>i>=Gi&&i<=Ki,xe=(i,t)=>{if(i[t]!==$i||i[t+1]!==Ai||i[t+2]!==Bi)return;let e=t+3;const s=e;for(;e<i.length&&Yi(i[e]);)e++;if(e!==s){if(e===i.length)return{state:"partial"};if(i[e]===Hi)return{endIndex:e,state:"complete"}}},Fi=i=>{for(let t=0;t<i.length;t++)if(xe(i,t)?.state==="complete")return!0;return!1},ji=i=>{const t=[];let e=0;for(;e<i.length;){const s=xe(i,e);if(s?.state==="complete"){e=s.endIndex+1;continue}if(s?.state==="partial")break;t.push(i[e]),e++}return t},qi=({isTty:i,isUnmounting:t,isWindows:e,nextOutputHeight:s,previousOutputHeight:r,viewportRows:n})=>{if(!i)return!1;const l=r>0,o=r>=n,a=s>=n,f=r>n,h=s>n,m=o&&s<n;return f||h&&l||m||t&&o||e&&(a||o)},Ct=i=>i instanceof Error||Object.prototype.toString.call(i)==="[object Error]",ae=i=>{const t=!i.destroyed&&!i.writableEnded&&(i.writable??!0),e=i._writableState!==void 0||i.writableLength!==void 0;return{canWriteToStdout:t,hasWritableState:e}},ft=(i,t)=>{if(!i||typeof i.flush!="function")return;const e=i;t?e.flush():typeof e.cancel=="function"&&e.cancel()};class zi{isConcurrent;options;log;manualCursorPosition;renderedCursorPosition;renderedCursorRequested;throttledLog;isScreenReaderEnabled;interactive;renderThrottleMs;alternateScreen;isUnmounted;isUnmounting;lastOutput;lastOutputToRender;lastOutputHeight;lastTerminalWidth;nativeLog;useNativeRenderer;container;rootNode;fullStaticOutput;backbufferNode;backbufferMultiWarned=!1;exitPromise;exitResult;beforeExitHandler;restoreConsole;unsubscribeResize;throttledOnRender;hasPendingThrottledRender=!1;kittyProtocolEnabled=!1;kittyFlags;isSuspended=!1;pauseInput;resumeInput;cancelKittyDetection;nextRenderCommit;deferredInitDone=!1;constructor(t){this.options=t,this.rootNode=oi("ink-root"),this.rootNode.onComputeLayout=this.calculateLayout,this.isScreenReaderEnabled=t.isScreenReaderEnabled??P.env.INK_SCREEN_READER==="true",this.interactive=this.resolveInteractiveOption(t.interactive),this.alternateScreen=!1;const e=t.debug||this.isScreenReaderEnabled,s=t.maxFps??30,r=s>0?Math.max(1,Math.ceil(1e3/s)):0;this.renderThrottleMs=e?0:r;const n=e?this.onRender:(()=>{const o=ne(this.onRender,r,{leading:!0,trailing:!0});return this.throttledOnRender=o,()=>{this.hasPendingThrottledRender=!0,o()}})();if(e&&(this.throttledOnRender=void 0),t.standardReactLayoutTiming){let o=!1;const a=()=>{o||(o=!0,queueMicrotask(()=>{o=!1,this.onRender()}))};this.rootNode.onRender=a,this.rootNode.onImmediateRender=a}else this.rootNode.onRender=n,this.rootNode.onImmediateRender=this.onRender;this.rootNode.onStaticChange=this.handleStaticChange,this.log=Di.create(t.stdout,{incremental:t.incrementalRendering}),this.useNativeRenderer=t.useNativeRenderer??!1,this.useNativeRenderer&&(this.nativeLog=Wi(t.stdout),this.nativeLog||(this.useNativeRenderer=!1)),this.manualCursorPosition=void 0,this.renderedCursorPosition=void 0,this.renderedCursorRequested=!1,this.throttledLog=e?this.log:ne(o=>{const a=this.log.willRender(o),f=this.shouldSync();f&&a&&this.options.stdout.write(H),this.log(o),f&&a&&this.options.stdout.write(A)},void 0,{leading:!0,trailing:!0}),this.isUnmounted=!1,this.isUnmounting=!1,this.isConcurrent=t.concurrent??!1,this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.lastTerminalWidth=q(this.options.stdout).columns,this.fullStaticOutput="";const l=t.concurrent?Ke:Ye;this.container=k.createContainer(this.rootNode,l,null,!1,null,"id",()=>{},()=>{},()=>{},()=>{}),this.unsubscribeExit=vi(this.unmount,{alwaysLast:!1}),this.setAlternateScreen(!!t.alternateScreen),t.patchConsole&&this.patchConsole(),this.interactive&&(t.stdout.on("resize",this.resized),this.unsubscribeResize=()=>{t.stdout.off("resize",this.resized)}),this.initImmediateKittyKeyboard(),P.env.DEV==="true"&&k.injectIntoDevTools(),this.exitPromise=new Promise((o,a)=>{this.resolveExitPromise=o,this.rejectExitPromise=a}),this.exitPromise.catch(it)}runDeferredInit(){this.deferredInitDone||(this.deferredInitDone=!0,this.initDeferredKittyKeyboard())}resized=()=>{const t=q(this.options.stdout).columns;t<this.lastTerminalWidth&&(this.log.clear(),this.lastOutput="",this.lastOutputToRender=""),ai(),this.calculateLayout(),ni(this.rootNode),this.onRender(),this.lastTerminalWidth=t};resolveExitPromise=()=>{};rejectExitPromise=()=>{};unsubscribeExit=()=>{};handleAppExit=t=>{if(!(this.isUnmounted||this.isUnmounting)){if(Ct(t)){this.unmount(t);return}this.exitResult=t,this.unmount()}};getActiveCursorPosition=()=>this.renderedCursorRequested?this.renderedCursorPosition:this.manualCursorPosition;setCursorPosition=t=>{this.manualCursorPosition=t,this.log.setCursorPosition(this.getActiveCursorPosition())};restoreLastOutput=()=>{this.interactive&&(this.log.setCursorPosition(this.getActiveCursorPosition()),this.log(this.lastOutputToRender||`${this.lastOutput}
14
- `))};calculateLayout=()=>{const t=s=>{const r=new Map;this.calculateScrollAndTriggerObservers(s,r);for(const[n,l]of r)n.internalTrigger(l)};this.backbufferNode=void 0,this.prepareYogaTree(this.rootNode,t);const e=q(this.options.stdout).columns;this.rootNode.yogaNode.setWidth(e),this.rootNode.yogaNode.calculateLayout(void 0,void 0,U.DIRECTION_LTR),t(this.rootNode)};calculateScrollAndTriggerObservers(t,e){if(t.nodeName==="ink-box"){const{style:s}=t,r=s.overflow??"visible",n=s.overflowX??r,l=s.overflowY??r;n==="scroll"||l==="scroll"?(ci(t),s.overflowToBackbuffer&&(this.backbufferNode&&this.backbufferNode!==t&&!this.backbufferMultiWarned&&(this.backbufferMultiWarned=!0,console.warn("[@visulima/tui] Multiple scrollable regions have `overflowToBackbuffer` enabled; only one is supported. The last one in render order wins.")),this.backbufferNode=t)):t.internal_scrollState&&delete t.internal_scrollState}if(di(t,e),!t.internal_static)for(const s of t.childNodes)s.nodeName!=="#text"&&this.calculateScrollAndTriggerObservers(s,e)}recalculateLayout(){this.markAllTextNodesDirty(this.rootNode),this.calculateLayout(),this.onRender()}prepareYogaTree(t,e){if(t.isYogaTreeDetached&&!t.cachedRender&&t.yogaNode){for(t.yogaNode.setWidthAuto(),t.yogaNode.setHeightAuto(),li(t.yogaNode,t.style);t.yogaNode.getChildCount()>0;)t.yogaNode.getChild(0).remove();let s=0;for(const r of t.childNodes){const n=r;r.nodeName!=="#text"&&n.yogaNode&&(t.yogaNode.insertChild(n.yogaNode,s),s++)}t.isYogaTreeDetached=!1,this.markAllTextNodesDirty(t)}for(const s of t.childNodes)s.nodeName!=="#text"&&this.prepareYogaTree(s,e);if(t.nodeName==="ink-static-render"&&!t.cachedRender){const s=q(this.options.stdout).columns,{width:r}=t.style;t.yogaNode&&(t.yogaNode.setWidth(typeof r=="number"?r:s),t.yogaNode.calculateLayout(void 0,void 0,U.DIRECTION_LTR)),e(t),si(t,{skipStaticElements:!1}),t.internal_onRendered?.()}}markAllTextNodesDirty(t){if(!t.cachedRender){t.nodeName==="ink-text"&&t.yogaNode&&t.yogaNode.markDirty();for(const e of t.childNodes)e.nodeName!=="#text"&&this.markAllTextNodesDirty(e)}}handleStaticChange=()=>{this.fullStaticOutput=""};computeBackbufferOutput(){const t=this.backbufferNode;if(!t?.internal_scrollState||!this.interactive||!this.options.stdout.isTTY||this.alternateScreen||this.isScreenReaderEnabled||this.options.debug)return"";const e=Math.round(t.internal_scrollState.scrollTop),s=t.yogaNode?.getComputedPadding(U.EDGE_TOP)??0,r=Math.max(0,e-Math.round(s)),n=t.internal_maxPushedScrollTop??0,{maxScrollbackLength:l}=t.style,o=l===void 0?n:Math.max(n,r-Math.max(0,l)),a=r-o;if(a<=0)return"";const f=Ii(t,o,a);return f===""?"":(t.internal_maxPushedScrollTop=r,`${f}\x1B[0m
15
- `)}onRender=()=>{if(this.hasPendingThrottledRender=!1,this.isUnmounted)return;this.deferredInitDone||this.runDeferredInit(),this.nextRenderCommit&&(this.nextRenderCommit.resolve(),this.nextRenderCommit=void 0);const t=ri(this.rootNode,this.isScreenReaderEnabled,{useNativeRenderer:this.useNativeRenderer}),{cursorPosition:e,cursorRequested:s,cursorShape:r,output:n,outputBuffer:l,outputHeight:o,outputWidth:a,staticOutput:f}=t;this.renderedCursorRequested=s,this.renderedCursorPosition=e,this.log.setCursorShape(s?r:void 0);const h=this.computeBackbufferOutput();if(this.useNativeRenderer&&this.nativeLog&&l&&a){f&&f!==`
16
- `&&this.options.stdout.write(f),h&&this.options.stdout.write(h),this.nativeLog.render(l,a,o),this.lastOutputHeight=o;return}s&&this.log.setCursorPosition(this.getActiveCursorPosition());const m=f&&f!==`
17
- `;if(this.options.debug){m&&(this.fullStaticOutput+=f),this.lastOutput=n,this.lastOutputToRender=n,this.lastOutputHeight=o,this.options.stdout.write(this.fullStaticOutput+n);return}if(!this.interactive){m&&this.options.stdout.write(f),this.lastOutput=n,this.lastOutputToRender=`${n}
18
- `,this.lastOutputHeight=o;return}if(this.isScreenReaderEnabled){const w=this.shouldSync();if(w&&this.options.stdout.write(H),m){const b=this.lastOutputHeight>0?G(this.lastOutputHeight):"";this.options.stdout.write(b+f),this.lastOutputHeight=0}if(n===this.lastOutput&&!m){w&&this.options.stdout.write(A);return}const d=q(this.options.stdout).columns,c=Ge(n,{trim:!1,width:d,wrapMode:"BREAK_WORDS"}).replace(/\n$/,"");if(m)this.options.stdout.write(c);else{const b=this.lastOutputHeight>0?G(this.lastOutputHeight):"";this.options.stdout.write(b+c)}this.lastOutput=n,this.lastOutputToRender=c,this.lastOutputHeight=c===""?0:c.split(`
19
- `).length,w&&this.options.stdout.write(A);return}m&&(this.fullStaticOutput+=f),this.renderInteractiveFrame(n,o,m?f:"",h)};accessibilityContextValue;render(t){this.accessibilityContextValue??={isScreenReaderEnabled:this.isScreenReaderEnabled};const e=_(Fe.Provider,{value:this.accessibilityContextValue,children:_(we,{exitOnCtrlC:this.options.exitOnCtrlC,interactive:this.interactive,onExit:this.handleAppExit,onRegisterInputControl:this.registerInputControl,onSuspendTerminal:this.suspendTerminal,onWaitUntilRenderFlush:this.waitUntilRenderFlush,renderThrottleMs:this.renderThrottleMs,setCursorPosition:this.setCursorPosition,stderr:this.options.stderr,stdin:this.options.stdin,stdout:this.options.stdout,writeToStderr:this.writeToStderr,writeToStdout:this.writeToStdout,children:t})});this.options.concurrent?k.updateContainer(e,this.container,null,it):(k.updateContainerSync(e,this.container,null,it),k.flushSyncWork())}writeToStdout=t=>{if(this.isUnmounted)return;if(this.options.debug){this.options.stdout.write(t+this.fullStaticOutput+this.lastOutput);return}if(!this.interactive){this.options.stdout.write(t);return}const e=this.shouldSync();e&&this.options.stdout.write(H),this.log.clear(),this.options.stdout.write(t),this.restoreLastOutput(),e&&this.options.stdout.write(A)};writeToStderr=t=>{if(this.isUnmounted)return;if(this.options.debug){this.options.stderr.write(t),this.options.stdout.write(this.fullStaticOutput+this.lastOutput);return}if(!this.interactive){this.options.stderr.write(t);return}const e=this.shouldSync();e&&this.options.stdout.write(H),this.log.clear(),this.options.stderr.write(t),this.restoreLastOutput(),e&&this.options.stdout.write(A)};unmount=t=>{if(this.isUnmounted||this.isUnmounting)return;this.isUnmounting=!0,this.beforeExitHandler&&(P.off("beforeExit",this.beforeExitHandler),this.beforeExitHandler=void 0);const e=this.options.stdout,{canWriteToStdout:s,hasWritableState:r}=ae(e);ft(this.throttledOnRender,s),s&&!this.alternateScreen&&(!this.throttledOnRender||!this.hasPendingThrottledRender&&this.fullStaticOutput==="")&&(this.calculateLayout(),this.onRender()),this.isUnmounted=!0,this.unsubscribeExit(),ft(this.throttledLog,s),typeof this.restoreConsole=="function"&&this.restoreConsole();const n=()=>{typeof this.unsubscribeResize=="function"&&this.unsubscribeResize(),this.cancelKittyDetection&&this.cancelKittyDetection(),s&&(this.kittyProtocolEnabled&&this.writeBestEffort(this.options.stdout,"\x1B[<u"),this.alternateScreen?(this.log.clear(),this.log.done(),this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.fullStaticOutput="",this.writeBestEffort(this.options.stdout,Jt),this.writeBestEffort(this.options.stdout,ot),this.alternateScreen=!1):this.interactive?this.options.debug||this.log.done():this.options.stdout.write(this.options.debug?`
20
- `:`${this.lastOutput}
21
- `)),this.kittyProtocolEnabled=!1,Ot.delete(this.options.stdout);const{exitResult:o}=this,a=()=>{Ct(t)?this.rejectExitPromise(t):this.resolveExitPromise(o)};t!==void 0&&!Ct(t)?a():s&&r?this.options.stdout.write("",a):setImmediate(a)},l=k;this.options.concurrent?(k.updateContainerSync(null,this.container,null,it),k.flushSyncWork(),l.flushPassiveEffects?.(),n()):(k.updateContainerSync(null,this.container,null,it),k.flushSyncWork(),n())};async waitUntilExit(){return this.beforeExitHandler||(this.beforeExitHandler=()=>{this.unmount()},P.on("beforeExit",this.beforeExitHandler)),this.exitPromise}async waitUntilRenderFlush(){if(this.isUnmounted||this.isUnmounting){await this.awaitExit();return}if(await ue(),this.isUnmounted||this.isUnmounting){await this.awaitExit();return}if(this.isConcurrent&&this.hasPendingConcurrentWork()&&(await Promise.race([this.awaitNextRender(),this.awaitExit()]),this.isUnmounted||this.isUnmounting)){this.nextRenderCommit=void 0,await this.awaitExit();return}k.flushSyncWork();const t=this.options.stdout,{canWriteToStdout:e,hasWritableState:s}=ae(t);if(ft(this.throttledOnRender,e),ft(this.throttledLog,e),e&&s){await new Promise(r=>{this.options.stdout.write("",()=>{r()})});return}await ue()}clear(){this.interactive&&!this.options.debug&&(this.log.clear(),this.log.sync(this.lastOutputToRender||`${this.lastOutput}
22
- `))}patchConsole(){this.options.debug||(this.restoreConsole=hi((t,e)=>{t==="stdout"&&this.writeToStdout(e),t==="stderr"&&(e.startsWith("The above error occurred")||this.writeToStderr(e))}))}setAlternateScreen(t){this.alternateScreen=this.resolveAlternateScreenOption(t,this.interactive),this.alternateScreen&&(this.writeBestEffort(this.options.stdout,Xt),this.writeBestEffort(this.options.stdout,nt))}resolveInteractiveOption(t){return t??(!fe&&!!this.options.stdout.isTTY)}resolveAlternateScreenOption(t,e){return!!t&&e&&!!this.options.stdout.isTTY}shouldSync(){return Mi(this.options.stdout,this.interactive)}writeBestEffort(t,e){try{t.write(e)}catch{}}async awaitExit(){try{await this.exitPromise}catch{}}hasPendingConcurrentWork(){const t=this.container;return(t.pendingLanes??0)!==0&&t.callbackNode!==void 0&&t.callbackNode!==null}async awaitNextRender(){if(!this.nextRenderCommit){let t;const e=new Promise(s=>{t=s});this.nextRenderCommit={promise:e,resolve:t}}return this.nextRenderCommit.promise}renderInteractiveFrame(t,e,s,r=""){const n=s+r,l=n!=="",o=this.options.stdout.isTTY,a=o?q(this.options.stdout).rows:24,f=o&&e>=a,h=f?t:`${t}
23
- `,m=P.platform==="win32",w=o&&m&&(f||this.lastOutputHeight>=a);if(qi({isTty:o,isUnmounting:this.isUnmounting,isWindows:m,nextOutputHeight:e,previousOutputHeight:this.lastOutputHeight,viewportRows:a})){if(this.options.incrementalRendering&&!w){l&&(this.log.clear(),this.options.stdout.write(n)),(t!==this.lastOutput||this.log.isCursorDirty()||l)&&this.throttledLog(h),this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e;return}const d=this.shouldSync();d&&this.options.stdout.write(H),this.options.stdout.write(He+this.fullStaticOutput+r+t),this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e,this.log.sync(h),d&&this.options.stdout.write(A);return}if(l){const d=this.shouldSync();d&&this.options.stdout.write(H),this.log.clear(),this.options.stdout.write(n),this.log(h),d&&this.options.stdout.write(A)}else(t!==this.lastOutput||this.log.isCursorDirty())&&this.throttledLog(h);this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e}initImmediateKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="enabled")return;const e=t.flags??["disambiguateEscapeCodes"];this.options.stdin.isTTY&&this.options.stdout.isTTY&&this.enableKittyProtocol(e)}initDeferredKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="auto")return;const e=t.flags??["disambiguateEscapeCodes"];!this.interactive||!this.options.stdin.isTTY||!this.options.stdout.isTTY||this.confirmKittySupport(e)}confirmKittySupport(t){const{stdin:e,stdout:s}=this.options;let r=[];const n=()=>{this.cancelKittyDetection=void 0,clearTimeout(o),e.removeListener("data",l);const a=ji(r);r=[],a.length>0&&e.unshift(zt.from(a))},l=a=>{const f=typeof a=="string"?zt.from(a):a;for(const h of f)r.push(h);Fi(r)&&(n(),this.isUnmounted||this.enableKittyProtocol(t))};e.on("data",l);const o=setTimeout(n,200);this.cancelKittyDetection=n,s.write("\x1B[?u")}registerInputControl=(t,e)=>{this.pauseInput=t,this.resumeInput=e};suspendTerminal=(async t=>{if(this.beginSuspend(),t){try{await t()}finally{await this.endSuspend()}return}const e=async()=>{await this.endSuspend()};return{resume:e,[Symbol.asyncDispose]:e}});beginSuspend(){if(this.isSuspended)throw new Error("The terminal is already suspended. Resume the current suspension before suspending again.");if(this.isSuspended=!0,!(!this.interactive||this.isUnmounted||this.isUnmounting))try{this.log.clear(),this.log.done(),this.kittyProtocolEnabled&&this.writeBestEffort(this.options.stdout,"\x1B[<u"),this.alternateScreen&&(this.writeBestEffort(this.options.stdout,Jt),this.writeBestEffort(this.options.stdout,ot)),this.pauseInput?.()}catch(t){this.isSuspended=!1;try{this.resumeInput?.()}catch{}throw t}}async endSuspend(){if(this.isSuspended&&(this.isSuspended=!1,this.resumeInput?.(),!(!this.interactive||this.isUnmounted||this.isUnmounting))){this.alternateScreen&&this.writeBestEffort(this.options.stdout,Xt),this.kittyProtocolEnabled&&this.kittyFlags&&this.writeBestEffort(this.options.stdout,`\x1B[>${Qt(this.kittyFlags)}u`),this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.log.reset();try{this.calculateLayout(),this.onRender(),await this.waitUntilRenderFlush()}catch{}}}enableKittyProtocol(t){this.kittyFlags=t,this.options.stdout.write(`\x1B[>${Qt(t)}u`),this.kittyProtocolEnabled=!0}}const Es=(i,t)=>{const e={alternateScreen:!1,concurrent:!1,debug:!1,exitOnCtrlC:!0,incrementalRendering:!1,maxFps:30,patchConsole:!0,stderr:P.stderr,stdin:P.stdin,stdout:P.stdout,...Vi(t)},s=Xi(e.stdout,()=>new zi(e));return s.render(i),{cleanup(){s.unmount()},clear(){s.clear()},rerender(r){s.render(r)},rootNode:s.rootNode,unmount(){s.unmount()},waitUntilExit(){return s.waitUntilExit()},waitUntilRenderFlush(){return s.waitUntilRenderFlush()}}},Vi=(i={})=>i instanceof Me?{stdin:P.stdin,stdout:i}:i,Xi=(i,t)=>{const e=Ot.get(i);if(e===void 0){const s=t();return Ot.set(i,s),s}return P.stderr.write(`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.
24
- `),e};export{Es as default};
@@ -1 +0,0 @@
1
- import i from"react";import{FocusProvider as y,useFocusManager as W}from"./FocusContext-C2Sosxa4.js";import{TuiContext as I,useInput as z}from"./TuiContext-BNmP0lMY.js";import{LayoutNode as v}from"./LayoutNode-LPYsuzBg.js";import{T as f,s as P}from"./reconciler-ClpU7Y-V.js";import{renderTreeToBuffer as F}from"./renderTreeToBuffer-BpSD0sBJ.js";import{TuiApp as L}from"./TuiApp-CCVaiKbf.js";import{InputParser as T}from"./InputParser-CiBitCva.js";import{terminalSize as G}from"./Renderer-BeS49FNq.js";import{createInlineLoop as M}from"./createInlineLoop-DnEvE2eM.js";const R=n=>i.createElement("box",n,n.children),K=n=>i.createElement("text",n,n.children),Q=()=>i.createElement(R,{flexGrow:1}),b=({children:n})=>{const{disableFocus:c,enableFocus:e,focusNext:a,focusPrevious:o}=W();return z((w,s)=>{s.tab&&!s.shift&&a(),s.tab&&s.shift&&o(),s.escape&&(c(),e())}),i.createElement(i.Fragment,null,n)};function V(n,c){const e=new L,a=new T(process.stdin),o=new v,{height:w,width:s}=e.getSize();o.yogaNode.setWidth(s),o.yogaNode.setHeight(w);const u=f.createContainer(o,0,null,!1,null,"",t=>console.error(t),null),p=t=>i.createElement(I.Provider,{value:{app:e,input:a,writeStderr:l=>e.writeStderr(l),writeStdout:l=>e.writeStdout(l)}},i.createElement(y,null,i.createElement(b,null,t)));f.updateContainer(p(n),u,null,()=>{});const h=(t,l)=>o.calculateLayout(t,l),x=(t,l,H)=>F(o,t,l,H),g=()=>e.paintNow(h,x);let S=!1;P(()=>{S=!0});const d=Math.round(1e3/(c?.maxFps??60)),E=setInterval(()=>{S&&(S=!1,g())},d);let N;const r=new Promise(t=>{N=t}),m=()=>{clearInterval(E),f.updateContainer(null,u,null,()=>{}),o.destroy(),e.stop(),a.stop(),process.off("SIGWINCH",C),N()};a.on("exit",()=>{m(),process.exit(0)}),e.on("quit",()=>{m(),process.exit(0)}),a.start(),e.start();const C=()=>{const t=process.stdout.columns||80,l=process.stdout.rows||24;e.resize(t,l),o.yogaNode.setWidth(t),o.yogaNode.setHeight(l),e.emit("resize"),g()};return process.on("SIGWINCH",C),g(),{app:e,input:a,rerender(t){f.updateContainer(p(t),u,null,()=>{})},unmount(){m()},waitUntilExit(){return r}}}function X(n,c){const e=G(),a=c?.rows??10,{cols:o}=e,w=Math.min(a,e.rows),s=new T(process.stdin),u=new v;u.yogaNode.setWidth(o),u.yogaNode.setHeight(w);const p=[],h=[],x={quit:()=>d.stop(),writeStderr:r=>h.push(r),writeStdout:r=>p.push(r)},g=f.createContainer(u,0,null,!1,null,"",r=>console.error(r),null),S=r=>i.createElement(I.Provider,{value:{app:x,input:s,writeStderr:x.writeStderr,writeStdout:x.writeStdout}},i.createElement(y,null,i.createElement(b,null,r)));f.updateContainer(S(n),g,null,()=>{}),P(()=>{});const d=M((r,m,C)=>{u.calculateLayout(m,C),F(u,r,m,C)},{...c,fps:c?.maxFps??c?.fps??60,rows:w});s.on("exit",()=>d.stop());let E;const N=new Promise(r=>{E=r});return process.on("exit",()=>{p.length>0&&process.stdout.write(p.join("")),h.length>0&&process.stderr.write(h.join("")),E()}),d.start(),s.start(),{unmount(){d.stop()},waitUntilExit(){return N}}}export{R as _Box,Q as _Spacer,K as _Text,V as render,X as renderInline};