@visulima/tui 2.0.0 → 3.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 +13 -0
- package/dist/components/box.d.ts +25 -25
- package/dist/components/canvas.d.ts +26 -31
- package/dist/components/cursor.d.ts +39 -44
- package/dist/components/error-overview.d.ts +1 -3
- package/dist/components/error-overview.js +1 -1
- package/dist/components/newline.d.ts +6 -8
- package/dist/components/spacer.d.ts +4 -4
- package/dist/components/static-render.d.ts +9 -40
- package/dist/components/static.d.ts +13 -13
- package/dist/components/text.d.ts +34 -47
- package/dist/components/transform.d.ts +7 -11
- package/dist/core/index.d.ts +11 -11
- package/dist/core/index.js +1 -1
- package/dist/ink/canvas/index.d.ts +10 -10
- package/dist/ink/hooks/use-animation.d.ts +22 -22
- package/dist/ink/hooks/use-app.d.ts +3 -3
- package/dist/ink/hooks/use-box-metrics.d.ts +16 -16
- package/dist/ink/hooks/use-clipboard.d.ts +16 -16
- package/dist/ink/hooks/use-color-blindness.d.ts +16 -16
- package/dist/ink/hooks/use-console-capture.d.ts +19 -19
- package/dist/ink/hooks/use-cursor.d.ts +6 -6
- package/dist/ink/hooks/use-focus-manager.d.ts +25 -25
- package/dist/ink/hooks/use-focus.d.ts +14 -18
- package/dist/ink/hooks/use-form.d.ts +32 -32
- package/dist/ink/hooks/use-hotkey.d.ts +17 -17
- package/dist/ink/hooks/use-input.d.ts +92 -92
- package/dist/ink/hooks/use-input.js +2 -2
- package/dist/ink/hooks/use-interval.d.ts +14 -14
- package/dist/ink/hooks/use-is-screen-reader-enabled.d.ts +3 -3
- package/dist/ink/hooks/use-key-bindings.d.ts +32 -32
- package/dist/ink/hooks/use-key-chord.d.ts +15 -15
- package/dist/ink/hooks/use-paste.d.ts +38 -38
- package/dist/ink/hooks/use-paste.js +1 -1
- package/dist/ink/hooks/use-persistent-state.d.ts +46 -46
- package/dist/ink/hooks/use-persistent-state.js +2 -2
- package/dist/ink/hooks/use-scroll-acceleration.d.ts +24 -24
- package/dist/ink/hooks/use-scroll-input.d.ts +15 -15
- package/dist/ink/hooks/use-stderr.d.ts +6 -6
- package/dist/ink/hooks/use-stderr.js +1 -1
- package/dist/ink/hooks/use-stdin.d.ts +10 -10
- package/dist/ink/hooks/use-stdin.js +1 -1
- package/dist/ink/hooks/use-stdout.d.ts +6 -6
- package/dist/ink/hooks/use-stdout.js +1 -1
- package/dist/ink/hooks/use-stopwatch.d.ts +12 -12
- package/dist/ink/hooks/use-terminal-palette.d.ts +11 -11
- package/dist/ink/hooks/use-text-buffer.d.ts +2 -2
- package/dist/ink/hooks/use-text-selection.d.ts +18 -18
- package/dist/ink/hooks/use-timeout.d.ts +11 -11
- package/dist/ink/hooks/use-timer.d.ts +19 -19
- package/dist/ink/hooks/use-window-size.d.ts +8 -8
- package/dist/ink/hooks/use-window-size.js +1 -1
- package/dist/ink/index.d.ts +109 -122
- package/dist/ink/index.js +1 -1
- package/dist/ink/mouse/use-element-position.d.ts +6 -6
- package/dist/ink/mouse/use-mouse-action.d.ts +1 -1
- package/dist/ink/mouse/use-mouse-position.d.ts +1 -1
- package/dist/ink/mouse/use-mouse.d.ts +1 -1
- package/dist/ink/mouse/use-on-mouse-click.d.ts +3 -3
- package/dist/ink/mouse/use-on-mouse-hover.d.ts +2 -2
- package/dist/ink/mouse/use-on-mouse-state.d.ts +2 -2
- package/dist/ink/public/cursor.d.ts +21 -21
- package/dist/ink/public/dom.d.ts +2 -2
- package/dist/ink/public/highlighter.d.ts +16 -26
- package/dist/ink/public/input.d.ts +6 -6
- package/dist/ink/public/styles.d.ts +1 -1
- package/dist/ink/public/utils.d.ts +2 -2
- package/dist/packem_shared/{DevTools-D9tfChBc.js → DevTools-CZ-O0Ckm.js} +1 -1
- package/dist/packem_shared/FocusContext-BWFqf9kb.js +1 -0
- package/dist/packem_shared/InputParser-CUAGWKQQ.js +2 -0
- package/dist/packem_shared/MouseProvider-DOcWCRVq.js +1 -0
- package/dist/packem_shared/{Renderer-DsskdkUd.js → Renderer-BeS49FNq.js} +1 -1
- package/dist/packem_shared/{TuiApp-DjIgv5Sk.js → TuiApp-CCVaiKbf.js} +1 -1
- package/dist/packem_shared/app-context.d-DMLw5Nxy.d.ts +56 -0
- package/dist/packem_shared/{buffer.d-j_dP5JyC.d.ts → buffer.d-CttIC480.d.ts} +26 -26
- package/dist/packem_shared/clipboard.d-nDPQkZ2H.d.ts +23 -0
- package/dist/packem_shared/color-matrix.d-sTqnJ23h.d.ts +50 -0
- package/dist/packem_shared/createInlineLoop-BMDYJkRp.js +2 -0
- package/dist/packem_shared/{dom.d-g-nsYquD.d.ts → dom.d-CLGlidfI.d.ts} +138 -151
- package/dist/packem_shared/{input.d-D-Yxqha8.d.ts → input.d-CL_4MfL-.d.ts} +30 -24
- package/dist/packem_shared/load-native-root-binding-CxJnHcac.js +1 -0
- package/dist/packem_shared/{mouse-context.d-BfL9xGk_.d.ts → mouse-context.d-W-nszUps.d.ts} +8 -8
- package/dist/packem_shared/reconciler-D4fi5NfR.js +1 -0
- package/dist/packem_shared/reconciler-DkwOtC5B.js +1 -0
- package/dist/packem_shared/render-CPVY5vpQ.js +1 -0
- package/dist/packem_shared/render-CvhjGwOg.js +24 -0
- package/dist/packem_shared/render.d-DjQhFsiN.d.ts +435 -0
- package/dist/packem_shared/{renderToString-DqLFFPvO.js → renderToString-B1LgWcJe.js} +1 -1
- package/dist/packem_shared/{renderToString-DkTmJPaS.js → renderToString-Df6HST7u.js} +1 -1
- package/dist/packem_shared/{selection.d-KWphH--_.d.ts → selection.d-BSAWa4ey.d.ts} +16 -16
- package/dist/packem_shared/stderr-context-CR2LLec6.js +1 -0
- package/dist/packem_shared/stdin-context-BjMA9Sbi.js +1 -0
- package/dist/packem_shared/stdout-context-DAAlQct2.js +1 -0
- package/dist/packem_shared/styles.d-CKGQFfm4.d.ts +485 -0
- package/dist/packem_shared/{terminal-palette.d-D2SQjfn-.d.ts → terminal-palette.d-JbWHISW-.d.ts} +7 -7
- package/dist/packem_shared/utils-CVgM8kTn.js +1 -0
- package/dist/react/index.d.ts +160 -178
- package/dist/react/index.js +1 -1
- package/dist/testing/index.d.ts +151 -151
- package/dist/testing/index.js +1 -1
- package/index.js +52 -52
- package/package.json +13 -13
- package/dist/packem_shared/FocusContext-C2Sosxa4.js +0 -1
- package/dist/packem_shared/InputParser-CiBitCva.js +0 -2
- package/dist/packem_shared/MouseProvider-DUqQ3Eaa.js +0 -1
- package/dist/packem_shared/app-context.d-CG88lgkg.d.ts +0 -56
- package/dist/packem_shared/clipboard.d-D6lZTQ21.d.ts +0 -23
- package/dist/packem_shared/color-matrix.d-DSXLsB64.d.ts +0 -50
- package/dist/packem_shared/createInlineLoop-BT40Wpmx.js +0 -2
- package/dist/packem_shared/load-native-root-binding-DDikxNox.js +0 -1
- package/dist/packem_shared/reconciler-ClpU7Y-V.js +0 -1
- package/dist/packem_shared/reconciler-DhUGYWCr.js +0 -1
- package/dist/packem_shared/render-D7aV_hO1.js +0 -24
- package/dist/packem_shared/render-DMcWfI6-.js +0 -1
- package/dist/packem_shared/render.d-BvfwvSCx.d.ts +0 -435
- package/dist/packem_shared/stderr-context-Bvnik0hL.js +0 -1
- package/dist/packem_shared/stdin-context-88AhuztD.js +0 -1
- package/dist/packem_shared/stdout-context-BnblEPez.js +0 -1
- package/dist/packem_shared/styles.d-D7iZuNC-.d.ts +0 -492
- package/dist/packem_shared/utils-C8l_3Dzw.js +0 -1
|
@@ -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};
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { D as DOMElement } from "./dom.d-CLGlidfI.js";
|
|
3
|
+
import { T as TerminalSuspension } from "./app-context.d-DMLw5Nxy.js";
|
|
4
|
+
import 'node:stream';
|
|
5
|
+
import { CursorPosition } from "../ink/public/cursor.js";
|
|
6
|
+
declare const kittyFlags: {
|
|
7
|
+
readonly disambiguateEscapeCodes: 1;
|
|
8
|
+
readonly reportAllKeysAsEscapeCodes: 8;
|
|
9
|
+
readonly reportAlternateKeys: 4;
|
|
10
|
+
readonly reportAssociatedText: 16;
|
|
11
|
+
readonly reportEventTypes: 2;
|
|
12
|
+
};
|
|
13
|
+
type KittyFlagName = keyof typeof kittyFlags;
|
|
14
|
+
declare const kittyModifiers: {
|
|
15
|
+
readonly alt: 2;
|
|
16
|
+
readonly capsLock: 64;
|
|
17
|
+
readonly ctrl: 4;
|
|
18
|
+
readonly hyper: 16;
|
|
19
|
+
readonly meta: 32;
|
|
20
|
+
readonly numLock: 128;
|
|
21
|
+
readonly shift: 1;
|
|
22
|
+
readonly super: 8;
|
|
23
|
+
};
|
|
24
|
+
type KittyKeyboardOptions = {
|
|
25
|
+
flags?: KittyFlagName[];
|
|
26
|
+
mode?: "auto" | "enabled" | "disabled";
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Performance metrics for a render operation.
|
|
30
|
+
*/
|
|
31
|
+
type RenderMetrics = {
|
|
32
|
+
/**
|
|
33
|
+
* Time spent rendering in milliseconds.
|
|
34
|
+
*/
|
|
35
|
+
renderTime: number;
|
|
36
|
+
};
|
|
37
|
+
type Options = {
|
|
38
|
+
/**
|
|
39
|
+
* Render the app in the terminal's alternate screen buffer. When enabled, the app renders on a separate screen, and the original terminal content is restored when the app exits. This is the same mechanism used by programs like vim, htop, and less.
|
|
40
|
+
*
|
|
41
|
+
* Note: The terminal's scrollback buffer is not available while in the alternate screen. This is standard terminal behavior; programs like vim use the alternate screen specifically to avoid polluting the user's scrollback history.
|
|
42
|
+
*
|
|
43
|
+
* Note: Ink intentionally treats alternate-screen teardown output as disposable. It does not preserve or replay teardown-time frames, hook writes, or `console.*` output after restoring the primary screen.
|
|
44
|
+
*
|
|
45
|
+
Only works in interactive mode. Ignored when `interactive` is `false` or in a non-interactive environment (CI, piped stdout).
|
|
46
|
+
|
|
47
|
+
Note: Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change this option or create a fresh instance.
|
|
48
|
+
|
|
49
|
+
@default false
|
|
50
|
+
|
|
51
|
+
@see {@link RenderOptions.alternateScreen}
|
|
52
|
+
*/
|
|
53
|
+
alternateScreen?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Enable React Concurrent Rendering mode.
|
|
56
|
+
*
|
|
57
|
+
* When enabled:
|
|
58
|
+
* - Suspense boundaries work correctly with async data
|
|
59
|
+
* - `useTransition` and `useDeferredValue` are fully functional
|
|
60
|
+
- Updates can be interrupted for higher priority work
|
|
61
|
+
|
|
62
|
+
Note: Concurrent mode changes the timing of renders. Some tests may need to use `act()` to properly await updates. Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change the rendering mode or create a fresh instance.
|
|
63
|
+
|
|
64
|
+
@default false
|
|
65
|
+
@experimental
|
|
66
|
+
*/
|
|
67
|
+
concurrent?: boolean;
|
|
68
|
+
debug: boolean;
|
|
69
|
+
exitOnCtrlC: boolean;
|
|
70
|
+
incrementalRendering?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Override automatic interactive mode detection.
|
|
73
|
+
*
|
|
74
|
+
* By default, Ink detects whether the environment is interactive based on CI detection (via [`is-in-ci`](https://github.com/sindresorhus/is-in-ci)) and `stdout.isTTY`. Most users should not need to set this.
|
|
75
|
+
*
|
|
76
|
+
* When non-interactive, Ink disables ANSI erase sequences, cursor manipulation, synchronized output, resize handling, and kitty keyboard auto-detection, writing only the final frame at unmount.
|
|
77
|
+
*
|
|
78
|
+
Set to `false` to force non-interactive mode or `true` to force interactive mode when the automatic detection doesn't suit your use case.
|
|
79
|
+
|
|
80
|
+
Note: Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change this option or create a fresh instance.
|
|
81
|
+
|
|
82
|
+
@default true (false if in CI or `stdout.isTTY` is falsy)
|
|
83
|
+
|
|
84
|
+
@see {@link RenderOptions.interactive}
|
|
85
|
+
*/
|
|
86
|
+
interactive?: boolean;
|
|
87
|
+
isScreenReaderEnabled?: boolean;
|
|
88
|
+
kittyKeyboard?: KittyKeyboardOptions;
|
|
89
|
+
maxFps?: number;
|
|
90
|
+
onRender?: (metrics: RenderMetrics) => void;
|
|
91
|
+
patchConsole: boolean;
|
|
92
|
+
standardReactLayoutTiming?: boolean;
|
|
93
|
+
stderr: NodeJS.WriteStream;
|
|
94
|
+
stdin: NodeJS.ReadStream;
|
|
95
|
+
stdout: NodeJS.WriteStream;
|
|
96
|
+
/**
|
|
97
|
+
* Whether to track text selection state during rendering.
|
|
98
|
+
*
|
|
99
|
+
* @default false
|
|
100
|
+
*/
|
|
101
|
+
trackSelection?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Use the native Rust cell-diff renderer instead of ANSI string-based log-update.
|
|
104
|
+
* Produces a Uint32Array buffer that the Rust renderer diffs cell-by-cell,
|
|
105
|
+
* generating minimal ANSI escape sequences. Significantly reduces GC pressure
|
|
106
|
+
* and improves rendering performance for complex UIs.
|
|
107
|
+
*
|
|
108
|
+
* Falls back to the string-based path if native bindings are not available.
|
|
109
|
+
* @default false
|
|
110
|
+
*/
|
|
111
|
+
useNativeRenderer?: boolean;
|
|
112
|
+
waitUntilExit?: () => Promise<unknown>;
|
|
113
|
+
};
|
|
114
|
+
declare class Ink {
|
|
115
|
+
/**
|
|
116
|
+
* Whether this instance is using concurrent rendering mode.
|
|
117
|
+
*/
|
|
118
|
+
readonly isConcurrent: boolean;
|
|
119
|
+
private readonly options;
|
|
120
|
+
private readonly log;
|
|
121
|
+
private manualCursorPosition;
|
|
122
|
+
private renderedCursorPosition;
|
|
123
|
+
private renderedCursorRequested;
|
|
124
|
+
private readonly throttledLog;
|
|
125
|
+
private readonly isScreenReaderEnabled;
|
|
126
|
+
private readonly interactive;
|
|
127
|
+
private readonly renderThrottleMs;
|
|
128
|
+
private alternateScreen;
|
|
129
|
+
private isUnmounted;
|
|
130
|
+
private isUnmounting;
|
|
131
|
+
private lastOutput;
|
|
132
|
+
private lastOutputToRender;
|
|
133
|
+
private lastOutputHeight;
|
|
134
|
+
private lastTerminalWidth;
|
|
135
|
+
private readonly nativeLog;
|
|
136
|
+
private readonly useNativeRenderer;
|
|
137
|
+
private readonly container;
|
|
138
|
+
readonly rootNode: DOMElement;
|
|
139
|
+
private fullStaticOutput;
|
|
140
|
+
private backbufferNode;
|
|
141
|
+
private backbufferMultiWarned;
|
|
142
|
+
private readonly exitPromise;
|
|
143
|
+
private exitResult;
|
|
144
|
+
private beforeExitHandler?;
|
|
145
|
+
private restoreConsole?;
|
|
146
|
+
private unsubscribeResize?;
|
|
147
|
+
private readonly throttledOnRender?;
|
|
148
|
+
private hasPendingThrottledRender;
|
|
149
|
+
private kittyProtocolEnabled;
|
|
150
|
+
private kittyFlags?;
|
|
151
|
+
private isSuspended;
|
|
152
|
+
private pauseInput?;
|
|
153
|
+
private resumeInput?;
|
|
154
|
+
private cancelKittyDetection?;
|
|
155
|
+
private nextRenderCommit?;
|
|
156
|
+
private deferredInitDone;
|
|
157
|
+
constructor(options: Options);
|
|
158
|
+
/**
|
|
159
|
+
* Perform deferred initialization on the first render frame.
|
|
160
|
+
* Kitty keyboard auto-detection is deferred here because the CSI ? u
|
|
161
|
+
* query sets up a synchronous stdin listener with a 200ms timeout.
|
|
162
|
+
* "enabled" mode runs immediately in the constructor (it's just a write).
|
|
163
|
+
*/
|
|
164
|
+
private runDeferredInit;
|
|
165
|
+
resized: () => void;
|
|
166
|
+
resolveExitPromise: (result?: unknown) => void;
|
|
167
|
+
rejectExitPromise: (reason?: Error) => void;
|
|
168
|
+
unsubscribeExit: () => void;
|
|
169
|
+
handleAppExit: (errorOrResult?: unknown) => void;
|
|
170
|
+
getActiveCursorPosition: () => CursorPosition | undefined;
|
|
171
|
+
setCursorPosition: (position: CursorPosition | undefined) => void;
|
|
172
|
+
restoreLastOutput: () => void;
|
|
173
|
+
calculateLayout: () => void;
|
|
174
|
+
private calculateScrollAndTriggerObservers;
|
|
175
|
+
/**
|
|
176
|
+
* Force a full layout recalculation by marking all text nodes dirty.
|
|
177
|
+
* Useful when the string width function changes or terminal font changes.
|
|
178
|
+
*/
|
|
179
|
+
recalculateLayout(): void;
|
|
180
|
+
/**
|
|
181
|
+
* Walks the DOM tree before Yoga layout to handle StaticRender nodes.
|
|
182
|
+
*
|
|
183
|
+
* - Re-attach Yoga children if a cached render was invalidated.
|
|
184
|
+
* - Pre-render ink-static-render nodes that don't have a cached render yet.
|
|
185
|
+
*/
|
|
186
|
+
private prepareYogaTree;
|
|
187
|
+
private markAllTextNodesDirty;
|
|
188
|
+
handleStaticChange: () => void;
|
|
189
|
+
/**
|
|
190
|
+
* Compute the slice of lines that newly scrolled off the top of the single
|
|
191
|
+
* `overflowToBackbuffer` region and have not yet been flushed into the
|
|
192
|
+
* terminal's real scrollback. Advances the monotonic
|
|
193
|
+
* `internal_maxPushedScrollTop` bookkeeping so each line is emitted exactly
|
|
194
|
+
* once and scrolling back up is a no-op. Returns a newline-terminated
|
|
195
|
+
* string to write above the live frame, or "" when there is nothing to do.
|
|
196
|
+
*
|
|
197
|
+
* No-op outside inline mode (alternate-screen / non-TTY / non-interactive /
|
|
198
|
+
* screen-reader / debug), since terminal scrollback only exists for an
|
|
199
|
+
* inline, in-place-updated live region. Debug mode is excluded because it
|
|
200
|
+
* re-dumps the full grid every frame and never writes this slice — running
|
|
201
|
+
* it there would advance the monotonic pointer past lines that were never
|
|
202
|
+
* emitted.
|
|
203
|
+
*/
|
|
204
|
+
private computeBackbufferOutput;
|
|
205
|
+
onRender: () => void;
|
|
206
|
+
private accessibilityContextValue;
|
|
207
|
+
render(node: ReactNode): void;
|
|
208
|
+
writeToStdout: (data: string) => void;
|
|
209
|
+
writeToStderr: (data: string) => void;
|
|
210
|
+
unmount: (error?: Error | number | null) => void;
|
|
211
|
+
waitUntilExit(): Promise<unknown>;
|
|
212
|
+
waitUntilRenderFlush(): Promise<void>;
|
|
213
|
+
clear(): void;
|
|
214
|
+
patchConsole(): void;
|
|
215
|
+
private setAlternateScreen;
|
|
216
|
+
private resolveInteractiveOption;
|
|
217
|
+
private resolveAlternateScreenOption;
|
|
218
|
+
private shouldSync;
|
|
219
|
+
private writeBestEffort;
|
|
220
|
+
private awaitExit;
|
|
221
|
+
private hasPendingConcurrentWork;
|
|
222
|
+
private awaitNextRender;
|
|
223
|
+
private renderInteractiveFrame;
|
|
224
|
+
/**
|
|
225
|
+
* Handle kitty keyboard "enabled" mode immediately (just a stdout.write).
|
|
226
|
+
* Called from the constructor.
|
|
227
|
+
*/
|
|
228
|
+
private initImmediateKittyKeyboard;
|
|
229
|
+
/**
|
|
230
|
+
* Handle kitty keyboard "auto" mode detection. Deferred to first render
|
|
231
|
+
* because the CSI ? u query sets up a stdin listener with a 200ms timeout.
|
|
232
|
+
*/
|
|
233
|
+
private initDeferredKittyKeyboard;
|
|
234
|
+
private confirmKittySupport;
|
|
235
|
+
registerInputControl: (pauseInput: () => void, resumeInput: () => void) => void;
|
|
236
|
+
/**
|
|
237
|
+
* Hand terminal control to a child process, then restore Ink's rendering.
|
|
238
|
+
* With a callback, the terminal is released for its duration and resumed in a
|
|
239
|
+
* `finally`. Without one, returns a handle whose `resume()` (or `await using`)
|
|
240
|
+
* restores.
|
|
241
|
+
*/
|
|
242
|
+
suspendTerminal: {
|
|
243
|
+
(callback: () => Promise<void> | void): Promise<undefined>;
|
|
244
|
+
(): Promise<TerminalSuspension>;
|
|
245
|
+
};
|
|
246
|
+
private beginSuspend;
|
|
247
|
+
private endSuspend;
|
|
248
|
+
private enableKittyProtocol;
|
|
249
|
+
}
|
|
250
|
+
type RenderOptions = {
|
|
251
|
+
/**
|
|
252
|
+
* Render the app in the terminal's alternate screen buffer. When enabled, the app renders on a separate screen, and the original terminal content is restored when the app exits. This is the same mechanism used by programs like vim, htop, and less.
|
|
253
|
+
*
|
|
254
|
+
* Note: The terminal's scrollback buffer is not available while in the alternate screen. This is standard terminal behavior; programs like vim use the alternate screen specifically to avoid polluting the user's scrollback history.
|
|
255
|
+
*
|
|
256
|
+
* Note: Ink intentionally treats alternate-screen teardown output as disposable. It does not preserve or replay teardown-time frames, hook writes, or `console.*` output after restoring the primary screen.
|
|
257
|
+
*
|
|
258
|
+
* Only works in interactive mode. Ignored when `interactive` is `false` or in a non-interactive environment (CI, piped stdout).
|
|
259
|
+
*
|
|
260
|
+
*Note: Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change this option or create a fresh instance.
|
|
261
|
+
* @default false
|
|
262
|
+
*/
|
|
263
|
+
alternateScreen?: boolean;
|
|
264
|
+
/**
|
|
265
|
+
* Enable React Concurrent Rendering mode.
|
|
266
|
+
*
|
|
267
|
+
* When enabled:
|
|
268
|
+
* - Suspense boundaries work correctly with async data
|
|
269
|
+
* - `useTransition` and `useDeferredValue` are fully functional
|
|
270
|
+
* - Updates can be interrupted for higher priority work
|
|
271
|
+
*
|
|
272
|
+
*Note: Concurrent mode changes the timing of renders. Some tests may need to use `act()` to properly await updates. Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change the rendering mode or create a fresh instance.
|
|
273
|
+
* @default false
|
|
274
|
+
*/
|
|
275
|
+
concurrent?: boolean;
|
|
276
|
+
/**
|
|
277
|
+
* If true, each update will be rendered as separate output, without replacing the previous one.
|
|
278
|
+
* @default false
|
|
279
|
+
*/
|
|
280
|
+
debug?: boolean;
|
|
281
|
+
/**
|
|
282
|
+
* Configure whether Ink should listen for Ctrl+C keyboard input and exit the app. This is needed in case `process.stdin` is in raw mode, because then Ctrl+C is ignored by default and the process is expected to handle it manually.
|
|
283
|
+
* @default true
|
|
284
|
+
*/
|
|
285
|
+
exitOnCtrlC?: boolean;
|
|
286
|
+
/**
|
|
287
|
+
* Enable incremental rendering mode which only updates changed lines instead of redrawing the entire output.
|
|
288
|
+
*This can reduce flickering and improve performance for frequently updating UIs.
|
|
289
|
+
* @default false
|
|
290
|
+
*/
|
|
291
|
+
incrementalRendering?: boolean;
|
|
292
|
+
/**
|
|
293
|
+
* Override automatic interactive mode detection.
|
|
294
|
+
*
|
|
295
|
+
* By default, Ink detects whether the environment is interactive based on CI detection (via [`is-in-ci`](https://github.com/sindresorhus/is-in-ci)) and `stdout.isTTY`. Most users should not need to set this.
|
|
296
|
+
*
|
|
297
|
+
* When non-interactive, Ink disables ANSI erase sequences, cursor manipulation, synchronized output, resize handling, and kitty keyboard auto-detection, writing only the final frame at unmount.
|
|
298
|
+
*
|
|
299
|
+
* Set to `false` to force non-interactive mode or `true` to force interactive mode when the automatic detection doesn't suit your use case.
|
|
300
|
+
*
|
|
301
|
+
*Note: Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change this option or create a fresh instance.
|
|
302
|
+
* @default true (false if in CI or `stdout.isTTY` is falsy)
|
|
303
|
+
*/
|
|
304
|
+
interactive?: boolean;
|
|
305
|
+
/**
|
|
306
|
+
* Enable screen reader support. See https://github.com/vadimdemedes/ink/blob/master/readme.md#screen-reader-support
|
|
307
|
+
* @default process.env['INK_SCREEN_READER'] === 'true'
|
|
308
|
+
*/
|
|
309
|
+
isScreenReaderEnabled?: boolean;
|
|
310
|
+
/**
|
|
311
|
+
* Configure kitty keyboard protocol support for enhanced keyboard input.
|
|
312
|
+
* Enables additional modifiers (super, hyper, capsLock, numLock) and
|
|
313
|
+
*disambiguated key events in terminals that support the protocol.
|
|
314
|
+
* @see https://sw.kovidgoyal.net/kitty/keyboard-protocol/
|
|
315
|
+
*/
|
|
316
|
+
kittyKeyboard?: KittyKeyboardOptions;
|
|
317
|
+
/**
|
|
318
|
+
* Maximum frames per second for render updates.
|
|
319
|
+
* This controls how frequently the UI can update to prevent excessive re-rendering.
|
|
320
|
+
*Higher values allow more frequent updates but may impact performance.
|
|
321
|
+
* @default 30
|
|
322
|
+
*/
|
|
323
|
+
maxFps?: number;
|
|
324
|
+
/**
|
|
325
|
+
* Runs the given callback after each render and re-render with render metrics.
|
|
326
|
+
*
|
|
327
|
+
* Note: this callback runs after Ink commits a frame, but it does not wait for `stdout`/`stderr` stream callbacks.
|
|
328
|
+
* To run code after output is flushed, use `waitUntilRenderFlush()`.
|
|
329
|
+
*/
|
|
330
|
+
onRender?: (metrics: RenderMetrics) => void;
|
|
331
|
+
/**
|
|
332
|
+
* Patch console methods to ensure console output doesn't mix with Ink's output.
|
|
333
|
+
*
|
|
334
|
+
*Note: Once unmount starts, Ink restores the native console before React cleanup runs. Teardown-time `console.*` output then follows the normal console behavior instead of being rerouted through Ink.
|
|
335
|
+
* @default true
|
|
336
|
+
*/
|
|
337
|
+
patchConsole?: boolean;
|
|
338
|
+
/**
|
|
339
|
+
* If true, Ink defers frame output until after React's commit phase completes,
|
|
340
|
+
* ensuring `useLayoutEffect` hooks run before the frame is written to the terminal.
|
|
341
|
+
*
|
|
342
|
+
* This eliminates the one-frame flicker when components measure layout
|
|
343
|
+
* (e.g., scroll position, element size) in `useLayoutEffect` and adjust state.
|
|
344
|
+
*
|
|
345
|
+
* **Warning:** Incompatible with the `<Static>` component, which relies on
|
|
346
|
+
* immediate render timing to append output.
|
|
347
|
+
* @default false
|
|
348
|
+
*/
|
|
349
|
+
standardReactLayoutTiming?: boolean;
|
|
350
|
+
/**
|
|
351
|
+
* Error stream.
|
|
352
|
+
* @default process.stderr
|
|
353
|
+
*/
|
|
354
|
+
stderr?: NodeJS.WriteStream;
|
|
355
|
+
/**
|
|
356
|
+
* Input stream where app will listen for input.
|
|
357
|
+
* @default process.stdin
|
|
358
|
+
*/
|
|
359
|
+
stdin?: NodeJS.ReadStream;
|
|
360
|
+
/**
|
|
361
|
+
* Output stream where the app will be rendered.
|
|
362
|
+
* @default process.stdout
|
|
363
|
+
*/
|
|
364
|
+
stdout?: NodeJS.WriteStream;
|
|
365
|
+
/**
|
|
366
|
+
* Use the native Rust cell-diff renderer for terminal output.
|
|
367
|
+
* Produces a Uint32Array buffer that the Rust renderer diffs cell-by-cell,
|
|
368
|
+
* generating minimal ANSI escape sequences. Reduces GC pressure and
|
|
369
|
+
* improves rendering performance for complex UIs.
|
|
370
|
+
*
|
|
371
|
+
* Falls back to string-based rendering if native bindings are not available.
|
|
372
|
+
* @default false
|
|
373
|
+
*/
|
|
374
|
+
useNativeRenderer?: boolean;
|
|
375
|
+
};
|
|
376
|
+
type Instance = {
|
|
377
|
+
/**
|
|
378
|
+
* Unmount the current app and remove the internal Ink instance for this stdout.
|
|
379
|
+
*
|
|
380
|
+
* This is mostly useful for advanced cases where you need `render()` to create a fresh instance for the same stream without leaving terminal state such as the alternate screen behind.
|
|
381
|
+
*/
|
|
382
|
+
cleanup: () => void;
|
|
383
|
+
/**
|
|
384
|
+
* Clear output.
|
|
385
|
+
*/
|
|
386
|
+
clear: () => void;
|
|
387
|
+
/**
|
|
388
|
+
* Replace the previous root node with a new one or update props of the current root node.
|
|
389
|
+
*/
|
|
390
|
+
rerender: Ink["render"];
|
|
391
|
+
/**
|
|
392
|
+
* The root DOM element of the rendered tree.
|
|
393
|
+
* Useful for programmatic DOM inspection and advanced measurement.
|
|
394
|
+
*/
|
|
395
|
+
rootNode: DOMElement;
|
|
396
|
+
/**
|
|
397
|
+
* Manually unmount the whole Ink app.
|
|
398
|
+
*/
|
|
399
|
+
unmount: Ink["unmount"];
|
|
400
|
+
/**
|
|
401
|
+
* Returns a promise that settles when the app is unmounted.
|
|
402
|
+
*
|
|
403
|
+
* It resolves with the value passed to `exit(value)` and rejects with the error passed to `exit(error)`.
|
|
404
|
+
*When `unmount()` is called manually, it settles after unmount-related stdout writes complete.
|
|
405
|
+
* @example
|
|
406
|
+
* ```jsx
|
|
407
|
+
* const {unmount, waitUntilExit} = render(<MyApp />);
|
|
408
|
+
*
|
|
409
|
+
* setTimeout(unmount, 1000);
|
|
410
|
+
*
|
|
411
|
+
* await waitUntilExit(); // resolves after `unmount()` is called
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
waitUntilExit: Ink["waitUntilExit"];
|
|
415
|
+
/**
|
|
416
|
+
* Returns a promise that settles after pending render output is flushed to stdout.
|
|
417
|
+
*
|
|
418
|
+
*This can be used after `rerender()` when you need to run code only after the frame is written.
|
|
419
|
+
* @example
|
|
420
|
+
* ```jsx
|
|
421
|
+
* const {rerender, waitUntilRenderFlush} = render(<MyApp step="loading" />);
|
|
422
|
+
*
|
|
423
|
+
* rerender(<MyApp step="ready" />);
|
|
424
|
+
* await waitUntilRenderFlush(); // output for "ready" is flushed
|
|
425
|
+
*
|
|
426
|
+
* runNextCommand();
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
waitUntilRenderFlush: Ink["waitUntilRenderFlush"];
|
|
430
|
+
};
|
|
431
|
+
/**
|
|
432
|
+
* Mount a component and render the output.
|
|
433
|
+
*/
|
|
434
|
+
declare const render: (node: ReactNode, options?: NodeJS.WriteStream | RenderOptions) => Instance;
|
|
435
|
+
export { Instance as I, KittyFlagName as K, RenderOptions as R, KittyKeyboardOptions as a, kittyModifiers as b, kittyFlags as k, render as r };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{LegacyRoot as p}from"react-reconciler/constants.js";import N from"yoga-layout";import{c as g}from"./dom-rphpG0kf.js";import{j as l}from"./reconciler-
|
|
1
|
+
import{LegacyRoot as p}from"react-reconciler/constants.js";import N from"yoga-layout";import{c as g}from"./dom-rphpG0kf.js";import{j as l}from"./reconciler-DkwOtC5B.js";import{H as i}from"./renderer-Cs0KEr1o.js";import{calculateScroll as v}from"./calculateScroll-D4Y_JR4H.js";const L=(f,u)=>{const d=u?.columns??80,e=g("ink-root");let a="";e.onComputeLayout=()=>{e.yogaNode.setWidth(d),e.yogaNode.calculateLayout(void 0,void 0,N.DIRECTION_LTR);const o=t=>{if(t.nodeName==="ink-box"){const n=t.style.overflow??"visible",m=t.style.overflowX??n,y=t.style.overflowY??n;(m==="scroll"||y==="scroll")&&v(t)}for(const n of t.childNodes)n.nodeName!=="#text"&&o(n)};o(e)},e.onImmediateRender=()=>{const{staticOutput:o}=i(e,!1);o&&o!==`
|
|
2
2
|
`&&(a+=o)};let r;const c=l.createContainer(e,p,null,!1,null,"render-to-string",o=>{r??=o},()=>{},()=>{},()=>{});let s=!1;try{l.updateContainerSync(f,c,null,()=>{}),l.flushSyncWork();const{output:o}=i(e,!1);if(l.updateContainerSync(null,c,null,()=>{}),l.flushSyncWork(),s=!0,e.yogaNode.free(),r!==void 0)throw r instanceof Error?r:new Error(String(r));const t=a.endsWith(`
|
|
3
3
|
`)?a.slice(0,-1):a;return t&&o?`${t}
|
|
4
4
|
${o}`:t||o}finally{if(!s&&e.yogaNode)try{e.yogaNode.freeRecursive()}catch{}}};export{L as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import s from"react";import{FocusProvider as S}from"./FocusContext-
|
|
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,13 +1,13 @@
|
|
|
1
|
-
import { b as DOMNode, e as StyledLine } from "./dom.d-
|
|
1
|
+
import { b as DOMNode, e as StyledLine } from "./dom.d-CLGlidfI.js";
|
|
2
2
|
/**
|
|
3
|
-
* Compare the document position of two points in the DOM tree.
|
|
4
|
-
* Returns -1 if A is before B, 0 if equal, 1 if A is after B.
|
|
5
|
-
*/
|
|
3
|
+
* Compare the document position of two points in the DOM tree.
|
|
4
|
+
* Returns -1 if A is before B, 0 if equal, 1 if A is after B.
|
|
5
|
+
*/
|
|
6
6
|
declare const comparePoints: (nodeA: DOMNode, offsetA: number, nodeB: DOMNode, offsetB: number) => number;
|
|
7
7
|
/**
|
|
8
|
-
* A Range represents a contiguous portion of the DOM tree.
|
|
9
|
-
* Modeled after the browser's Range API.
|
|
10
|
-
*/
|
|
8
|
+
* A Range represents a contiguous portion of the DOM tree.
|
|
9
|
+
* Modeled after the browser's Range API.
|
|
10
|
+
*/
|
|
11
11
|
declare class Range {
|
|
12
12
|
startContainer: DOMNode | undefined;
|
|
13
13
|
startOffset: number;
|
|
@@ -25,9 +25,9 @@ declare class Range {
|
|
|
25
25
|
private updateCommonAncestor;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Manages multiple Range objects and provides high-level selection operations.
|
|
29
|
-
* Modeled after the browser's Selection API.
|
|
30
|
-
*/
|
|
28
|
+
* Manages multiple Range objects and provides high-level selection operations.
|
|
29
|
+
* Modeled after the browser's Selection API.
|
|
30
|
+
*/
|
|
31
31
|
declare class Selection {
|
|
32
32
|
anchorNode: DOMNode | undefined;
|
|
33
33
|
anchorOffset: number;
|
|
@@ -49,12 +49,12 @@ declare class Selection {
|
|
|
49
49
|
private notifyChange;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
* Apply selection highlighting to a range of characters in a StyledLine.
|
|
53
|
-
*
|
|
54
|
-
* Characters whose index falls within [start, end) of the selection range
|
|
55
|
-
* get the INVERSE style flag applied. Returns a new StyledLine with the
|
|
56
|
-
* selection highlighting — the original is not mutated.
|
|
57
|
-
*/
|
|
52
|
+
* Apply selection highlighting to a range of characters in a StyledLine.
|
|
53
|
+
*
|
|
54
|
+
* Characters whose index falls within [start, end) of the selection range
|
|
55
|
+
* get the INVERSE style flag applied. Returns a new StyledLine with the
|
|
56
|
+
* selection highlighting — the original is not mutated.
|
|
57
|
+
*/
|
|
58
58
|
declare const applySelectionToStyledLine: (line: StyledLine, range: {
|
|
59
59
|
end: number;
|
|
60
60
|
start: number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as c}from"node:module";import{createContext as t}from"react";const e=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,r=e,s=t({stderr:r.stderr,write(){}});s.displayName="InternalStderrContext";export{s as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as s}from"node:module";import{createContext as l}from"react";let o;const i=t=>(o??=s(import.meta.url))(t),e=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,c=t=>{if(typeof e<"u"&&e.versions&&e.versions.node){const[n,r]=e.versions.node.split(".").map(Number);if(n>22||n===22&&r>=3||n===20&&r>=16)return e.getBuiltinModule(t)}return i(t)},{EventEmitter:a}=c("node:events"),d=e,u=l({internal_eventEmitter:new a,internal_exitOnCtrlC:!0,isRawModeSupported:!1,setBracketedPasteMode(){},setRawMode(){},stdin:d.stdin});u.displayName="InternalStdinContext";export{u as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as c}from"node:module";import{createContext as o}from"react";const e=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,t=e,r=o({stdout:t.stdout,write(){}});r.displayName="InternalStdoutContext";export{r as t};
|