@visulima/tui 4.0.1 → 4.0.3

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,12 @@
1
+ ## @visulima/tui [4.0.3](https://github.com/visulima/visulima/compare/%40visulima%2Ftui%404.0.2...%40visulima%2Ftui%404.0.3) (2026-08-19)
2
+
3
+ ## @visulima/tui [4.0.2](https://github.com/visulima/visulima/compare/%40visulima%2Ftui%404.0.1...%40visulima%2Ftui%404.0.2) (2026-08-18)
4
+
5
+
6
+ ### Dependencies
7
+
8
+ * **@visulima/ansi:** upgraded to 4.2.0
9
+
1
10
  ## @visulima/tui [4.0.1](https://github.com/visulima/visulima/compare/%40visulima%2Ftui%404.0.0...%40visulima%2Ftui%404.0.1) (2026-08-17)
2
11
 
3
12
  ## @visulima/tui [4.0.0](https://github.com/visulima/visulima/compare/%40visulima%2Ftui%403.0.0...%40visulima%2Ftui%404.0.0) (2026-08-08)
@@ -1,4 +1,4 @@
1
- import { T as TerminalPalette } from "../../packem_shared/terminal-palette.d-JbWHISW-.js";
1
+ import { T as TerminalPalette } from "../../packem_shared/terminal-palette.d-DSgSpnMs.js";
2
2
  import 'node:stream';
3
3
  type UseTerminalPaletteResult = {
4
4
  readonly isLoading: boolean;
@@ -1 +1 @@
1
- import{useState as a,useMemo as f,useEffect as c}from"react";import{isTerminalPaletteQuerySupported as m,queryTerminalPalette as d}from"../../packem_shared/isTerminalPaletteQuerySupported-DwJPJ8_h.js";import{useStdinContext as p}from"./use-stdin.js";import y from"./use-stdout.js";const x=()=>{const{stdin:t}=p(),{stdout:e}=y(),[n,i]=a(null),[l,o]=a(!0),s=f(()=>m(),[]);return c(()=>{if(!s||!t||!e){o(!1);return}let r=!1;return(async()=>{try{const u=await d(t,e,200);r||i(u)}catch{}finally{r||o(!1)}})(),()=>{r=!0}},[s,t,e]),{isLoading:l,isSupported:s,palette:n}};export{x as default,x as useTerminalPalette};
1
+ import{useState as n,useMemo as c,useEffect as f}from"react";import{isTerminalPaletteQuerySupported as d,queryTerminalPalette as m}from"../../packem_shared/isTerminalPaletteQuerySupported-X6YXYjSp.js";import{useStdinContext as p}from"./use-stdin.js";import g from"./use-stdout.js";const T=()=>{const{stdin:e}=p(),{stdout:o}=g(),[a,i]=n(null),[l,s]=n(!0),r=c(()=>d(),[]);return f(()=>{if(!r||!e||!o){s(!1);return}const t=new AbortController;return(async()=>{try{const u=await m(e,o,200,t.signal);t.signal.aborted||i(u)}catch{}finally{t.signal.aborted||s(!1)}})(),()=>{t.abort()}},[r,e,o]),{isLoading:l,isSupported:r,palette:a}};export{T as default,T as useTerminalPalette};
@@ -11,10 +11,10 @@ type C as ClipboardTarget, c as clearOsc52, i as isOsc52Supported, w as writeOsc
11
11
  export { b as COLOR_BLINDNESS_COMPENSATION, c as COLOR_BLINDNESS_SIMULATION, type C as ColorBlindnessType, type a as ColorMatrix, I as IDENTITY_MATRIX, d as applyColorMatrix, h as hexToRgb, r as rgbToHex, t as transformHexColor } from "../packem_shared/color-matrix.d-sTqnJ23h.js";
12
12
  import { D as DOMElement, a as DOMNode, S as StyledLine } from "../packem_shared/dom.d-BV2bnRcH.js";
13
13
  export { R as ResizeObserver, type b as ResizeObserverCallback, c as ResizeObserverEntry, type d as ScrollState, type e as StickyHeader, f as calculateScroll, g as getPathToRoot, h as getScrollHeight, i as getScrollLeft, j as getScrollTop, k as getScrollWidth, l as isNodeSelectable } from "../packem_shared/dom.d-BV2bnRcH.js";
14
- export { type I as Instance, type K as KittyFlagName, type a as KittyKeyboardOptions, type R as RenderOptions, k as kittyFlags, b as kittyModifiers, r as render } from "../packem_shared/render.d-dEKhpngX.js";
14
+ export { type I as Instance, type K as KittyFlagName, type a as KittyKeyboardOptions, type R as RenderOptions, k as kittyFlags, b as kittyModifiers, r as render } from "../packem_shared/render.d-tqP_-Le_.js";
15
15
  import React, { PropsWithChildren, ReactNode } from 'react';
16
16
  export { R as Range, S as Selection, a as applySelectionToStyledLine, c as comparePoints } from "../packem_shared/selection.d-DCMpXtpU.js";
17
- export { type T as TerminalPalette, i as isTerminalPaletteQuerySupported, q as queryTerminalPalette } from "../packem_shared/terminal-palette.d-JbWHISW-.js";
17
+ export { type T as TerminalPalette, i as isTerminalPaletteQuerySupported, q as queryTerminalPalette } from "../packem_shared/terminal-palette.d-DSgSpnMs.js";
18
18
  export type { CursorPosition } from "./public/cursor.js";
19
19
  import { M as MouseButton, e as MousePosition } from "../packem_shared/mouse-context.d-5TGeZyIF.js";
20
20
  export type { f as MouseAction, a as MouseClickAction, d as MouseContextShape, b as MouseDragAction, g as MouseEvents, c as MouseScrollAction } from "../packem_shared/mouse-context.d-5TGeZyIF.js";
package/dist/ink/index.js CHANGED
@@ -1 +1 @@
1
- import{clearOsc52 as o,isOsc52Supported as r,writeOsc52 as a}from"../packem_shared/clearOsc52-olbKg5Nw.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-CaI93Rjj.js";import{g as d,i as x}from"../packem_shared/dom-xpeZzKuf.js";import{IMECompositionBuffer as S,isIMEInput as h}from"../packem_shared/IMECompositionBuffer-uYiAz3jI.js";import{kittyFlags as M,kittyModifiers as O}from"../packem_shared/kittyFlags-jpd_IAFL.js";import{processLayout as I}from"../packem_shared/processLayout-DYdx6C3A.js";import{c as b,a as C,b as E,g as N,d as R,e as B,f as P,h as H,i as v,j as W,k,l as A,m as _}from"../packem_shared/measure-element-pHwUPovG.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-DtlK6gar.js";import{default as V}from"../packem_shared/render-DrIzCc0i.js";import{default as Y}from"../packem_shared/renderToString-D66vRHLQ.js";import{default as J,ResizeObserverEntry as K}from"../packem_shared/ResizeObserver-ClWoCtGV.js";import{calculateScroll as $,getScrollHeight as ee,getScrollLeft as te,getScrollTop as oe,getScrollWidth as re}from"../packem_shared/calculateScroll-jdxVlcmq.js";import{Range as se,Selection as le,applySelectionToStyledLine as ie,comparePoints as ne}from"../packem_shared/Range-CMqYzhij.js";import{squashTextNodesWithMap as fe}from"../packem_shared/squashTextNodesWithMap-CUJZZeW3.js";import{isTerminalPaletteQuerySupported as ce,queryTerminalPalette as me}from"../packem_shared/isTerminalPaletteQuerySupported-DwJPJ8_h.js";import{wrapOrTruncateStyledLine as xe}from"../packem_shared/wrapOrTruncateStyledLine-Gm21gYDr.js";import{default as Se}from"../packem_shared/Fullscreen-DKKMVbkg.js";import{default as Te}from"../packem_shared/MouseProvider-BSTuFqG9.js";import{default as Oe}from"../packem_shared/isIntersecting-C8tJIsvH.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 Re}from"./mouse/use-on-mouse-hover.js";import{default as Pe}from"./mouse/use-on-mouse-state.js";import{p as ve}from"../packem_shared/ansi-parser-CysVDsNz.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,N as getAddedScrollHeight,R 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,Re 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-olbKg5Nw.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-CaI93Rjj.js";import{g as d,i as x}from"../packem_shared/dom-xpeZzKuf.js";import{IMECompositionBuffer as S,isIMEInput as h}from"../packem_shared/IMECompositionBuffer-uYiAz3jI.js";import{kittyFlags as M,kittyModifiers as O}from"../packem_shared/kittyFlags-jpd_IAFL.js";import{processLayout as I}from"../packem_shared/processLayout-DYdx6C3A.js";import{c as b,a as C,b as E,g as N,d as R,e as B,f as P,h as H,i as v,j as W,k,l as A,m as _}from"../packem_shared/measure-element-pHwUPovG.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-DtlK6gar.js";import{default as V}from"../packem_shared/render-DGiSemZa.js";import{default as Y}from"../packem_shared/renderToString-D66vRHLQ.js";import{default as J,ResizeObserverEntry as K}from"../packem_shared/ResizeObserver-ClWoCtGV.js";import{calculateScroll as $,getScrollHeight as ee,getScrollLeft as te,getScrollTop as oe,getScrollWidth as re}from"../packem_shared/calculateScroll-jdxVlcmq.js";import{Range as se,Selection as le,applySelectionToStyledLine as ie,comparePoints as ne}from"../packem_shared/Range-CMqYzhij.js";import{squashTextNodesWithMap as fe}from"../packem_shared/squashTextNodesWithMap-CUJZZeW3.js";import{isTerminalPaletteQuerySupported as ce,queryTerminalPalette as me}from"../packem_shared/isTerminalPaletteQuerySupported-X6YXYjSp.js";import{wrapOrTruncateStyledLine as xe}from"../packem_shared/wrapOrTruncateStyledLine-Gm21gYDr.js";import{default as Se}from"../packem_shared/Fullscreen-DKKMVbkg.js";import{default as Te}from"../packem_shared/MouseProvider-BSTuFqG9.js";import{default as Oe}from"../packem_shared/isIntersecting-C8tJIsvH.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 Re}from"./mouse/use-on-mouse-hover.js";import{default as Pe}from"./mouse/use-on-mouse-state.js";import{p as ve}from"../packem_shared/ansi-parser-CysVDsNz.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,N as getAddedScrollHeight,R 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,Re as useOnMouseHover,Pe as useOnMouseState,xe as wrapOrTruncateStyledLine,a as writeOsc52};
@@ -0,0 +1 @@
1
+ import{parseColor as $}from"@visulima/ansi";import{r as v}from"./probe-terminal-mMqobBjP.js";const u="\x07",E="\x1B",f=`${E}]`,P=`${E}\\`,p=16,y=3+p,w=8192,x=e=>{const r=e.lastIndexOf(";"),o=$(r===-1?e:e.slice(r+1));if(o===void 0)return null;const t=n=>n.toString(16).padStart(2,"0");return`#${t(o.r)}${t(o.g)}${t(o.b)}`},M=()=>{const e=process.env.TERM_PROGRAM??"";return new Set(["Alacritty","contour","foot","Ghostty","iTerm2","iTerm.app","kitty","rio","WezTerm"]).has(e)?!0:(process.env.TERM??"").startsWith("xterm")||!!process.env.WT_SESSION},A=(e,r)=>{const o=x(e);if(o===null)return!1;if(e.startsWith("10;"))return r.foreground=o,!0;if(e.startsWith("11;"))return r.background=o,!0;if(e.startsWith("12;"))return r.cursor=o,!0;if(e.startsWith("4;")){const t=e.indexOf(";",2),n=Number(e.slice(2,t===-1?e.length:t));if(Number.isSafeInteger(n)&&n>=0&&n<p)return r.colors[n]=o,!0}return!1},C=()=>{const e=[`${f}10;?${u}`,`${f}11;?${u}`,`${f}12;?${u}`];for(let r=0;r<p;r+=1)e.push(`${f}4;${String(r)};?${u}`);return e.join("")},S=new WeakMap,N=e=>{S.delete(e)},W=e=>{const r=[];let o="",t=e;for(;;){const n=t.indexOf(f);if(n===-1){const l=t.endsWith(E)?1:0;return o+=t.slice(0,t.length-l),{answers:r,foreign:o,rest:t.slice(t.length-l)}}o+=t.slice(0,n),t=t.slice(n);const s=t.indexOf(u),c=t.indexOf(P),h=s!==-1,m=c!==-1;if(!h&&!m)return{answers:r,foreign:o,rest:t};const g=h&&(!m||s<c)?s:c;r.push(t.slice(f.length,g)),t=t.slice(g+(g===s?u.length:P.length))}},k=async(e,r,o)=>new Promise(t=>{const n={colors:Array.from({length:p})};let s="",c="",h=0,m=!1;const g=e.listenerCount("data")===0;let l;const T=d=>{const a=W(c+d.toString());s+=a.foreign,c=a.rest;for(const i of a.answers)A(i,n)&&(h+=1);(h>=y||c.length+s.length>w)&&b()};function b(){if(m)return;m=!0,l&&clearTimeout(l);const d=e.listenerCount("data")===1;e.removeListener("data",T);const a=s+c;if(g&&d&&a.length>0)try{e.pause(),e.unshift(a)}catch{}const i={};n.foreground&&(i.foreground=n.foreground),n.background&&(i.background=n.background),n.cursor&&(i.cursor=n.cursor),n.colors.some(Boolean)&&(i.colors=n.colors.map(O=>O??"")),t(i)}e.on("data",T),l=setTimeout(b,o),r.write(C())}),R=async(e,r)=>{const o=Promise.withResolvers(),t=()=>{o.resolve({})};r.addEventListener("abort",t,{once:!0});try{return await Promise.race([e,o.promise])}finally{r.removeEventListener("abort",t)}},B=async(e,r,o)=>{let t;try{t=await v(e,async()=>k(e,r,o))}catch(n){throw S.delete(r),n}return Object.keys(t).length===0&&S.delete(r),t},I=async(e,r,o=500,t)=>{if(t?.aborted)return{};let n=S.get(r);return n||(n=B(e,r,o),S.set(r,n)),t?R(n,t):n};export{N as clearTerminalPaletteCache,M as isTerminalPaletteQuerySupported,I as queryTerminalPalette,W as takeOscAnswers};
@@ -0,0 +1 @@
1
+ const c=new WeakMap,s=async(t,e)=>(await t,e()),u=(t,e)=>{const a=c.get(t),n=a===void 0?e():s(a,e);let r;return r=(async()=>{try{await n}catch{}c.get(t)===r&&c.delete(t)})(),c.set(t,r),n};export{u as r};
@@ -0,0 +1,22 @@
1
+ import{createRequire as Fe}from"node:module";import{jsx as L}from"react/jsx-runtime";import{cursorShow as ft,setMode as le,BracketedPasteMode as de,resetMode as he,eraseLines as st,cursorHide as Rt,cursorUp as Vt,cursorNextLine as We,cursorTo as Ae,eraseLineEnd as Ue,createDecMode as He,ALT_SCREEN_ON as $t,clearScreenAndHomeCursor as Ke,ALT_SCREEN_OFF as Qt}from"@visulima/ansi";import{wordWrap as Ge}from"@visulima/string";import{ConcurrentRoot as Ye,LegacyRoot as qe}from"react-reconciler/constants.js";import M from"yoga-layout";import{a as je}from"./accessibility-context-DDyHTwmA.js";import{useState as ct,useRef as C,useCallback as v,useEffect as lt,useMemo as A}from"react";import{a as Ve}from"./animation-context-Icwf5tBE.js";import{A as $e}from"./app-context-CfgsW0CV.js";import{C as Qe}from"./cursor-context-wLwblh2o.js";import Xe from"../components/error-boundary.js";import{F as Ze}from"./focus-context-8h3hmNxy.js";import{S as Je}from"./stderr-context-Xeacf3Ir.js";import{S as ti}from"./stdin-context-Ceh-YuU1.js";import{S as ei}from"./stdout-context-BhxOwdNK.js";import{O as ii,a as si,b as ni,r as ri}from"./renderer-D97BmOBO.js";import{c as oi,e as ai}from"./dom-xpeZzKuf.js";import{resolveFlags as Xt}from"./kittyFlags-jpd_IAFL.js";import{buildReturnToBottomPrefix as Zt,buildCursorSuffix as Et,cursorPositionChanged as Jt,buildCursorOnlySequence as ui,buildCursorShapeSequence as te}from"./buildCursorOnlySequence-D24o0D7-.js";import{l as ci}from"./load-native-root-binding-B1WunHs4.js";import{a as li}from"./measure-text-DtlK6gar.js";import{r as di}from"./probe-terminal-mMqobBjP.js";import{r as I,s as hi}from"./reconciler-BPm7fZa6.js";import{measureAndExtractObservers as fi}from"./ResizeObserver-ClWoCtGV.js";import{calculateScroll as pi}from"./calculateScroll-jdxVlcmq.js";import{g as q}from"./utils-BlDbvbdr.js";let Me;const Be=i=>(Me??=Fe(import.meta.url))(i),V=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,mt=i=>{if(typeof V<"u"&&V.versions&&V.versions.node){const[t,e]=V.versions.node.split(".").map(Number);if(t>22||t===22&&e>=3||t===20&&e>=16)return V.getBuiltinModule(i)}return Be(i)},E=V,{env:vt}=E,{PassThrough:jt,Stream:De}=mt("node:stream"),{Buffer:zt}=mt("node:buffer"),{Console:_e}=mt("node:console"),{EventEmitter:ze}=mt("node:events"),ee=i=>i in vt&&vt[i]!=="0"&&vt[i]!=="false",fe=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 bt={};const mi=i=>{const t=new jt,e=new jt;t.write=n=>{i("stdout",n)},e.write=n=>{i("stderr",n)};const s=new console.Console(t,e);for(const n of ie)bt[n]=console[n],console[n]=s[n];return()=>{for(const n of ie)console[n]=bt[n];bt={}}},$=[];$.push("SIGHUP","SIGINT","SIGTERM");process.platform!=="win32"&&$.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&$.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT");const ht=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",yt=Symbol.for("signal-exit emitter"),wt=globalThis,gi=Object.defineProperty.bind(Object);class vi{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(wt[yt])return wt[yt];gi(wt,yt,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(t,e){this.listeners[t].push(e)}removeListener(t,e){const s=this.listeners[t],n=s.indexOf(e);n!==-1&&(n===0&&s.length===1?s.length=0:s.splice(n,1))}emit(t,e,s){if(this.emitted[t])return!1;this.emitted[t]=!0;let n=!1;for(const r of this.listeners[t])n=r(e,s)===!0||n;return t==="exit"&&(n=this.emit("afterExit",e,s)||n),n}}class pe{}const bi=i=>({onExit(t,e){return i.onExit(t,e)},load(){return i.load()},unload(){return i.unload()}});class yi extends pe{onExit(){return()=>{}}load(){}unload(){}}class wi extends pe{#o=Tt.platform==="win32"?"SIGINT":"SIGHUP";#e=new vi;#t;#n;#r;#s={};#i=!1;constructor(t){super(),this.#t=t,this.#s={};for(const e of $)this.#s[e]=()=>{const s=this.#t.listeners(e);let{count:n}=this.#e;const r=t;if(typeof r.__signal_exit_emitter__=="object"&&typeof r.__signal_exit_emitter__.count=="number"&&(n+=r.__signal_exit_emitter__.count),s.length===n){this.unload();const u=this.#e.emit("exit",null,e),o=e==="SIGHUP"?this.#o:e;u||t.kill(t.pid,o)}};this.#r=t.reallyExit,this.#n=t.emit}onExit(t,e){if(!ht(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 $)try{const e=this.#s[t];e&&this.#t.on(t,e)}catch{}this.#t.emit=(t,...e)=>this.#u(t,...e),this.#t.reallyExit=t=>this.#a(t)}}unload(){this.#i&&(this.#i=!1,$.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.#n,this.#t.reallyExit=this.#r,this.#e.count-=1)}#a(t){return ht(this.#t)?(this.#t.exitCode=t||0,this.#e.emit("exit",this.#t.exitCode,null),this.#r.call(this.#t,this.#t.exitCode)):0}#u(t,...e){const s=this.#n;if(t==="exit"&&ht(this.#t)){typeof e[0]=="number"&&(this.#t.exitCode=e[0]);const n=s.call(this.#t,t,...e);return this.#e.emit("exit",this.#t.exitCode,null),n}else return s.call(this.#t,t,...e)}}const Tt=globalThis.process,{onExit:Si}=bi(ht(Tt)?new wi(Tt):new yi),pt="\x1B",me="\x1B[200~",se="\x1B[201~",xi=i=>i>=48&&i<=63,Ri=i=>i>=32&&i<=47,ge=i=>i>=64&&i<=126,Ti=(i,t,e)=>{const s=t+e+1;let n=s;for(;n<i.length;n++){const r=i.codePointAt(n);if(r===void 0)return"pending";if(!(xi(r)||Ri(r))&&!(r===91&&n===s))return ge(r)?{nextIndex:n+1,sequence:i.slice(t,n+1)}:void 0}return"pending"},Ci=(i,t,e)=>{const s=t+e+2;if(s>i.length)return"pending";const n=i.codePointAt(s-1);if(!(n===void 0||!ge(n)))return{nextIndex:s,sequence:i.slice(t,s)}},ne=(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 Ci(i,t,e)},Ei=(i,t)=>{const e=i.codePointAt(t+1),s=e!==void 0&&e>65535?2:1,n=t+1+s;return{nextIndex:n,sequence:i.slice(t,n)}},Pi=(i,t)=>{if(t===i.length-1)return"pending";if(i[t+1]===pt){if(t+2>=i.length)return"pending";const n=ne(i,t,2);return n==="pending"?"pending":n||{nextIndex:t+2,sequence:i.slice(t,t+2)}}const s=ne(i,t,1);return s==="pending"?"pending":s||Ei(i,t)},re=(i,t)=>{let e=0;for(let s=0;s<i.length;s++){const n=i[s];(n===""||n==="\b")&&(s>e&&t.push(i.slice(e,s)),t.push(n),e=s+1)}e<i.length&&t.push(i.slice(e))},Oi=i=>{const t=[];let e=0;const s=n=>({events:t,pending:i.slice(n)});for(;e<i.length;){const n=i.indexOf(pt,e);if(n===-1)return re(i.slice(e),t),{events:t,pending:""};n>e&&re(i.slice(e,n),t);const r=Pi(i,n);if(r==="pending")return s(n);if(r.sequence===me){const u=r.nextIndex,o=i.indexOf(se,u);if(o===-1)return s(n);t.push({paste:i.slice(u,o)}),e=o+se.length;continue}t.push(r.sequence),e=r.nextIndex}return{events:t,pending:""}},Ii=()=>{let i="";return{flushPendingEscape(){if(!i.startsWith(pt))return;const t=i;return i="",t},hasPendingEscape(){return i.startsWith(pt)&&!i.startsWith(me)&&i!=="\x1B[200"},push(t){const e=Oi(i+t);return i=e.pending,e.events},reset(){i=""}}},Ni=" ",ki="\x1B[Z",Li="\x1B",oe=le(de),St=he(de),ve=({children:i,exitOnCtrlC:t,interactive:e,onExit:s,onRegisterInputControl:n,onSuspendTerminal:r,onWaitUntilRenderFlush:u,renderThrottleMs:o,setCursorPosition:d,stderr:l,stdin:c,stdout:h,writeToStderr:y,writeToStdout:S})=>{const[m,b]=ct(!0),[g,w]=ct(void 0),[,P]=ct([]),O=C(0),T=C([]),B=C(new Map),Q=C(void 0),D=C(0),F=C(!1),W=C(0),[N]=ct(()=>{const a=new ze;return a.setMaxListeners(1/0),a}),X=C(void 0),Z=C(void 0);Z.current??=Ii();const J=C(void 0),Pt=C(!1),Re=20,H=v(()=>{J.current&&(clearTimeout(J.current),J.current=void 0)},[]),K=v(()=>{Q.current&&(clearTimeout(Q.current),Q.current=void 0)},[]),rt=v(()=>{if(K(),B.current.size===0)return;let a=Number.POSITIVE_INFINITY;for(const f of B.current.values())a=Math.min(a,f.nextDueTime);const p=Math.max(0,a-performance.now());Q.current=setTimeout(()=>{Q.current=void 0;const f=performance.now(),x=[...B.current.values()];for(const R of x){if(f<R.nextDueTime)continue;R.callback(f);const ke=f-R.startTime,Le=Math.floor(ke/R.interval)+1;R.nextDueTime=R.startTime+Le*R.interval}rt()},p)},[K]),Ot=v((a,p)=>{const f=performance.now();return B.current.set(a,{callback:a,interval:p,nextDueTime:f+p,startTime:f}),rt(),{startTime:f,unsubscribe(){if(B.current.delete(a),B.current.size===0){K();return}rt()}}},[K,rt]);lt(()=>()=>{K()},[K]);const k=c.isTTY,It=v(()=>{X.current&&(c.removeListener("readable",X.current),X.current=void 0)},[c]),G=v(()=>{Z.current?.reset(),H(),It()},[H,It]),Y=v(()=>{F.current=!1,c.setRawMode(!1),c.unref(),D.current=0,G()},[c,G]),tt=v(a=>{k&&(D.current>0||F.current)&&Y(),s(a)},[k,Y,s]),Nt=v(a=>{if(a.includes("")&&t){tt();return}a===Li&&m&&w(p=>{if(!p)return p})},[t,tt,m]),et=v(a=>{Nt(a),N.emit("input",a)},[Nt,N]),kt=v(()=>{H(),J.current=setTimeout(()=>{J.current=void 0;const a=Z.current.flushPendingEscape();a&&et(a)},Re)},[H,et]),gt=v(()=>{H();let a;for(;(a=c.read())!==null;){const p=Z.current.push(a);for(const f of p)if(typeof f=="string")et(f);else{if(N.listenerCount("paste")===0){Pt.current||(Pt.current=!0,y(`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(f.paste);continue}N.emit("paste",f.paste)}}Z.current.hasPendingEscape()&&kt()},[c,et,H,kt,y,N]),ot=v(()=>{X.current||(X.current=gt,c.addListener("readable",gt))},[c,gt]),Lt=v(a=>{if(!k)throw c===E.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(c.setEncoding("utf8"),a){if(D.current===0){const p=F.current;F.current=!1,p||(c.ref(),c.setRawMode(!0)),ot()}D.current++;return}D.current!==0&&--D.current===0&&(G(),F.current=!0,queueMicrotask(()=>{F.current&&Y()}))},[k,c,ot,G,Y]),Ft=v(a=>{if(h.isTTY){if(a){W.current===0&&h.write(oe),W.current++;return}W.current!==0&&--W.current===0&&h.write(St)}},[h]),Mt=C({bracketedPaste:!1,rawMode:!1}),Bt=v(()=>{const a=k&&(D.current>0||F.current),p=W.current>0;Mt.current={bracketedPaste:p,rawMode:a},p&&h.isTTY&&h.write(St),a&&(F.current=!1,G(),c.setRawMode(!1),c.unref())},[k,h,c,G]),Dt=v(()=>{const{bracketedPaste:a,rawMode:p}=Mt.current;p&&(c.ref(),c.setRawMode(!0),c.setEncoding("utf8"),ot()),a&&h.isTTY&&h.write(oe)},[c,h,ot]);lt(()=>{n(Bt,Dt)},[n,Bt,Dt]);const _t=v((a,p)=>{const f=a.findIndex(x=>x.id===p);for(let x=f+1;x<a.length;x++){const R=a[x];if(R?.isActive)return R.id}},[]),Wt=v((a,p)=>{const f=a.findIndex(x=>x.id===p);for(let x=f-1;x>=0;x--){const R=a[x];if(R?.isActive)return R.id}},[]),at=v(()=>{const a=T.current;w(p=>{const f=a.find(R=>R.isActive)?.id;return _t(a,p)??f})},[_t]),ut=v(()=>{const a=T.current;w(p=>{const f=a.findLast(R=>R.isActive)?.id;return Wt(a,p)??f})},[Wt]);lt(()=>{const a=f=>{!m||O.current===0||(f===Ni&&at(),f===ki&&ut())};N.on("input",a);const p=N;return()=>{p.off("input",a)}},[m,at,ut,N]);const At=v(()=>{b(!0)},[]),Ut=v(()=>{b(!1)},[]),Ht=v(a=>{T.current.some(f=>f?.id===a)&&w(a)},[]),Kt=v((a,{autoFocus:p})=>{const f=[...T.current,{id:a,isActive:!0}];O.current=f.length,T.current=f,P(f),p&&w(x=>x||a)},[]),Gt=v(a=>{w(f=>{if(f!==a)return f});const p=T.current.filter(f=>f.id!==a);O.current=p.length,T.current=p,P(p)},[]),Yt=v(a=>{const p=T.current.map(f=>f.id!==a?f:{id:a,isActive:!0});T.current=p,P(p)},[]),qt=v(a=>{w(f=>{if(f!==a)return f});const p=T.current.map(f=>f.id!==a?f:{id:a,isActive:!1});T.current=p,P(p)},[]);lt(()=>()=>{const a=!h.destroyed&&!h.writableEnded;e&&a&&h.write(ft),k&&(D.current>0||F.current)&&Y(),W.current>0&&(h.isTTY&&a&&h.write(St),W.current=0)},[h,k,Y,e]);const Te=A(()=>({exit:tt,suspendTerminal:r,waitUntilRenderFlush:u}),[tt,r,u]),Ce=A(()=>({internal_eventEmitter:N,internal_exitOnCtrlC:t,isRawModeSupported:k,setBracketedPasteMode:Ft,setRawMode:Lt,stdin:c}),[c,Lt,Ft,k,t,N]),Ee=A(()=>({stdout:h,write:S}),[h,S]),Pe=A(()=>({stderr:l,write:y}),[l,y]),Oe=A(()=>({setCursorPosition:d}),[d]),Ie=A(()=>({activate:Yt,activeId:g,add:Kt,deactivate:qt,disableFocus:Ut,enableFocus:At,focus:Ht,focusNext:at,focusPrevious:ut,remove:Gt}),[g,Kt,Gt,Yt,qt,At,Ut,at,ut,Ht]),Ne=A(()=>({renderThrottleMs:o,subscribe:Ot}),[Ot,o]);return L($e.Provider,{value:Te,children:L(ti.Provider,{value:Ce,children:L(ei.Provider,{value:Ee,children:L(Je.Provider,{value:Pe,children:L(Ze.Provider,{value:Ie,children:L(Ve.Provider,{value:Ne,children:L(Qe.Provider,{value:Oe,children:L(Xe,{onError:tt,children:i})})})})})})})})};ve.displayName="InternalApp";const Fi=(i,t,e)=>{if(e<=0||!i.yogaNode)return"";const{yogaNode:s}=i,n=s.getComputedBorder(M.EDGE_LEFT),r=s.getComputedBorder(M.EDGE_RIGHT),u=s.getComputedBorder(M.EDGE_TOP),o=s.getComputedPadding(M.EDGE_LEFT),d=s.getComputedPadding(M.EDGE_RIGHT),l=s.getComputedPadding(M.EDGE_TOP),c=Math.round(s.getComputedWidth()-n-r-o-d);if(c<=0)return"";const h=new ii({height:e,width:c}),S=-(i.internal_scrollState?.scrollLeft??0)-n-o,m=-t-u-l;for(const b of i.childNodes)si(b,h,{absoluteOffsetX:S,absoluteOffsetY:m,offsetX:S,offsetY:m,skipStaticElements:!1});return h.get().output},Ct=new WeakMap,j=i=>i??"default",Mi=()=>{let i,t;return{consumeDelta:()=>{if(j(t)===j(i))return"";const e=j(t);return i=t,te(e)},consumeRestoreOnDone:()=>{const e=j(i)!=="default";return i=void 0,t=void 0,e?te("default"):""},isDirty:()=>j(t)!==j(i),setPending:e=>{t=e}}},nt=(i,t)=>t.endsWith(`
5
+ `)?i.length-1:i.length,be=i=>i.rows||1/0,ye=(i,t)=>Math.min(i,be(t)),we=(i,t)=>{const{activeCursor:e,content:s,contentLines:n,previousLines:r,returnPrefix:u,shapeDelta:o}=i,d=Et(nt(n,s),e);t.write(o+u+st(ye(r.length,t))+s+d)},Bi=(i,t)=>{const{activeCursor:e,content:s,contentLines:n,previous:r,previousLines:u,returnPrefix:o,shapeDelta:d}=i,l=nt(n,s);if(s===`
6
+ `||r.length===0){we(i,t);return}const c=nt(u,r),h=s.endsWith(`
7
+ `),y=[d,o],S=be(t);if(l<c){const b=r.endsWith(`
8
+ `)?1:0;y.push(st(Math.min(c-l+b,S)),Vt(Math.min(l,S-1)))}else y.push(Vt(Math.min(c-1,S-1)));for(let m=0;m<l;m+=1){const b=m===l-1;if(n[m]===u[m]){(!b||h)&&y.push(We());continue}y.push(Ae(0)+n[m]+Ue+(b&&!h?"":`
9
+ `))}y.push(Et(l,e)),t.write(y.join(""))},Di=(i,{showCursor:t=!1},e)=>{let s=[],n="",r=!1,u,o=!1,d,l=!1;const c=Mi(),h=()=>o?u:void 0,y=(g,w)=>{const P=Jt(w,d);return g!==n||P||c.isDirty()},S=g=>{d=g?{...g}:void 0,l=g!==void 0},m=()=>{n="",s=[],d=void 0,l=!1},b=g=>{!t&&!r&&(i.write(Rt),r=!0);const w=h();o=!1;const P=Jt(w,d);if(!y(g,w))return!1;const O=c.consumeDelta(),T=g.split(`
10
+ `),B=nt(T,g);return g===n&&P?(i.write(O+ui({cursorPosition:w,cursorWasShown:l,previousCursorPosition:d,previousLineCount:s.length,visibleLineCount:B})),S(w),!0):g===n&&O!==""?(i.write(O),S(w),!0):(e({activeCursor:w,content:g,contentLines:T,previous:n,previousLines:s,returnPrefix:Zt(l,s.length,d),shapeDelta:O},i),n=g,s=T,S(w),!0)};return b.clear=()=>{const g=Zt(l,s.length,d);i.write(g+st(ye(s.length,i))),m()},b.done=()=>{m();const g=c.consumeRestoreOnDone();g!==""&&i.write(g),t||(i.write(ft),r=!1)},b.reset=m,b.sync=g=>{const w=h();o=!1;const P=g.split(`
11
+ `);n=g,s=P;const O=c.consumeDelta();O!==""&&i.write(O),!w&&l&&i.write(Rt),w&&i.write(Et(nt(P,g),w)),S(w)},b.setCursorPosition=g=>{u=g,o=!0},b.setCursorShape=c.setPending,b.isCursorDirty=()=>o||c.isDirty(),b.willRender=g=>y(g,h()),b},_i=(i,{incremental:t=!1,showCursor:e=!1}={})=>Di(i,{showCursor:e},t?Bi:we),Wi={create:_i},Se=He(2026),U=le(Se),_=he(Se);function Ai(i,t){return"isTTY"in i&&i.isTTY&&(t??!fe)}let z;const Ui=()=>{if(z!==!1){if(z!==void 0)return z;try{return z=ci(import.meta.url).Renderer,z}catch{z=!1;return}}},Hi=i=>{const t=Ui();if(!t)return;let e,s=0,n=0;const r=(u,o)=>{(!e||s!==u||n!==o)&&(e?e.resize(u,o):e=new t(u,o),s=u,n=o)};return{clear(){if(e){const u=new Uint32Array(s*n*2),o=65535;for(let d=0;d<u.length;d+=2)u[d]=32,u[d+1]=o;e.render(u)}},destroy(){e=void 0},render(u,o,d){if(r(o,d),!!e){i.isTTY&&e.writeRaw(U);try{e.render(u)}finally{i.isTTY&&e.writeRaw(_)}}},resize(u,o){r(u,o)}}};function ae(i,t=0,e={}){const s=e.leading??!0,n=e.trailing??!0;let r,u,o,d;const l=()=>{if(u===void 0)return;const m=u;u=void 0,d=i(...m)},c=()=>{r!==void 0&&(clearTimeout(r),r=void 0)},h=()=>{r=void 0,n&&l(),u=void 0,o=void 0},y=()=>{c(),r=setTimeout(h,t)},S=function(...b){const g=Date.now();if(o??=g,g-o>=t)return u=b,l(),o=g,y(),d;u=b;const w=r===void 0;return y(),s&&w&&l(),d};return S.cancel=()=>{c(),u=void 0,o=void 0},S.flush=()=>(c(),l(),o=void 0,d),S}console.Console||(console.Console=_e);const it=()=>{},ue=async()=>new Promise(i=>{setImmediate(i)}),Ki=27,Gi=91,Yi=63,qi=117,ji=48,zi=57,Vi=i=>i>=ji&&i<=zi,xe=(i,t)=>{if(i[t]!==Ki||i[t+1]!==Gi||i[t+2]!==Yi)return;let e=t+3;const s=e;for(;e<i.length&&Vi(i[e]);)e++;if(e!==s){if(e===i.length)return{state:"partial"};if(i[e]===qi)return{endIndex:e,state:"complete"}}},$i=i=>{for(let t=0;t<i.length;t++)if(xe(i,t)?.state==="complete")return!0;return!1},Qi=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},Xi=({isTty:i,isUnmounting:t,isWindows:e,nextOutputHeight:s,previousOutputHeight:n,viewportRows:r})=>{if(!i)return!1;const u=n>0,o=n>=r,d=s>=r,l=n>r,c=s>r,h=o&&s<r;return l||c&&u||h||t&&o||e&&(d||o)},xt=i=>i instanceof Error||Object.prototype.toString.call(i)==="[object Error]",ce=i=>{const t=!i.destroyed&&!i.writableEnded&&(i.writable??!0),e=i._writableState!==void 0||i.writableLength!==void 0;return{canWriteToStdout:t,hasWritableState:e}},dt=(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??E.env.INK_SCREEN_READER==="true",this.interactive=this.resolveInteractiveOption(t.interactive),this.alternateScreen=!1;const e=t.debug||this.isScreenReaderEnabled,s=t.maxFps??30,n=s>0?Math.max(1,Math.ceil(1e3/s)):0;this.renderThrottleMs=e?0:n;const r=e?this.onRender:(()=>{const o=ae(this.onRender,n,{leading:!0,trailing:!0});return this.throttledOnRender=o,()=>{this.hasPendingThrottledRender=!0,o()}})();if(e&&(this.throttledOnRender=void 0),t.standardReactLayoutTiming){let o=!1;const d=()=>{o||(o=!0,queueMicrotask(()=>{o=!1,this.onRender()}))};this.rootNode.onRender=d,this.rootNode.onImmediateRender=d}else this.rootNode.onRender=r,this.rootNode.onImmediateRender=this.onRender;this.rootNode.onStaticChange=this.handleStaticChange,this.log=Wi.create(t.stdout,{incremental:t.incrementalRendering}),this.useNativeRenderer=t.useNativeRenderer??!1,this.useNativeRenderer&&(this.nativeLog=Hi(t.stdout),this.nativeLog||(this.useNativeRenderer=!1)),this.manualCursorPosition=void 0,this.renderedCursorPosition=void 0,this.renderedCursorRequested=!1,this.throttledLog=e?this.log:ae(o=>{const d=this.log.willRender(o),l=this.shouldSync();l&&d&&this.options.stdout.write(U),this.log(o),l&&d&&this.options.stdout.write(_)},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 u=t.concurrent?Ye:qe;this.container=I.createContainer(this.rootNode,u,null,!1,null,"id",()=>{},()=>{},()=>{},()=>{}),this.unsubscribeExit=Si(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(),E.env.DEV==="true"&&I.injectIntoDevTools(),this.exitPromise=new Promise((o,d)=>{this.resolveExitPromise=o,this.rejectExitPromise=d}),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=""),li(),this.calculateLayout(),ai(this.rootNode),this.onRender(),this.lastTerminalWidth=t};resolveExitPromise=()=>{};rejectExitPromise=()=>{};unsubscribeExit=()=>{};handleAppExit=t=>{if(!(this.isUnmounted||this.isUnmounting)){if(xt(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}
12
+ `))};calculateLayout=()=>{const t=s=>{const n=new Map;this.calculateScrollAndTriggerObservers(s,n);for(const[r,u]of n)r.internalTrigger(u)};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,M.DIRECTION_LTR),t(this.rootNode)};calculateScrollAndTriggerObservers(t,e){if(t.nodeName==="ink-box"){const{style:s}=t,n=s.overflow??"visible",r=s.overflowX??n,u=s.overflowY??n;r==="scroll"||u==="scroll"?(pi(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(fi(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(),hi(t.yogaNode,t.style);t.yogaNode.getChildCount()>0;)t.yogaNode.getChild(0).remove();let s=0;for(const n of t.childNodes){const r=n;n.nodeName!=="#text"&&r.yogaNode&&(t.yogaNode.insertChild(r.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:n}=t.style;t.yogaNode&&(t.yogaNode.setWidth(typeof n=="number"?n:s),t.yogaNode.calculateLayout(void 0,void 0,M.DIRECTION_LTR)),e(t),ni(t,{skipStaticElements:!1,trackSelection:this.options.trackSelection}),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(M.EDGE_TOP)??0,n=Math.max(0,e-Math.round(s)),r=t.internal_maxPushedScrollTop??0,{maxScrollbackLength:u}=t.style,o=u===void 0?r:Math.max(r,n-Math.max(0,u)),d=n-o;if(d<=0)return"";const l=Fi(t,o,d);return l===""?"":(t.internal_maxPushedScrollTop=n,`${l}\x1B[0m
13
+ `)}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:n,output:r,outputBuffer:u,outputHeight:o,outputWidth:d,staticOutput:l}=t;this.renderedCursorRequested=s,this.renderedCursorPosition=e,this.log.setCursorShape(s?n:void 0);const c=this.computeBackbufferOutput();if(this.useNativeRenderer&&this.nativeLog&&u&&d){l&&l!==`
14
+ `&&this.options.stdout.write(l),c&&this.options.stdout.write(c),this.nativeLog.render(u,d,o),this.lastOutputHeight=o;return}s&&this.log.setCursorPosition(this.getActiveCursorPosition());const h=l&&l!==`
15
+ `;if(this.options.debug){h&&(this.fullStaticOutput+=l),this.lastOutput=r,this.lastOutputToRender=r,this.lastOutputHeight=o,this.options.stdout.write(this.fullStaticOutput+r);return}if(!this.interactive){h&&this.options.stdout.write(l),this.lastOutput=r,this.lastOutputToRender=`${r}
16
+ `,this.lastOutputHeight=o;return}if(this.isScreenReaderEnabled){const y=this.shouldSync();if(y&&this.options.stdout.write(U),h){const b=this.lastOutputHeight>0?st(this.lastOutputHeight):"";this.options.stdout.write(b+l),this.lastOutputHeight=0}if(r===this.lastOutput&&!h){y&&this.options.stdout.write(_);return}const S=q(this.options.stdout).columns,m=Ge(r,{trim:!1,width:S,wrapMode:"BREAK_WORDS"}).replace(/\n$/,"");if(h)this.options.stdout.write(m);else{const b=this.lastOutputHeight>0?st(this.lastOutputHeight):"";this.options.stdout.write(b+m)}this.lastOutput=r,this.lastOutputToRender=m,this.lastOutputHeight=m===""?0:m.split(`
17
+ `).length,y&&this.options.stdout.write(_);return}h&&(this.fullStaticOutput+=l),this.renderInteractiveFrame(r,o,h?l:"",c)};accessibilityContextValue;render(t){this.accessibilityContextValue??={isScreenReaderEnabled:this.isScreenReaderEnabled};const e=L(je.Provider,{value:this.accessibilityContextValue,children:L(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?I.updateContainer(e,this.container,null,it):(I.updateContainerSync(e,this.container,null,it),I.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(U),this.log.clear(),this.options.stdout.write(t),this.restoreLastOutput(),e&&this.options.stdout.write(_)};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(U),this.log.clear(),this.options.stderr.write(t),this.restoreLastOutput(),e&&this.options.stdout.write(_)};unmount=t=>{if(this.isUnmounted||this.isUnmounting)return;this.isUnmounting=!0,this.beforeExitHandler&&(E.off("beforeExit",this.beforeExitHandler),this.beforeExitHandler=void 0);const e=this.options.stdout,{canWriteToStdout:s,hasWritableState:n}=ce(e);dt(this.throttledOnRender,s),s&&!this.alternateScreen&&(!this.throttledOnRender||!this.hasPendingThrottledRender&&this.fullStaticOutput==="")&&(this.calculateLayout(),this.onRender()),this.isUnmounted=!0,this.unsubscribeExit(),dt(this.throttledLog,s),typeof this.restoreConsole=="function"&&this.restoreConsole();const r=()=>{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,ft),this.alternateScreen=!1):this.interactive?this.options.debug||this.log.done():this.options.stdout.write(this.options.debug?`
18
+ `:`${this.lastOutput}
19
+ `)),this.kittyProtocolEnabled=!1,Ct.delete(this.options.stdout);const{exitResult:o}=this,d=()=>{xt(t)?this.rejectExitPromise(t):this.resolveExitPromise(o)};t!==void 0&&!xt(t)?d():s&&n?this.options.stdout.write("",d):setImmediate(d)},u=I;this.options.concurrent?(I.updateContainerSync(null,this.container,null,it),I.flushSyncWork(),u.flushPassiveEffects?.(),r()):(I.updateContainerSync(null,this.container,null,it),I.flushSyncWork(),r())};async waitUntilExit(){return this.beforeExitHandler||(this.beforeExitHandler=()=>{this.unmount()},E.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}I.flushSyncWork();const t=this.options.stdout,{canWriteToStdout:e,hasWritableState:s}=ce(t);if(dt(this.throttledOnRender,e),dt(this.throttledLog,e),e&&s){await new Promise(n=>{this.options.stdout.write("",()=>{n()})});return}await ue()}clear(){!this.interactive||this.options.debug||(this.log.clear(),this.log.sync(this.lastOutputToRender||`${this.lastOutput}
20
+ `))}patchConsole(){this.options.debug||(this.restoreConsole=mi((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,$t),this.writeBestEffort(this.options.stdout,Rt))}resolveInteractiveOption(t){return t??(!fe&&this.options.stdout.isTTY)}resolveAlternateScreenOption(t,e){return!!t&&e&&this.options.stdout.isTTY}shouldSync(){return Ai(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,n=""){const r=s+n,u=r!=="",o=this.options.stdout.isTTY,d=o?q(this.options.stdout).rows:24,l=o&&e>=d,c=l?t:`${t}
21
+ `,h=E.platform==="win32",y=o&&h&&(l||this.lastOutputHeight>=d);if(Xi({isTty:o,isUnmounting:this.isUnmounting,isWindows:h,nextOutputHeight:e,previousOutputHeight:this.lastOutputHeight,viewportRows:d})){if(this.options.incrementalRendering&&!y){u&&(this.log.clear(),this.options.stdout.write(r)),(t!==this.lastOutput||this.log.isCursorDirty()||u)&&this.throttledLog(c),this.lastOutput=t,this.lastOutputToRender=c,this.lastOutputHeight=e;return}const m=this.shouldSync();m&&this.options.stdout.write(U),this.options.stdout.write(Ke+this.fullStaticOutput+n+c),this.lastOutput=t,this.lastOutputToRender=c,this.lastOutputHeight=e,this.log.sync(c),m&&this.options.stdout.write(_);return}if(u){const m=this.shouldSync();m&&this.options.stdout.write(U),this.log.clear(),this.options.stdout.write(r),this.log(c),m&&this.options.stdout.write(_)}else(t!==this.lastOutput||this.log.isCursorDirty())&&this.throttledLog(c);this.lastOutput=t,this.lastOutputToRender=c,this.lastOutputHeight=e}initImmediateKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="enabled")return;const s=t.flags??["disambiguateEscapeCodes"];this.options.stdin.isTTY&&this.options.stdout.isTTY&&this.enableKittyProtocol(s)}initDeferredKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="auto")return;const s=t.flags??["disambiguateEscapeCodes"];!this.interactive||!this.options.stdin.isTTY||!this.options.stdout.isTTY||this.confirmKittySupport(s)}confirmKittySupport(t){di(this.options.stdin,async()=>this.runKittySupportQuery(t))}async runKittySupportQuery(t){const{stdin:e,stdout:s}=this.options;let n=[],r,u;const o=()=>{this.cancelKittyDetection=void 0,r&&clearTimeout(r),e.removeListener("data",d);const l=Qi(n);n=[],l.length>0&&e.unshift(zt.from(l))},d=l=>{const c=typeof l=="string"?zt.from(l):l;for(const h of c)n.push(h);$i(n)&&(o(),this.isUnmounted||this.enableKittyProtocol(t),u?.())};return e.on("data",d),s.write("\x1B[?u"),new Promise(l=>{u=l,r=setTimeout(()=>{o(),l()},200),this.cancelKittyDetection=()=>{o(),l()}})}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,ft)),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,$t),this.kittyProtocolEnabled&&this.kittyFlags&&this.writeBestEffort(this.options.stdout,`\x1B[>${Xt(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[>${Xt(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:E.stderr,stdin:E.stdin,stdout:E.stdout,...Ji(t)},s=ts(e.stdout,()=>new Zi(e));return s.render(i),{cleanup(){s.unmount()},clear(){s.clear()},rerender(n){s.render(n)},rootNode:s.rootNode,unmount(){s.unmount()},waitUntilExit(){return s.waitUntilExit()},waitUntilRenderFlush(){return s.waitUntilRenderFlush()}}},Ji=(i={})=>i instanceof De?{stdin:E.stdin,stdout:i}:i,ts=(i,t)=>{const e=Ct.get(i);if(e===void 0){const s=t();return Ct.set(i,s),s}return E.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.
22
+ `),e};export{Os as default};
@@ -35,53 +35,53 @@ type RenderMetrics = {
35
35
  };
36
36
  type Options = {
37
37
  /**
38
- * 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.
39
- *
40
- * 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.
41
- *
42
- * 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.
43
- *
44
- Only works in interactive mode. Ignored when `interactive` is `false` or in a non-interactive environment (CI, piped stdout).
45
-
46
- 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.
47
-
48
- @default false
49
-
50
- @see {@link RenderOptions.alternateScreen}
51
- */
38
+ * 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.
39
+ *
40
+ * 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.
41
+ *
42
+ * 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.
43
+ *
44
+ * Only works in interactive mode. Ignored when `interactive` is `false` or in a non-interactive environment (CI, piped stdout).
45
+ *
46
+ * 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.
47
+ *
48
+ * @default false
49
+ *
50
+ * @see {@link RenderOptions.alternateScreen}
51
+ */
52
52
  alternateScreen?: boolean;
53
53
  /**
54
- * Enable React Concurrent Rendering mode.
55
- *
56
- * When enabled:
57
- * - Suspense boundaries work correctly with async data
58
- * - `useTransition` and `useDeferredValue` are fully functional
59
- - Updates can be interrupted for higher priority work
60
-
61
- 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.
62
-
63
- @default false
64
- @experimental
65
- */
54
+ * Enable React Concurrent Rendering mode.
55
+ *
56
+ * When enabled:
57
+ * - Suspense boundaries work correctly with async data
58
+ * - `useTransition` and `useDeferredValue` are fully functional
59
+ * - Updates can be interrupted for higher priority work
60
+ *
61
+ * 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.
62
+ *
63
+ * @default false
64
+ * @experimental
65
+ */
66
66
  concurrent?: boolean;
67
67
  debug: boolean;
68
68
  exitOnCtrlC: boolean;
69
69
  incrementalRendering?: boolean;
70
70
  /**
71
- * Override automatic interactive mode detection.
72
- *
73
- * 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.
74
- *
75
- * 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.
76
- *
77
- Set to `false` to force non-interactive mode or `true` to force interactive mode when the automatic detection doesn't suit your use case.
78
-
79
- 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.
80
-
81
- @default true (false if in CI or `stdout.isTTY` is falsy)
82
-
83
- @see {@link RenderOptions.interactive}
84
- */
71
+ * Override automatic interactive mode detection.
72
+ *
73
+ * 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.
74
+ *
75
+ * 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.
76
+ *
77
+ * Set to `false` to force non-interactive mode or `true` to force interactive mode when the automatic detection doesn't suit your use case.
78
+ *
79
+ * 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.
80
+ *
81
+ * @default true (false if in CI or `stdout.isTTY` is falsy)
82
+ *
83
+ * @see {@link RenderOptions.interactive}
84
+ */
85
85
  interactive?: boolean;
86
86
  isScreenReaderEnabled?: boolean;
87
87
  kittyKeyboard?: KittyKeyboardOptions;
@@ -231,6 +231,7 @@ declare class Ink {
231
231
  */
232
232
  private initDeferredKittyKeyboard;
233
233
  private confirmKittySupport;
234
+ private runKittySupportQuery;
234
235
  registerInputControl: (pauseInput: () => void, resumeInput: () => void) => void;
235
236
  /**
236
237
  * Hand terminal control to a child process, then restore Ink's rendering.
@@ -0,0 +1,44 @@
1
+ import { Writable } from 'node:stream';
2
+ type TerminalPalette = {
3
+ readonly background: string;
4
+ readonly colors: ReadonlyArray<string>;
5
+ readonly cursor: string;
6
+ readonly foreground: string;
7
+ };
8
+ /**
9
+ * Check if the terminal likely supports OSC palette queries.
10
+ * @returns Whether a palette query is worth attempting.
11
+ */
12
+ declare const isTerminalPaletteQuerySupported: () => boolean;
13
+ /**
14
+ * The slice of a readable stream a probe needs.
15
+ *
16
+ * Narrower than `NodeJS.ReadableStream` so a caller can hand in any object with these four members
17
+ * — a test double included — without asserting it is a full stream.
18
+ */
19
+ interface ProbeStdin {
20
+ listenerCount: (event: string) => number;
21
+ on: (event: "data", listener: (chunk: Buffer | string) => void) => unknown;
22
+ pause: () => unknown;
23
+ removeListener: (event: "data", listener: (chunk: Buffer | string) => void) => unknown;
24
+ unshift: (chunk: string) => void;
25
+ }
26
+ /**
27
+ * Query the terminal for its current color palette.
28
+ *
29
+ * All queries go out in a single write and are answered against one listener, so an unresponsive
30
+ * terminal costs one `timeout` rather than one per query. The probe is shared per output stream:
31
+ * concurrent callers collapse onto one round trip, and the answer is reused for the process
32
+ * lifetime because a terminal's palette does not change underneath a running program.
33
+ *
34
+ * `signal` unsubscribes *this* caller; it does not cancel the shared probe, so a component
35
+ * unmounting mid-flight cannot discard the answer every other component is waiting for.
36
+ * @param stdin Readable stream (typically process.stdin in raw mode)
37
+ * @param stdout Writable stream (typically process.stdout)
38
+ * @param timeout Timeout in milliseconds for the whole batch (default: 500). Ignored when a probe
39
+ * for this stream is already in flight.
40
+ * @param signal Stops waiting; resolves with an empty palette
41
+ * @returns The colours the terminal reported. Missing entries mean it did not answer.
42
+ */
43
+ declare const queryTerminalPalette: (stdin: ProbeStdin, stdout: Writable, timeout?: number, signal?: AbortSignal) => Promise<Partial<TerminalPalette>>;
44
+ export { TerminalPalette as T, isTerminalPaletteQuerySupported as i, queryTerminalPalette as q };
@@ -1,5 +1,5 @@
1
1
  import { ReactElement } from 'react';
2
- import { R as RenderOptions } from "../packem_shared/render.d-dEKhpngX.js";
2
+ import { R as RenderOptions } from "../packem_shared/render.d-tqP_-Le_.js";
3
3
  import "../packem_shared/dom.d-BV2bnRcH.js";
4
4
  import 'yoga-layout';
5
5
  import "../ink/public/cursor.js";
@@ -1 +1 @@
1
- import{createRequire as _}from"node:module";import x from"../packem_shared/render-DrIzCc0i.js";import{createKeySender as y}from"../packem_shared/KEY-DGV_trPu.js";import{KEY as O}from"../packem_shared/KEY-DGV_trPu.js";import{createScreen as T}from"../packem_shared/createScreen-BBvF-ZyU.js";import{waitFor as b}from"../packem_shared/waitFor-BjdYqkin.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)},c=F("node:events");class j extends c{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 c{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 c{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=[],M=(t,e={})=>{const{columns:n,options:d}=e,s=new j(n),m=new v(n),i=new R,o=x(t,{debug:!0,exitOnCtrlC:!1,patchConsole:!1,stderr:m,stdin:i,stdout:s,...d});u.push(o);const l=T(()=>s.lastFrame(),s.frames),p=y(r=>i.write(r)),h=async()=>{await new Promise(r=>{setTimeout(r,0)}),await new Promise(r=>{setTimeout(r,0)})};return{cleanup:o.cleanup,flush:h,get frames(){return s.frames},keys:p,lastFrame:()=>s.lastFrame(),rerender:o.rerender,screen:l,stderr:m,stdin:i,stdout:s,unmount:o.unmount,async waitFor(r,f){await b(r,()=>l.text(),f)}}},P=()=>{for(const t of u)t.cleanup();u.length=0};export{O as KEY,P as cleanup,y as createKeySender,T as createScreen,M as render,b as waitFor};
1
+ import{createRequire as _}from"node:module";import x from"../packem_shared/render-DGiSemZa.js";import{createKeySender as y}from"../packem_shared/KEY-DGV_trPu.js";import{KEY as O}from"../packem_shared/KEY-DGV_trPu.js";import{createScreen as T}from"../packem_shared/createScreen-BBvF-ZyU.js";import{waitFor as b}from"../packem_shared/waitFor-BjdYqkin.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)},c=F("node:events");class j extends c{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 c{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 c{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=[],M=(t,e={})=>{const{columns:n,options:d}=e,s=new j(n),m=new v(n),i=new R,o=x(t,{debug:!0,exitOnCtrlC:!1,patchConsole:!1,stderr:m,stdin:i,stdout:s,...d});u.push(o);const l=T(()=>s.lastFrame(),s.frames),p=y(r=>i.write(r)),h=async()=>{await new Promise(r=>{setTimeout(r,0)}),await new Promise(r=>{setTimeout(r,0)})};return{cleanup:o.cleanup,flush:h,get frames(){return s.frames},keys:p,lastFrame:()=>s.lastFrame(),rerender:o.rerender,screen:l,stderr:m,stdin:i,stdout:s,unmount:o.unmount,async waitFor(r,f){await b(r,()=>l.text(),f)}}},P=()=>{for(const t of u)t.cleanup();u.length=0};export{O as KEY,P as cleanup,y as createKeySender,T as createScreen,M 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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 4.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.3 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": "4.0.1",
3
+ "version": "4.0.3",
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,7 +286,7 @@
286
286
  "MIGRATION-GUIDE.md"
287
287
  ],
288
288
  "dependencies": {
289
- "@visulima/ansi": "4.1.0",
289
+ "@visulima/ansi": "4.2.0",
290
290
  "@visulima/colorize": "2.1.1",
291
291
  "@visulima/error": "6.1.0",
292
292
  "@visulima/string": "3.1.0",
@@ -316,14 +316,14 @@
316
316
  }
317
317
  },
318
318
  "optionalDependencies": {
319
- "@visulima/tui-binding-darwin-arm64": "4.0.1",
320
- "@visulima/tui-binding-darwin-x64": "4.0.1",
321
- "@visulima/tui-binding-linux-arm64-gnu": "4.0.1",
322
- "@visulima/tui-binding-linux-arm64-musl": "4.0.1",
323
- "@visulima/tui-binding-linux-x64-gnu": "4.0.1",
324
- "@visulima/tui-binding-linux-x64-musl": "4.0.1",
325
- "@visulima/tui-binding-win32-arm64-msvc": "4.0.1",
326
- "@visulima/tui-binding-win32-x64-msvc": "4.0.1"
319
+ "@visulima/tui-binding-darwin-arm64": "4.0.3",
320
+ "@visulima/tui-binding-linux-arm64-musl": "4.0.3",
321
+ "@visulima/tui-binding-linux-arm64-gnu": "4.0.3",
322
+ "@visulima/tui-binding-darwin-x64": "4.0.3",
323
+ "@visulima/tui-binding-linux-x64-gnu": "4.0.3",
324
+ "@visulima/tui-binding-linux-x64-musl": "4.0.3",
325
+ "@visulima/tui-binding-win32-x64-msvc": "4.0.3",
326
+ "@visulima/tui-binding-win32-arm64-msvc": "4.0.3"
327
327
  },
328
328
  "engines": {
329
329
  "node": "^22.14.0 || >=24.10.0"
@@ -1 +0,0 @@
1
- const u=t=>{const r=/rgb:([\da-f]{2,4})\/([\da-f]{2,4})\/([\da-f]{2,4})/i.exec(t);if(!r)return null;const o=n=>n.length<=2?n.padStart(2,"0"):n.slice(0,2);return`#${o(r[1])}${o(r[2])}${o(r[3])}`},S=()=>{const t=process.env.TERM_PROGRAM??"";return new Set(["Alacritty","contour","foot","Ghostty","iTerm2","iTerm.app","kitty","rio","WezTerm"]).has(t)?!0:(process.env.TERM??"").startsWith("xterm")||!!process.env.WT_SESSION};const f=(t,r,o,n=500)=>new Promise(a=>{let s="",i;const c=()=>{i&&clearTimeout(i),t.removeListener("data",e)},e=l=>{if(s+=l.toString(),s.length>256){c(),a(null);return}(s.includes("\x07")||s.includes("\x1B\\"))&&(c(),a(s))};i=setTimeout(()=>{c(),a(null)},n),t.on("data",e),r.write(o)}),E=async(t,r,o=500)=>{const n={},a=await f(t,r,"\x1B]10;?\x07",o);if(a){const e=u(a);e&&(n.foreground=e)}const s=await f(t,r,"\x1B]11;?\x07",o);if(s){const e=u(s);e&&(n.background=e)}const i=await f(t,r,"\x1B]12;?\x07",o);if(i){const e=u(i);e&&(n.cursor=e)}const c=[];for(let e=0;e<16;e++){const l=await f(t,r,`\x1B]4;${e};?\x07`,o);if(l){const p=u(l);c.push(p??"")}else c.push("")}return c.some(e=>e.length>0)&&(n.colors=c),n};export{S as isTerminalPaletteQuerySupported,E as queryTerminalPalette};
@@ -1,24 +0,0 @@
1
- import{createRequire as Me}from"node:module";import{jsx as B}from"react/jsx-runtime";import{cursorShow as ot,setMode as de,BracketedPasteMode as he,resetMode as fe,eraseLines as G,cursorHide as at,cursorUp as Xt,cursorNextLine as Ue,cursorTo as _e,eraseLineEnd as He,createDecMode as Ge,ALT_SCREEN_ON as Zt,clearScreenAndHomeCursor as Ke,ALT_SCREEN_OFF as Jt}from"@visulima/ansi";import{wordWrap as Ye}from"@visulima/string";import{ConcurrentRoot as qe,LegacyRoot as je}from"react-reconciler/constants.js";import W from"yoga-layout";import{a as ze}from"./accessibility-context-DDyHTwmA.js";import{useState as ht,useRef as N,useCallback as w,useEffect as ft,useMemo as _}from"react";import{a as $e}from"./animation-context-Icwf5tBE.js";import{A as Qe}from"./app-context-CfgsW0CV.js";import{C as Xe}from"./cursor-context-wLwblh2o.js";import Ze from"../components/error-boundary.js";import{F as Je}from"./focus-context-8h3hmNxy.js";import{S as ti}from"./stderr-context-Xeacf3Ir.js";import{S as ei}from"./stdin-context-Ceh-YuU1.js";import{S as ii}from"./stdout-context-BhxOwdNK.js";import{O as si,a as ni,b as ri,r as oi}from"./renderer-D97BmOBO.js";import{c as ai,e as ui}from"./dom-xpeZzKuf.js";import{resolveFlags as te}from"./kittyFlags-jpd_IAFL.js";import{buildReturnToBottomPrefix as gt,buildCursorSuffix as nt,cursorPositionChanged as vt,buildCursorOnlySequence as pe,buildCursorShapeSequence as ee}from"./buildCursorOnlySequence-D24o0D7-.js";import{l as ci}from"./load-native-root-binding-B1WunHs4.js";import{a as li}from"./measure-text-DtlK6gar.js";import{r as D,s as di}from"./reconciler-BPm7fZa6.js";import{measureAndExtractObservers as hi}from"./ResizeObserver-ClWoCtGV.js";import{calculateScroll as fi}from"./calculateScroll-jdxVlcmq.js";import{g as z}from"./utils-BlDbvbdr.js";let Be;const Fe=i=>(Be??=Me(import.meta.url))(i),Q=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,yt=i=>{if(typeof Q<"u"&&Q.versions&&Q.versions.node){const[t,e]=Q.versions.node.split(".").map(Number);if(t>22||t===22&&e>=3||t===20&&e>=16)return Q.getBuiltinModule(i)}return Fe(i)},k=Q,{env:xt}=k,{PassThrough:$t,Stream:Ae}=yt("node:stream"),{Buffer:Qt}=yt("node:buffer"),{Console:We}=yt("node:console"),{EventEmitter:Ve}=yt("node:events"),ie=i=>i in xt&&xt[i]!=="0"&&xt[i]!=="false",me=ie("CI")||ie("CONTINUOUS_INTEGRATION"),se=["assert","count","countReset","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","table","time","timeEnd","timeLog","trace","warn"];let Rt={};const pi=i=>{const t=new $t,e=new $t;t.write=n=>{i("stdout",n)},e.write=n=>{i("stderr",n)};const s=new console.Console(t,e);for(const n of se)Rt[n]=console[n],console[n]=s[n];return()=>{for(const n of se)console[n]=Rt[n];Rt={}}},X=[];X.push("SIGHUP","SIGINT","SIGTERM");process.platform!=="win32"&&X.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&X.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",Tt=Symbol.for("signal-exit emitter"),Ct=globalThis,mi=Object.defineProperty.bind(Object);class gi{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(Ct[Tt])return Ct[Tt];mi(Ct,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],n=s.indexOf(e);n!==-1&&(n===0&&s.length===1?s.length=0:s.splice(n,1))}emit(t,e,s){if(this.emitted[t])return!1;this.emitted[t]=!0;let n=!1;for(const o of this.listeners[t])n=o(e,s)===!0||n;return t==="exit"&&(n=this.emit("afterExit",e,s)||n),n}}class ge{}const vi=i=>({onExit(t,e){return i.onExit(t,e)},load(){return i.load()},unload(){return i.unload()}});class wi extends ge{onExit(){return()=>{}}load(){}unload(){}}class bi extends ge{#o=Ot.platform==="win32"?"SIGINT":"SIGHUP";#e=new gi;#t;#n;#r;#s={};#i=!1;constructor(t){super(),this.#t=t,this.#s={};for(const e of X)this.#s[e]=()=>{const s=this.#t.listeners(e);let{count:n}=this.#e;const o=t;if(typeof o.__signal_exit_emitter__=="object"&&typeof o.__signal_exit_emitter__.count=="number"&&(n+=o.__signal_exit_emitter__.count),s.length===n){this.unload();const u=this.#e.emit("exit",null,e),r=e==="SIGHUP"?this.#o:e;u||t.kill(t.pid,r)}};this.#r=t.reallyExit,this.#n=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 X)try{const e=this.#s[t];e&&this.#t.on(t,e)}catch{}this.#t.emit=(t,...e)=>this.#u(t,...e),this.#t.reallyExit=t=>this.#a(t)}}unload(){this.#i&&(this.#i=!1,X.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.#n,this.#t.reallyExit=this.#r,this.#e.count-=1)}#a(t){return mt(this.#t)?(this.#t.exitCode=t||0,this.#e.emit("exit",this.#t.exitCode,null),this.#r.call(this.#t,this.#t.exitCode)):0}#u(t,...e){const s=this.#n;if(t==="exit"&&mt(this.#t)){typeof e[0]=="number"&&(this.#t.exitCode=e[0]);const n=s.call(this.#t,t,...e);return this.#e.emit("exit",this.#t.exitCode,null),n}else return s.call(this.#t,t,...e)}}const Ot=globalThis.process,{onExit:yi}=vi(mt(Ot)?new bi(Ot):new wi),wt="\x1B",ve="\x1B[200~",ne="\x1B[201~",Si=i=>i>=48&&i<=63,xi=i=>i>=32&&i<=47,we=i=>i>=64&&i<=126,Ri=(i,t,e)=>{const s=t+e+1;let n=s;for(;n<i.length;n++){const o=i.codePointAt(n);if(o===void 0)return"pending";if(!(Si(o)||xi(o))&&!(o===91&&n===s))return we(o)?{nextIndex:n+1,sequence:i.slice(t,n+1)}:void 0}return"pending"},Ti=(i,t,e)=>{const s=t+e+2;if(s>i.length)return"pending";const n=i.codePointAt(s-1);if(!(n===void 0||!we(n)))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 Ri(i,t,e);if(s==="O")return Ti(i,t,e)},Ci=(i,t)=>{const e=i.codePointAt(t+1),s=e!==void 0&&e>65535?2:1,n=t+1+s;return{nextIndex:n,sequence:i.slice(t,n)}},Ei=(i,t)=>{if(t===i.length-1)return"pending";if(i[t+1]===wt){if(t+2>=i.length)return"pending";const n=re(i,t,2);return n==="pending"?"pending":n||{nextIndex:t+2,sequence:i.slice(t,t+2)}}const s=re(i,t,1);return s==="pending"?"pending":s||Ci(i,t)},oe=(i,t)=>{let e=0;for(let s=0;s<i.length;s++){const n=i[s];(n===""||n==="\b")&&(s>e&&t.push(i.slice(e,s)),t.push(n),e=s+1)}e<i.length&&t.push(i.slice(e))},Pi=i=>{const t=[];let e=0;const s=n=>({events:t,pending:i.slice(n)});for(;e<i.length;){const n=i.indexOf(wt,e);if(n===-1)return oe(i.slice(e),t),{events:t,pending:""};n>e&&oe(i.slice(e,n),t);const o=Ei(i,n);if(o==="pending")return s(n);if(o.sequence===ve){const u=o.nextIndex,r=i.indexOf(ne,u);if(r===-1)return s(n);t.push({paste:i.slice(u,r)}),e=r+ne.length;continue}t.push(o.sequence),e=o.nextIndex}return{events:t,pending:""}},Oi=()=>{let i="";return{flushPendingEscape(){if(!i.startsWith(wt))return;const t=i;return i="",t},hasPendingEscape(){return i.startsWith(wt)&&!i.startsWith(ve)&&i!=="\x1B[200"},push(t){const e=Pi(i+t);return i=e.pending,e.events},reset(){i=""}}},Ii=" ",Ni="\x1B[Z",ki="\x1B",ae=de(he),Et=fe(he),be=({children:i,exitOnCtrlC:t,interactive:e,onExit:s,onRegisterInputControl:n,onSuspendTerminal:o,onWaitUntilRenderFlush:u,renderThrottleMs:r,setCursorPosition:a,stderr:f,stdin:h,stdout:m,writeToStderr:v,writeToStdout:d})=>{const[l,b]=ht(!0),[y,S]=ht(void 0),[,C]=ht([]),F=N(0),E=N([]),A=N(new Map),O=N(void 0),I=N(0),L=N(!1),R=N(0),[P]=ht(()=>{const c=new Ve;return c.setMaxListeners(1/0),c}),Z=N(void 0),J=N(void 0);J.current??=Oi();const tt=N(void 0),Nt=N(!1),Te=20,K=w(()=>{tt.current&&(clearTimeout(tt.current),tt.current=void 0)},[]),Y=w(()=>{O.current&&(clearTimeout(O.current),O.current=void 0)},[]),ut=w(()=>{if(Y(),A.current.size===0)return;let c=Number.POSITIVE_INFINITY;for(const p of A.current.values())c=Math.min(c,p.nextDueTime);const g=Math.max(0,c-performance.now());O.current=setTimeout(()=>{O.current=void 0;const p=performance.now(),x=[...A.current.values()];for(const T of x){if(p<T.nextDueTime)continue;T.callback(p);const Le=p-T.startTime,De=Math.floor(Le/T.interval)+1;T.nextDueTime=T.startTime+De*T.interval}ut()},g)},[Y]),kt=w((c,g)=>{const p=performance.now();return A.current.set(c,{callback:c,interval:g,nextDueTime:p+g,startTime:p}),ut(),{startTime:p,unsubscribe(){if(A.current.delete(c),A.current.size===0){Y();return}ut()}}},[Y,ut]);ft(()=>()=>{Y()},[Y]);const M=h.isTTY,Lt=w(()=>{Z.current&&(h.removeListener("readable",Z.current),Z.current=void 0)},[h]),q=w(()=>{J.current?.reset(),K(),Lt()},[K,Lt]),j=w(()=>{L.current=!1,h.setRawMode(!1),h.unref(),I.current=0,q()},[h,q]),et=w(c=>{M&&(I.current>0||L.current)&&j(),s(c)},[M,j,s]),Dt=w(c=>{if(c.includes("")&&t){et();return}c===ki&&l&&S(g=>{if(!g)return g})},[t,et,l]),it=w(c=>{Dt(c),P.emit("input",c)},[Dt,P]),Mt=w(()=>{K(),tt.current=setTimeout(()=>{tt.current=void 0;const c=J.current.flushPendingEscape();c&&it(c)},Te)},[K,it]),St=w(()=>{K();let c;for(;(c=h.read())!==null;){const g=J.current.push(c);for(const p of g)if(typeof p=="string")it(p);else{if(P.listenerCount("paste")===0){Nt.current||(Nt.current=!0,v(`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}P.emit("paste",p.paste)}}J.current.hasPendingEscape()&&Mt()},[h,it,K,Mt,v,P]),ct=w(()=>{Z.current||(Z.current=St,h.addListener("readable",St))},[h,St]),Bt=w(c=>{if(!M)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"),c){if(I.current===0){const g=L.current;L.current=!1,g||(h.ref(),h.setRawMode(!0)),ct()}I.current++;return}I.current!==0&&--I.current===0&&(q(),L.current=!0,queueMicrotask(()=>{L.current&&j()}))},[M,h,ct,q,j]),Ft=w(c=>{if(m.isTTY){if(c){R.current===0&&m.write(ae),R.current++;return}R.current!==0&&--R.current===0&&m.write(Et)}},[m]),At=N({bracketedPaste:!1,rawMode:!1}),Wt=w(()=>{const c=M&&(I.current>0||L.current),g=R.current>0;At.current={bracketedPaste:g,rawMode:c},g&&m.isTTY&&m.write(Et),c&&(L.current=!1,q(),h.setRawMode(!1),h.unref())},[M,m,h,q]),Ut=w(()=>{const{bracketedPaste:c,rawMode:g}=At.current;g&&(h.ref(),h.setRawMode(!0),h.setEncoding("utf8"),ct()),c&&m.isTTY&&m.write(ae)},[h,m,ct]);ft(()=>{n(Wt,Ut)},[n,Wt,Ut]);const _t=w((c,g)=>{const p=c.findIndex(x=>x.id===g);for(let x=p+1;x<c.length;x++){const T=c[x];if(T?.isActive)return T.id}},[]),Ht=w((c,g)=>{const p=c.findIndex(x=>x.id===g);for(let x=p-1;x>=0;x--){const T=c[x];if(T?.isActive)return T.id}},[]),lt=w(()=>{const c=E.current;S(g=>{const p=c.find(T=>T.isActive)?.id;return _t(c,g)??p})},[_t]),dt=w(()=>{const c=E.current;S(g=>{const p=c.findLast(T=>T.isActive)?.id;return Ht(c,g)??p})},[Ht]);ft(()=>{const c=p=>{!l||F.current===0||(p===Ii&&lt(),p===Ni&&dt())};P.on("input",c);const g=P;return()=>{g.off("input",c)}},[l,lt,dt,P]);const Gt=w(()=>{b(!0)},[]),Kt=w(()=>{b(!1)},[]),Yt=w(c=>{E.current.some(p=>p?.id===c)&&S(c)},[]),qt=w((c,{autoFocus:g})=>{const p=[...E.current,{id:c,isActive:!0}];F.current=p.length,E.current=p,C(p),g&&S(x=>x||c)},[]),jt=w(c=>{S(p=>{if(p!==c)return p});const g=E.current.filter(p=>p.id!==c);F.current=g.length,E.current=g,C(g)},[]),zt=w(c=>{const g=E.current.map(p=>p.id!==c?p:{id:c,isActive:!0});E.current=g,C(g)},[]),Vt=w(c=>{S(p=>{if(p!==c)return p});const g=E.current.map(p=>p.id!==c?p:{id:c,isActive:!1});E.current=g,C(g)},[]);ft(()=>()=>{const c=!m.destroyed&&!m.writableEnded;e&&c&&m.write(ot),M&&(I.current>0||L.current)&&j(),R.current>0&&(m.isTTY&&c&&m.write(Et),R.current=0)},[m,M,j,e]);const Ce=_(()=>({exit:et,suspendTerminal:o,waitUntilRenderFlush:u}),[et,o,u]),Ee=_(()=>({internal_eventEmitter:P,internal_exitOnCtrlC:t,isRawModeSupported:M,setBracketedPasteMode:Ft,setRawMode:Bt,stdin:h}),[h,Bt,Ft,M,t,P]),Pe=_(()=>({stdout:m,write:d}),[m,d]),Oe=_(()=>({stderr:f,write:v}),[f,v]),Ie=_(()=>({setCursorPosition:a}),[a]),Ne=_(()=>({activate:zt,activeId:y,add:qt,deactivate:Vt,disableFocus:Kt,enableFocus:Gt,focus:Yt,focusNext:lt,focusPrevious:dt,remove:jt}),[y,qt,jt,zt,Vt,Gt,Kt,lt,dt,Yt]),ke=_(()=>({renderThrottleMs:r,subscribe:kt}),[kt,r]);return B(Qe.Provider,{value:Ce,children:B(ei.Provider,{value:Ee,children:B(ii.Provider,{value:Pe,children:B(ti.Provider,{value:Oe,children:B(Je.Provider,{value:Ne,children:B($e.Provider,{value:ke,children:B(Xe.Provider,{value:Ie,children:B(Ze,{onError:et,children:i})})})})})})})})};be.displayName="InternalApp";const Li=(i,t,e)=>{if(e<=0||!i.yogaNode)return"";const{yogaNode:s}=i,n=s.getComputedBorder(W.EDGE_LEFT),o=s.getComputedBorder(W.EDGE_RIGHT),u=s.getComputedBorder(W.EDGE_TOP),r=s.getComputedPadding(W.EDGE_LEFT),a=s.getComputedPadding(W.EDGE_RIGHT),f=s.getComputedPadding(W.EDGE_TOP),h=Math.round(s.getComputedWidth()-n-o-r-a);if(h<=0)return"";const m=new si({height:e,width:h}),d=-(i.internal_scrollState?.scrollLeft??0)-n-r,l=-t-u-f;for(const b of i.childNodes)ni(b,m,{absoluteOffsetX:d,absoluteOffsetY:l,offsetX:d,offsetY:l,skipStaticElements:!1});return m.get().output},It=new WeakMap,V=i=>i??"default",ye=()=>{let i,t;return{consumeDelta:()=>{if(V(t)===V(i))return"";const e=V(t);return i=t,ee(e)},consumeRestoreOnDone:()=>{const e=V(i)!=="default";return i=void 0,t=void 0,e?ee("default"):""},isDirty:()=>V(t)!==V(i),setPending:e=>{t=e}}},rt=(i,t)=>t.endsWith(`
5
- `)?i.length-1:i.length,Se=i=>i.rows||1/0,bt=(i,t)=>Math.min(i,Se(t)),Di=(i,{showCursor:t=!1}={})=>{let e=0,s="",n=!1,o,u=!1,r,a=!1;const f=ye(),h=()=>u?o:void 0,m=(d,l)=>{const b=vt(l,r);return d!==s||b||f.isDirty()},v=d=>{!t&&!n&&(i.write(at),n=!0);const l=h();u=!1;const b=vt(l,r);if(!m(d,l))return!1;const y=f.consumeDelta(),S=d.split(`
6
- `),C=rt(S,d),F=nt(C,l);if(d===s&&b)i.write(y+pe({cursorPosition:l,cursorWasShown:a,previousCursorPosition:r,previousLineCount:e,visibleLineCount:C}));else if(d===s&&y!=="")i.write(y);else{s=d;const E=gt(a,e,r);i.write(y+E+G(bt(e,i))+d+F),e=S.length}return r=l?{...l}:void 0,a=l!==void 0,!0};return v.clear=()=>{const d=gt(a,e,r);i.write(d+G(bt(e,i))),s="",e=0,r=void 0,a=!1},v.done=()=>{s="",e=0,r=void 0,a=!1;const d=f.consumeRestoreOnDone();d!==""&&i.write(d),t||(i.write(ot),n=!1)},v.reset=()=>{s="",e=0,r=void 0,a=!1},v.sync=d=>{const l=u?o:void 0;u=!1;const b=d.split(`
7
- `);s=d,e=b.length;const y=f.consumeDelta();y!==""&&i.write(y),!l&&a&&i.write(at),l&&i.write(nt(rt(b,d),l)),r=l?{...l}:void 0,a=l!==void 0},v.setCursorPosition=d=>{o=d,u=!0},v.setCursorShape=f.setPending,v.isCursorDirty=()=>u||f.isDirty(),v.willRender=d=>m(d,h()),v},Mi=(i,{showCursor:t=!1}={})=>{let e=[],s="",n=!1,o,u=!1,r,a=!1;const f=ye(),h=()=>u?o:void 0,m=(d,l)=>{const b=vt(l,r);return d!==s||b||f.isDirty()},v=d=>{!t&&!n&&(i.write(at),n=!0);const l=h();u=!1;const b=vt(l,r);if(!m(d,l))return!1;const y=f.consumeDelta(),S=d.split(`
8
- `),C=rt(S,d),F=rt(e,s);if(d===s&&b)return i.write(y+pe({cursorPosition:l,cursorWasShown:a,previousCursorPosition:r,previousLineCount:e.length,visibleLineCount:C})),r=l?{...l}:void 0,a=l!==void 0,!0;if(d===s&&y!=="")return i.write(y),!0;const E=gt(a,e.length,r);if(d===`
9
- `||s.length===0){const R=nt(C,l);return i.write(y+E+G(bt(e.length,i))+d+R),a=l!==void 0,r=l?{...l}:void 0,s=d,e=S,!0}const A=d.endsWith(`
10
- `),O=[y,E],I=Se(i);if(C<F){const P=s.endsWith(`
11
- `)?1:0;O.push(G(Math.min(F-C+P,I)),Xt(Math.min(C,I-1)))}else O.push(Xt(Math.min(F-1,I-1)));for(let R=0;R<C;R++){const P=R===C-1;if(S[R]===e[R]){(!P||A)&&O.push(Ue());continue}O.push(_e(0)+S[R]+He+(P&&!A?"":`
12
- `))}const L=nt(C,l);return O.push(L),i.write(O.join("")),a=l!==void 0,r=l?{...l}:void 0,s=d,e=S,!0};return v.clear=()=>{const d=gt(a,e.length,r);i.write(d+G(bt(e.length,i))),s="",e=[],r=void 0,a=!1},v.done=()=>{s="",e=[],r=void 0,a=!1;const d=f.consumeRestoreOnDone();d!==""&&i.write(d),t||(i.write(ot),n=!1)},v.reset=()=>{s="",e=[],r=void 0,a=!1},v.sync=d=>{const l=u?o:void 0;u=!1;const b=d.split(`
13
- `);s=d,e=b;const y=f.consumeDelta();y!==""&&i.write(y),!l&&a&&i.write(at),l&&i.write(nt(rt(b,d),l)),r=l?{...l}:void 0,a=l!==void 0},v.setCursorPosition=d=>{o=d,u=!0},v.setCursorShape=f.setPending,v.isCursorDirty=()=>u||f.isDirty(),v.willRender=d=>m(d,h()),v},Bi=(i,{incremental:t=!1,showCursor:e=!1}={})=>t?Mi(i,{showCursor:e}):Di(i,{showCursor:e}),Fi={create:Bi},xe=Ge(2026),H=de(xe),U=fe(xe);function Ai(i,t){return"isTTY"in i&&i.isTTY&&(t??!me)}let $;const Wi=()=>{if($!==!1){if($!==void 0)return $;try{return $=ci(import.meta.url).Renderer,$}catch{$=!1;return}}},Ui=i=>{const t=Wi();if(!t)return;let e,s=0,n=0;const o=(u,r)=>{(!e||s!==u||n!==r)&&(e?e.resize(u,r):e=new t(u,r),s=u,n=r)};return{clear(){if(e){const u=new Uint32Array(s*n*2),r=65535;for(let a=0;a<u.length;a+=2)u[a]=32,u[a+1]=r;e.render(u)}},destroy(){e=void 0},render(u,r,a){if(o(r,a),!!e){i.isTTY&&e.writeRaw(H);try{e.render(u)}finally{i.isTTY&&e.writeRaw(U)}}},resize(u,r){o(u,r)}}};function ue(i,t=0,e={}){const s=e.leading??!0,n=e.trailing??!0;let o,u,r,a;const f=()=>{if(u===void 0)return;const l=u;u=void 0,a=i(...l)},h=()=>{o!==void 0&&(clearTimeout(o),o=void 0)},m=()=>{o=void 0,n&&f(),u=void 0,r=void 0},v=()=>{h(),o=setTimeout(m,t)},d=function(...b){const y=Date.now();if(r??=y,y-r>=t)return u=b,f(),r=y,v(),a;u=b;const S=o===void 0;return v(),s&&S&&f(),a};return d.cancel=()=>{h(),u=void 0,r=void 0},d.flush=()=>(h(),f(),r=void 0,a),d}console.Console||(console.Console=We);const st=()=>{},ce=async()=>new Promise(i=>{setImmediate(i)}),_i=27,Hi=91,Gi=63,Ki=117,Yi=48,qi=57,ji=i=>i>=Yi&&i<=qi,Re=(i,t)=>{if(i[t]!==_i||i[t+1]!==Hi||i[t+2]!==Gi)return;let e=t+3;const s=e;for(;e<i.length&&ji(i[e]);)e++;if(e!==s){if(e===i.length)return{state:"partial"};if(i[e]===Ki)return{endIndex:e,state:"complete"}}},zi=i=>{for(let t=0;t<i.length;t++)if(Re(i,t)?.state==="complete")return!0;return!1},Vi=i=>{const t=[];let e=0;for(;e<i.length;){const s=Re(i,e);if(s?.state==="complete"){e=s.endIndex+1;continue}if(s?.state==="partial")break;t.push(i[e]),e++}return t},$i=({isTty:i,isUnmounting:t,isWindows:e,nextOutputHeight:s,previousOutputHeight:n,viewportRows:o})=>{if(!i)return!1;const u=n>0,r=n>=o,a=s>=o,f=n>o,h=s>o,m=r&&s<o;return f||h&&u||m||t&&r||e&&(a||r)},Pt=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 Qi{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=ai("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,n=s>0?Math.max(1,Math.ceil(1e3/s)):0;this.renderThrottleMs=e?0:n;const o=e?this.onRender:(()=>{const r=ue(this.onRender,n,{leading:!0,trailing:!0});return this.throttledOnRender=r,()=>{this.hasPendingThrottledRender=!0,r()}})();if(e&&(this.throttledOnRender=void 0),t.standardReactLayoutTiming){let r=!1;const a=()=>{r||(r=!0,queueMicrotask(()=>{r=!1,this.onRender()}))};this.rootNode.onRender=a,this.rootNode.onImmediateRender=a}else this.rootNode.onRender=o,this.rootNode.onImmediateRender=this.onRender;this.rootNode.onStaticChange=this.handleStaticChange,this.log=Fi.create(t.stdout,{incremental:t.incrementalRendering}),this.useNativeRenderer=t.useNativeRenderer??!1,this.useNativeRenderer&&(this.nativeLog=Ui(t.stdout),this.nativeLog||(this.useNativeRenderer=!1)),this.manualCursorPosition=void 0,this.renderedCursorPosition=void 0,this.renderedCursorRequested=!1,this.throttledLog=e?this.log:ue(r=>{const a=this.log.willRender(r),f=this.shouldSync();f&&a&&this.options.stdout.write(H),this.log(r),f&&a&&this.options.stdout.write(U)},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=z(this.options.stdout).columns,this.fullStaticOutput="";const u=t.concurrent?qe:je;this.container=D.createContainer(this.rootNode,u,null,!1,null,"id",()=>{},()=>{},()=>{},()=>{}),this.unsubscribeExit=yi(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"&&D.injectIntoDevTools(),this.exitPromise=new Promise((r,a)=>{this.resolveExitPromise=r,this.rejectExitPromise=a}),this.exitPromise.catch(st)}runDeferredInit(){this.deferredInitDone||(this.deferredInitDone=!0,this.initDeferredKittyKeyboard())}resized=()=>{const t=z(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(Pt(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 n=new Map;this.calculateScrollAndTriggerObservers(s,n);for(const[o,u]of n)o.internalTrigger(u)};this.backbufferNode=void 0,this.prepareYogaTree(this.rootNode,t);const e=z(this.options.stdout).columns;this.rootNode.yogaNode.setWidth(e),this.rootNode.yogaNode.calculateLayout(void 0,void 0,W.DIRECTION_LTR),t(this.rootNode)};calculateScrollAndTriggerObservers(t,e){if(t.nodeName==="ink-box"){const{style:s}=t,n=s.overflow??"visible",o=s.overflowX??n,u=s.overflowY??n;o==="scroll"||u==="scroll"?(fi(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(hi(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 n of t.childNodes){const o=n;n.nodeName!=="#text"&&o.yogaNode&&(t.yogaNode.insertChild(o.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=z(this.options.stdout).columns,{width:n}=t.style;t.yogaNode&&(t.yogaNode.setWidth(typeof n=="number"?n:s),t.yogaNode.calculateLayout(void 0,void 0,W.DIRECTION_LTR)),e(t),ri(t,{skipStaticElements:!1,trackSelection:this.options.trackSelection}),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(W.EDGE_TOP)??0,n=Math.max(0,e-Math.round(s)),o=t.internal_maxPushedScrollTop??0,{maxScrollbackLength:u}=t.style,r=u===void 0?o:Math.max(o,n-Math.max(0,u)),a=n-r;if(a<=0)return"";const f=Li(t,r,a);return f===""?"":(t.internal_maxPushedScrollTop=n,`${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:n,output:o,outputBuffer:u,outputHeight:r,outputWidth:a,staticOutput:f}=t;this.renderedCursorRequested=s,this.renderedCursorPosition=e,this.log.setCursorShape(s?n:void 0);const h=this.computeBackbufferOutput();if(this.useNativeRenderer&&this.nativeLog&&u&&a){f&&f!==`
16
- `&&this.options.stdout.write(f),h&&this.options.stdout.write(h),this.nativeLog.render(u,a,r),this.lastOutputHeight=r;return}s&&this.log.setCursorPosition(this.getActiveCursorPosition());const m=f&&f!==`
17
- `;if(this.options.debug){m&&(this.fullStaticOutput+=f),this.lastOutput=o,this.lastOutputToRender=o,this.lastOutputHeight=r,this.options.stdout.write(this.fullStaticOutput+o);return}if(!this.interactive){m&&this.options.stdout.write(f),this.lastOutput=o,this.lastOutputToRender=`${o}
18
- `,this.lastOutputHeight=r;return}if(this.isScreenReaderEnabled){const v=this.shouldSync();if(v&&this.options.stdout.write(H),m){const b=this.lastOutputHeight>0?G(this.lastOutputHeight):"";this.options.stdout.write(b+f),this.lastOutputHeight=0}if(o===this.lastOutput&&!m){v&&this.options.stdout.write(U);return}const d=z(this.options.stdout).columns,l=Ye(o,{trim:!1,width:d,wrapMode:"BREAK_WORDS"}).replace(/\n$/,"");if(m)this.options.stdout.write(l);else{const b=this.lastOutputHeight>0?G(this.lastOutputHeight):"";this.options.stdout.write(b+l)}this.lastOutput=o,this.lastOutputToRender=l,this.lastOutputHeight=l===""?0:l.split(`
19
- `).length,v&&this.options.stdout.write(U);return}m&&(this.fullStaticOutput+=f),this.renderInteractiveFrame(o,r,m?f:"",h)};accessibilityContextValue;render(t){this.accessibilityContextValue??={isScreenReaderEnabled:this.isScreenReaderEnabled};const e=B(ze.Provider,{value:this.accessibilityContextValue,children:B(be,{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?D.updateContainer(e,this.container,null,st):(D.updateContainerSync(e,this.container,null,st),D.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(U)};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(U)};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:n}=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 o=()=>{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,It.delete(this.options.stdout);const{exitResult:r}=this,a=()=>{Pt(t)?this.rejectExitPromise(t):this.resolveExitPromise(r)};t!==void 0&&!Pt(t)?a():s&&n?this.options.stdout.write("",a):setImmediate(a)},u=D;this.options.concurrent?(D.updateContainerSync(null,this.container,null,st),D.flushSyncWork(),u.flushPassiveEffects?.(),o()):(D.updateContainerSync(null,this.container,null,st),D.flushSyncWork(),o())};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 ce(),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}D.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(n=>{this.options.stdout.write("",()=>{n()})});return}await ce()}clear(){this.interactive&&!this.options.debug&&(this.log.clear(),this.log.sync(this.lastOutputToRender||`${this.lastOutput}
22
- `))}patchConsole(){this.options.debug||(this.restoreConsole=pi((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,Zt),this.writeBestEffort(this.options.stdout,at))}resolveInteractiveOption(t){return t??(!me&&!!this.options.stdout.isTTY)}resolveAlternateScreenOption(t,e){return!!t&&e&&!!this.options.stdout.isTTY}shouldSync(){return Ai(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,n=""){const o=s+n,u=o!=="",r=this.options.stdout.isTTY,a=r?z(this.options.stdout).rows:24,f=r&&e>=a,h=f?t:`${t}
23
- `,m=k.platform==="win32",v=r&&m&&(f||this.lastOutputHeight>=a);if($i({isTty:r,isUnmounting:this.isUnmounting,isWindows:m,nextOutputHeight:e,previousOutputHeight:this.lastOutputHeight,viewportRows:a})){if(this.options.incrementalRendering&&!v){u&&(this.log.clear(),this.options.stdout.write(o)),(t!==this.lastOutput||this.log.isCursorDirty()||u)&&this.throttledLog(h),this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e;return}const l=this.shouldSync();l&&this.options.stdout.write(H),this.options.stdout.write(Ke+this.fullStaticOutput+n+h),this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e,this.log.sync(h),l&&this.options.stdout.write(U);return}if(u){const l=this.shouldSync();l&&this.options.stdout.write(H),this.log.clear(),this.options.stdout.write(o),this.log(h),l&&this.options.stdout.write(U)}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 s=t.flags??["disambiguateEscapeCodes"];this.options.stdin.isTTY&&this.options.stdout.isTTY&&this.enableKittyProtocol(s)}initDeferredKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="auto")return;const s=t.flags??["disambiguateEscapeCodes"];!this.interactive||!this.options.stdin.isTTY||!this.options.stdout.isTTY||this.confirmKittySupport(s)}confirmKittySupport(t){const{stdin:e,stdout:s}=this.options;let n=[];const o=()=>{this.cancelKittyDetection=void 0,clearTimeout(r),e.removeListener("data",u);const a=Vi(n);n=[],a.length>0&&e.unshift(Qt.from(a))},u=a=>{const f=typeof a=="string"?Qt.from(a):a;for(const h of f)n.push(h);zi(n)&&(o(),this.isUnmounted||this.enableKittyProtocol(t))};e.on("data",u);const r=setTimeout(o,200);this.cancelKittyDetection=o,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,Zt),this.kittyProtocolEnabled&&this.kittyFlags&&this.writeBestEffort(this.options.stdout,`\x1B[>${te(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[>${te(t)}u`),this.kittyProtocolEnabled=!0}}const Cs=(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=Zi(e.stdout,()=>new Qi(e));return s.render(i),{cleanup(){s.unmount()},clear(){s.clear()},rerender(n){s.render(n)},rootNode:s.rootNode,unmount(){s.unmount()},waitUntilExit(){return s.waitUntilExit()},waitUntilRenderFlush(){return s.waitUntilRenderFlush()}}},Xi=(i={})=>i instanceof Ae?{stdin:k.stdin,stdout:i}:i,Zi=(i,t)=>{const e=It.get(i);if(e===void 0){const s=t();return It.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{Cs as default};
@@ -1,19 +0,0 @@
1
- import { Writable } from 'node:stream';
2
- type TerminalPalette = {
3
- readonly background: string;
4
- readonly colors: ReadonlyArray<string>;
5
- readonly cursor: string;
6
- readonly foreground: string;
7
- };
8
- /**
9
- * Check if the terminal likely supports OSC palette queries.
10
- */
11
- declare const isTerminalPaletteQuerySupported: () => boolean;
12
- /**
13
- * Query the terminal for its current color palette.
14
- * @param stdin Readable stream (typically process.stdin in raw mode)
15
- * @param stdout Writable stream (typically process.stdout)
16
- * @param timeout Per-query timeout in milliseconds (default: 500)
17
- */
18
- declare const queryTerminalPalette: (stdin: NodeJS.ReadableStream, stdout: Writable, timeout?: number) => Promise<Partial<TerminalPalette>>;
19
- export { TerminalPalette as T, isTerminalPaletteQuerySupported as i, queryTerminalPalette as q };