@visulima/tui 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/components/box.d.ts +25 -25
- package/dist/components/canvas.d.ts +26 -31
- package/dist/components/cursor.d.ts +39 -44
- package/dist/components/error-overview.d.ts +1 -3
- package/dist/components/error-overview.js +1 -1
- package/dist/components/newline.d.ts +6 -8
- package/dist/components/spacer.d.ts +4 -4
- package/dist/components/static-render.d.ts +9 -40
- package/dist/components/static.d.ts +13 -13
- package/dist/components/text.d.ts +34 -47
- package/dist/components/transform.d.ts +7 -11
- package/dist/core/index.d.ts +11 -11
- package/dist/core/index.js +1 -1
- package/dist/ink/canvas/index.d.ts +10 -10
- package/dist/ink/hooks/use-animation.d.ts +22 -22
- package/dist/ink/hooks/use-app.d.ts +3 -3
- package/dist/ink/hooks/use-box-metrics.d.ts +16 -16
- package/dist/ink/hooks/use-clipboard.d.ts +16 -16
- package/dist/ink/hooks/use-color-blindness.d.ts +16 -16
- package/dist/ink/hooks/use-console-capture.d.ts +19 -19
- package/dist/ink/hooks/use-cursor.d.ts +6 -6
- package/dist/ink/hooks/use-focus-manager.d.ts +25 -25
- package/dist/ink/hooks/use-focus.d.ts +14 -18
- package/dist/ink/hooks/use-form.d.ts +32 -32
- package/dist/ink/hooks/use-hotkey.d.ts +17 -17
- package/dist/ink/hooks/use-input.d.ts +92 -92
- package/dist/ink/hooks/use-input.js +2 -2
- package/dist/ink/hooks/use-interval.d.ts +14 -14
- package/dist/ink/hooks/use-is-screen-reader-enabled.d.ts +3 -3
- package/dist/ink/hooks/use-key-bindings.d.ts +32 -32
- package/dist/ink/hooks/use-key-chord.d.ts +15 -15
- package/dist/ink/hooks/use-paste.d.ts +38 -38
- package/dist/ink/hooks/use-paste.js +1 -1
- package/dist/ink/hooks/use-persistent-state.d.ts +46 -46
- package/dist/ink/hooks/use-persistent-state.js +2 -2
- package/dist/ink/hooks/use-scroll-acceleration.d.ts +24 -24
- package/dist/ink/hooks/use-scroll-input.d.ts +15 -15
- package/dist/ink/hooks/use-stderr.d.ts +6 -6
- package/dist/ink/hooks/use-stderr.js +1 -1
- package/dist/ink/hooks/use-stdin.d.ts +10 -10
- package/dist/ink/hooks/use-stdin.js +1 -1
- package/dist/ink/hooks/use-stdout.d.ts +6 -6
- package/dist/ink/hooks/use-stdout.js +1 -1
- package/dist/ink/hooks/use-stopwatch.d.ts +12 -12
- package/dist/ink/hooks/use-terminal-palette.d.ts +11 -11
- package/dist/ink/hooks/use-text-buffer.d.ts +2 -2
- package/dist/ink/hooks/use-text-selection.d.ts +18 -18
- package/dist/ink/hooks/use-timeout.d.ts +11 -11
- package/dist/ink/hooks/use-timer.d.ts +19 -19
- package/dist/ink/hooks/use-window-size.d.ts +8 -8
- package/dist/ink/hooks/use-window-size.js +1 -1
- package/dist/ink/index.d.ts +109 -122
- package/dist/ink/index.js +1 -1
- package/dist/ink/mouse/use-element-position.d.ts +6 -6
- package/dist/ink/mouse/use-mouse-action.d.ts +1 -1
- package/dist/ink/mouse/use-mouse-position.d.ts +1 -1
- package/dist/ink/mouse/use-mouse.d.ts +1 -1
- package/dist/ink/mouse/use-on-mouse-click.d.ts +3 -3
- package/dist/ink/mouse/use-on-mouse-hover.d.ts +2 -2
- package/dist/ink/mouse/use-on-mouse-state.d.ts +2 -2
- package/dist/ink/public/cursor.d.ts +21 -21
- package/dist/ink/public/dom.d.ts +2 -2
- package/dist/ink/public/highlighter.d.ts +16 -26
- package/dist/ink/public/input.d.ts +6 -6
- package/dist/ink/public/styles.d.ts +1 -1
- package/dist/ink/public/utils.d.ts +2 -2
- package/dist/packem_shared/{DevTools-D9tfChBc.js → DevTools-CZ-O0Ckm.js} +1 -1
- package/dist/packem_shared/FocusContext-BWFqf9kb.js +1 -0
- package/dist/packem_shared/InputParser-CUAGWKQQ.js +2 -0
- package/dist/packem_shared/MouseProvider-DOcWCRVq.js +1 -0
- package/dist/packem_shared/{Renderer-DsskdkUd.js → Renderer-BeS49FNq.js} +1 -1
- package/dist/packem_shared/{TuiApp-DjIgv5Sk.js → TuiApp-CCVaiKbf.js} +1 -1
- package/dist/packem_shared/app-context.d-DMLw5Nxy.d.ts +56 -0
- package/dist/packem_shared/{buffer.d-j_dP5JyC.d.ts → buffer.d-CttIC480.d.ts} +26 -26
- package/dist/packem_shared/clipboard.d-nDPQkZ2H.d.ts +23 -0
- package/dist/packem_shared/color-matrix.d-sTqnJ23h.d.ts +50 -0
- package/dist/packem_shared/createInlineLoop-BMDYJkRp.js +2 -0
- package/dist/packem_shared/{dom.d-g-nsYquD.d.ts → dom.d-CLGlidfI.d.ts} +138 -151
- package/dist/packem_shared/{input.d-D-Yxqha8.d.ts → input.d-CL_4MfL-.d.ts} +30 -24
- package/dist/packem_shared/load-native-root-binding-CxJnHcac.js +1 -0
- package/dist/packem_shared/{mouse-context.d-BfL9xGk_.d.ts → mouse-context.d-W-nszUps.d.ts} +8 -8
- package/dist/packem_shared/reconciler-D4fi5NfR.js +1 -0
- package/dist/packem_shared/reconciler-DkwOtC5B.js +1 -0
- package/dist/packem_shared/render-CPVY5vpQ.js +1 -0
- package/dist/packem_shared/render-CvhjGwOg.js +24 -0
- package/dist/packem_shared/render.d-DjQhFsiN.d.ts +435 -0
- package/dist/packem_shared/{renderToString-DqLFFPvO.js → renderToString-B1LgWcJe.js} +1 -1
- package/dist/packem_shared/{renderToString-DkTmJPaS.js → renderToString-Df6HST7u.js} +1 -1
- package/dist/packem_shared/{selection.d-KWphH--_.d.ts → selection.d-BSAWa4ey.d.ts} +16 -16
- package/dist/packem_shared/stderr-context-CR2LLec6.js +1 -0
- package/dist/packem_shared/stdin-context-BjMA9Sbi.js +1 -0
- package/dist/packem_shared/stdout-context-DAAlQct2.js +1 -0
- package/dist/packem_shared/styles.d-CKGQFfm4.d.ts +485 -0
- package/dist/packem_shared/{terminal-palette.d-D2SQjfn-.d.ts → terminal-palette.d-JbWHISW-.d.ts} +7 -7
- package/dist/packem_shared/utils-CVgM8kTn.js +1 -0
- package/dist/react/index.d.ts +160 -178
- package/dist/react/index.js +1 -1
- package/dist/testing/index.d.ts +151 -151
- package/dist/testing/index.js +1 -1
- package/index.js +52 -52
- package/package.json +13 -13
- package/dist/packem_shared/FocusContext-C2Sosxa4.js +0 -1
- package/dist/packem_shared/InputParser-CiBitCva.js +0 -2
- package/dist/packem_shared/MouseProvider-DUqQ3Eaa.js +0 -1
- package/dist/packem_shared/app-context.d-CG88lgkg.d.ts +0 -56
- package/dist/packem_shared/clipboard.d-D6lZTQ21.d.ts +0 -23
- package/dist/packem_shared/color-matrix.d-DSXLsB64.d.ts +0 -50
- package/dist/packem_shared/createInlineLoop-BT40Wpmx.js +0 -2
- package/dist/packem_shared/load-native-root-binding-DDikxNox.js +0 -1
- package/dist/packem_shared/reconciler-ClpU7Y-V.js +0 -1
- package/dist/packem_shared/reconciler-DhUGYWCr.js +0 -1
- package/dist/packem_shared/render-D7aV_hO1.js +0 -24
- package/dist/packem_shared/render-DMcWfI6-.js +0 -1
- package/dist/packem_shared/render.d-BvfwvSCx.d.ts +0 -435
- package/dist/packem_shared/stderr-context-Bvnik0hL.js +0 -1
- package/dist/packem_shared/stdin-context-88AhuztD.js +0 -1
- package/dist/packem_shared/stdout-context-BnblEPez.js +0 -1
- package/dist/packem_shared/styles.d-D7iZuNC-.d.ts +0 -492
- package/dist/packem_shared/utils-C8l_3Dzw.js +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Check if a character is a C0 control character or DEL.
|
|
3
|
-
*/
|
|
2
|
+
* Check if a character is a C0 control character or DEL.
|
|
3
|
+
*/
|
|
4
4
|
declare const isControlCharacter: (input: string) => boolean;
|
|
5
5
|
/**
|
|
6
|
-
* Determine whether the input should be inserted as text.
|
|
7
|
-
* Filters out modifier chords (Ctrl+S, Meta+S, etc.) while allowing
|
|
8
|
-
* AltGr-produced symbols (Ctrl+Meta+@, Ctrl+Meta+€) on international keyboards.
|
|
9
|
-
*/
|
|
6
|
+
* Determine whether the input should be inserted as text.
|
|
7
|
+
* Filters out modifier chords (Ctrl+S, Meta+S, etc.) while allowing
|
|
8
|
+
* AltGr-produced symbols (Ctrl+Meta+@, Ctrl+Meta+€) on international keyboards.
|
|
9
|
+
*/
|
|
10
10
|
declare const isInsertableInput: (input: string, key: {
|
|
11
11
|
ctrl: boolean;
|
|
12
12
|
meta: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as l,jsx as u}from"react/jsx-runtime";import{useState as p,useRef as s,useEffect as h}from"react";import{useWindowSize as x,useTuiContext as w}from"./TuiContext-BNmP0lMY.js";import{_Box as i,_Spacer as S,_Text as D}from"./render-
|
|
1
|
+
import{jsxs as l,jsx as u}from"react/jsx-runtime";import{useState as p,useRef as s,useEffect as h}from"react";import{useWindowSize as x,useTuiContext as w}from"./TuiContext-BNmP0lMY.js";import{_Box as i,_Spacer as S,_Text as D}from"./render-CPVY5vpQ.js";function T(){const{app:r}=w(),[t,c]=p(0),e=s(0),n=s(Date.now()),o=s(null);return h(()=>{const m=()=>{o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{c(0),e.current=0,n.current=Date.now()},2e3),e.current++;const d=Date.now(),f=d-n.current;f>=500&&(c(Math.round(e.current/f*1e3)),e.current=0,n.current=d)},a=r.onBeforeFlush(()=>{m()});return()=>{a(),o.current&&clearTimeout(o.current)}},[r]),t}const b=({fps:r})=>{const t=r===0?"--":String(r);return u(i,{borderColor:"gray",borderStyle:"round",paddingX:1,children:l(D,{dim:!0,children:[t," ","updates/sec"]})})},B=({children:r,enabled:t=!0})=>{const c=T(),{columns:e,rows:n}=x();return l(i,{flexDirection:"column",height:n,width:e,children:[u(i,{flexGrow:1,children:r}),t&&l(i,{flexDirection:"row",flexShrink:0,children:[u(S,{}),u(b,{fps:c})]})]})};export{B as DevTools};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import E,{createContext as R,useRef as S,useState as I,useCallback as s,useMemo as P,useContext as C,useEffect as p}from"react";const m=R({activate(){},activeId:void 0,add(){},deactivate(){},disableFocus(){},enableFocus(){},focus(){},focusNext(){},focusPrevious(){},remove(){}});m.displayName="TuiFocusContext";const y=({children:i})=>{const u=S([]),[a,o]=I(void 0),[n,v]=I(!0),f=s((t,e)=>{if(u.current.some(r=>r.id===t))return;const d={autoFocus:e.autoFocus,id:t,isActive:!0};u.current=[...u.current,d],o(r=>e.autoFocus&&r===void 0||u.current.filter(M=>M.isActive).length===1&&r===void 0?t:r)},[]),l=s(t=>{u.current=u.current.filter(e=>e.id!==t),o(e=>e===t?void 0:e)},[]),F=s(t=>{u.current=u.current.map(e=>e.id===t?{...e,isActive:!0}:e)},[]),c=s(t=>{u.current=u.current.map(e=>e.id===t?{...e,isActive:!1}:e),o(e=>e===t?void 0:e)},[]),x=s(()=>v(!0),[]),b=s(()=>{v(!1),o(void 0)},[]),g=s(()=>{if(!n)return;const t=u.current.filter(e=>e.isActive);t.length!==0&&o(e=>{if(e===void 0)return t[0]?.id;const d=t.findIndex(r=>r.id===e);return t[(d+1)%t.length]?.id??t[0]?.id})},[n]),h=s(()=>{if(!n)return;const t=u.current.filter(e=>e.isActive);t.length!==0&&o(e=>{if(e===void 0)return t.at(-1)?.id;const d=t.findIndex(r=>r.id===e);return t[(d-1+t.length)%t.length]?.id??t.at(-1)?.id})},[n]),A=s(t=>{n&&u.current.some(e=>e.id===t&&e.isActive)&&o(t)},[n]),N=P(()=>({activate:F,activeId:a,add:f,deactivate:c,disableFocus:b,enableFocus:x,focus:A,focusNext:g,focusPrevious:h,remove:l}),[a,f,l,F,c,x,b,g,h,A]);return E.createElement(m.Provider,{value:N},i)},T=({autoFocus:i=!1,id:u,isActive:a=!0}={})=>{const{activate:o,activeId:n,add:v,deactivate:f,focus:l,remove:F}=C(m),c=P(()=>u??Math.random().toString(36).slice(2,7),[u]);return p(()=>(v(c,{autoFocus:i}),()=>{F(c)}),[c,i]),p(()=>{a?o(c):f(c)},[a,c]),{focus:l,isFocused:!!c&&n===c}},j=()=>{const i=C(m);return{activeId:i.activeId,disableFocus:i.disableFocus,enableFocus:i.enableFocus,focus:i.focus,focusNext:i.focusNext,focusPrevious:i.focusPrevious}};export{m as FocusContext,y as FocusProvider,T as useFocus,j as useFocusManager};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{l as c}from"./index-Dl9I2_QH.js";const u="\x1B[200~",o="\x1B[201~",p=1024*1024;class w extends c.EventEmitter{constructor(t){super(),this.stdin=t}stdin;_boundHandleData=null;_pasteBuffer=null;start(){typeof this.stdin.setRawMode=="function"&&this.stdin.setRawMode(!0),this.stdin.resume(),this.stdin.setEncoding("utf8"),this._boundHandleData=this.handleData.bind(this),this.stdin.on("data",this._boundHandleData)}stop(){typeof this.stdin.setRawMode=="function"&&this.stdin.setRawMode(!1),this.stdin.pause(),this._boundHandleData&&(this.stdin.removeListener("data",this._boundHandleData),this._boundHandleData=null)}handleData(t){if(t===""){this.emit("exit");return}if(this._pasteBuffer!==null||t.includes(u)){let e=t;if(this._pasteBuffer===null){const s=e.indexOf(u),d=e.slice(0,s);d.length>0&&this.handleData(d),this._pasteBuffer="",e=e.slice(s+u.length)}const i=e.indexOf(o);if(i===-1){const s=this._pasteBuffer+e;if(s.length>p){this._pasteBuffer=null,this.emit("data",s);return}this._pasteBuffer=s;return}const r=this._pasteBuffer+e.slice(0,i),a=e.slice(i+o.length);this._pasteBuffer=null,this.emit("paste",r),this.listenerCount("paste")===0&&this.emit("data",r),a.length>0&&this.handleData(a);return}if(t.length===1){const e=t.charCodeAt(0);if(e>=1&&e<=26&&e!==3&&e!==9&&e!==10&&e!==13){const i=String.fromCharCode(e+96);this.emit("ctrl",i),this.emit("data",t,{ctrl:!0});return}}if(t==="\x1B[A"){this.emit("keydown","up");return}if(t==="\x1B[B"){this.emit("keydown","down");return}if(t==="\x1B[C"){this.emit("keydown","right");return}if(t==="\x1B[D"){this.emit("keydown","left");return}if(t===" "){this.emit("keydown","tab");return}if(t==="\x1B[Z"){this.emit("keydown","shift-tab");return}if(t==="\x1B"){this.emit("keydown","escape");return}if(t==="\r"||t===`
|
|
2
|
+
`){this.emit("keydown","enter");return}if(t===""){this.emit("keydown","backspace");return}if(t==="\x1B[3~"){this.emit("keydown","delete");return}if(t==="\x1B[5~"){this.emit("keydown","pageUp");return}if(t==="\x1B[6~"){this.emit("keydown","pageDown");return}if(t==="\x1B[H"||t==="\x1B[1~"){this.emit("keydown","home");return}if(t==="\x1B[F"||t==="\x1B[4~"){this.emit("keydown","end");return}if(t.length===2&&t[0]==="\x1B"){this.emit("meta",t[1]),this.emit("data",t,{meta:!0});return}if(t.startsWith("\x1B[<")){const e=t.match(/\u001B\[<(\d+);(\d+);(\d+)(M)/i);if(e){const i=Number.parseInt(e[1]),r=Number.parseInt(e[2])-1,a=Number.parseInt(e[3])-1,s=e[4]==="m",d=(i&4)!==0,l=(i&8)!==0,f=(i&16)!==0,h=i&-29;let n=null;if(h===0&&!s?n="left":h===1&&!s?n="middle":h===2&&!s?n="right":h===64?n="scrollUp":h===65&&(n="scrollDown"),n){const m={button:n,ctrl:f,meta:l,shift:d,x:r,y:a};this.emit("mouse",m),n==="left"&&this.emit("click",{x:r,y:a})}}return}this.emit("data",t)}}export{w as InputParser};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as _}from"node:module";import{jsx as h}from"react/jsx-runtime";import{useRef as d,useReducer as j,useEffect as b,useMemo as x}from"react";import{useStdinContext as w}from"../ink/hooks/use-stdin.js";import q from"../ink/hooks/use-stdout.js";import{M as n,d as B}from"./ansi-parser-DlgLtOYO.js";import{o as E}from"./mouse-context-DaARgUu1.js";let y;const v=e=>(y??=_(import.meta.url))(e),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=e=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[t,i]=u.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return u.getBuiltinModule(e)}return v(e)},{EventEmitter:M}=T("node:events"),R=u,S={button:null,click:null,drag:null,position:{x:0,y:0},scroll:null},C=(e,t)=>{switch(t.type){case"click":return{...e,button:t.button,click:t.click,position:t.position};case"click-reset":return{...e,button:null,click:null};case"drag":return{...e,button:t.button,drag:t.drag,position:t.position};case"move":return{...e,position:t.position};case"scroll":return{...e,position:t.position,scroll:t.scroll};case"scroll-reset":return{...e,scroll:null};default:return e}},A=({children:e})=>{const{internal_eventEmitter:t}=w(),{stdout:i}=q(),l=d(new M),[s,c]=j(C,S),p=d(void 0),m=d(void 0);b(()=>{const a=i.isTTY?i:R.stdout;return a.write(n.mouseButton.on+n.mouseMotion.on+n.mouseMotionOthers.on+n.mouseSGR.on),()=>{a.write(n.mouseSGR.off+n.mouseMotionOthers.off+n.mouseMotion.off+n.mouseButton.off)}},[i]),b(()=>{const a=k=>{const o=B(k);if(!o)return;const r={x:o.x,y:o.y};switch(l.current.emit("position",r),o.type){case"click":{c({button:o.button,click:o.action,position:r,type:"click"}),l.current.emit("click",r,o.action,o.button),clearTimeout(p.current),p.current=setTimeout(()=>{c({type:"click-reset"})},100);break}case"drag":{const f=o.action==="press"?"dragging":null;c({button:o.button,drag:f,position:r,type:"drag"}),l.current.emit("drag",r,f,o.button);break}case"move":{c({position:r,type:"move"});break}case"scroll":{c({position:r,scroll:o.direction,type:"scroll"}),l.current.emit("scroll",r,o.direction),clearTimeout(m.current),m.current=setTimeout(()=>{c({type:"scroll-reset"})},100);break}}};return t.on("input",a),()=>{t.off("input",a),clearTimeout(p.current),clearTimeout(m.current)}},[t]);const g=x(()=>({button:s.button,click:s.click,drag:s.drag,events:l.current,position:s.position,scroll:s.scroll}),[s]);return h(E,{value:g,children:e})};export{A as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{p as r}from"./load-native-root-binding-
|
|
1
|
+
import{p as r}from"./load-native-root-binding-CxJnHcac.js";const n=r(import.meta.url),e=n,m=e.Renderer,t=e.TerminalGuard,a=e.terminalSize;export{m as Renderer,t as TerminalGuard,a as terminalSize};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createDecMode as h,setMode as n,resetMode as u}from"@visulima/ansi";import{l as f}from"./index-Dl9I2_QH.js";import{Renderer as s,TerminalGuard as o}from"./Renderer-
|
|
1
|
+
import{createDecMode as h,setMode as n,resetMode as u}from"@visulima/ansi";import{l as f}from"./index-Dl9I2_QH.js";import{Renderer as s,TerminalGuard as o}from"./Renderer-BeS49FNq.js";const i=h(2026),d=n(i),a=u(i);class p extends f.EventEmitter{renderer;terminal=null;backBuffer;width;height;isRunning=!1;stdoutBuffer=[];stderrBuffer=[];constructor(){super(),this.width=process.stdout.columns||80,this.height=process.stdout.rows||24,this.renderer=new s(this.width,this.height),this.backBuffer=new Uint32Array(this.width*this.height*2)}start(){this.isRunning||(this.terminal=new o(!0),this.isRunning=!0)}quit(){this.emit("quit")}stop(){this.isRunning=!1,this.terminal?.leave(),this.terminal=null,this.stdoutBuffer.length>0&&(process.stdout.write(this.stdoutBuffer.join("")),this.stdoutBuffer=[]),this.stderrBuffer.length>0&&(process.stderr.write(this.stderrBuffer.join("")),this.stderrBuffer=[])}writeStdout(t){this.isRunning?this.stdoutBuffer.push(t):process.stdout.write(t)}writeStderr(t){this.isRunning?this.stderrBuffer.push(t):process.stderr.write(t)}getBuffer(){return this.backBuffer}getSize(){return{height:this.height,width:this.width}}resize(t,e){this.width=t,this.height=e,this.renderer=new s(t,e),this.backBuffer=new Uint32Array(t*e*2)}beforeFlushListeners=[];onBeforeFlush(t){return this.beforeFlushListeners.push(t),()=>{this.beforeFlushListeners=this.beforeFlushListeners.filter(e=>e!==t)}}paintNow(t,e){if(this.isRunning){t(this.width,this.height),e(this.backBuffer,this.width,this.height);for(const r of this.beforeFlushListeners)r(this.backBuffer,this.width,this.height);this.renderer.writeRaw(d);try{this.renderer.render(this.backBuffer)}finally{this.renderer.writeRaw(a)}}}}export{p as TuiApp};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A handle returned by `suspendTerminal()` when called without a callback.
|
|
4
|
+
* Call `resume()` (or use `await using`, which disposes it) to restore Ink's
|
|
5
|
+
* rendering and input handling.
|
|
6
|
+
*/
|
|
7
|
+
type TerminalSuspension = {
|
|
8
|
+
readonly [Symbol.asyncDispose]: () => Promise<void>;
|
|
9
|
+
readonly resume: () => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
type Props = {
|
|
12
|
+
/**
|
|
13
|
+
* Exit (unmount) the whole Ink app.
|
|
14
|
+
*
|
|
15
|
+
* - `exit()` — resolves `waitUntilExit()` with `undefined`.
|
|
16
|
+
* - `exit(new Error('…'))` — rejects `waitUntilExit()` with the error.
|
|
17
|
+
* - `exit(value)` — resolves `waitUntilExit()` with `value`.
|
|
18
|
+
*/
|
|
19
|
+
readonly exit: (errorOrResult?: Error | unknown) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Temporarily hand terminal control to a child process (e.g. an editor,
|
|
22
|
+
* pager, or interactive subprocess), then restore Ink's rendering.
|
|
23
|
+
*
|
|
24
|
+
* - `suspendTerminal(async () => { … })` — runs the callback with the
|
|
25
|
+
* terminal released and auto-resumes when it settles.
|
|
26
|
+
* - `suspendTerminal()` — returns a {@link TerminalSuspension} handle; call
|
|
27
|
+
* `resume()` (or `await using`) to restore.
|
|
28
|
+
*/
|
|
29
|
+
readonly suspendTerminal: {
|
|
30
|
+
(callback: () => Promise<void> | void): Promise<undefined>;
|
|
31
|
+
(): Promise<TerminalSuspension>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Returns a promise that settles after pending render output is flushed to stdout.
|
|
35
|
+
* @example
|
|
36
|
+
* ```jsx
|
|
37
|
+
* import {useEffect} from 'react';
|
|
38
|
+
* import {useApp} from '@visulima/tui/hooks/use-app';
|
|
39
|
+
|
|
40
|
+
const Example = () => {
|
|
41
|
+
const {waitUntilRenderFlush} = useApp();
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
void (async () => {
|
|
45
|
+
await waitUntilRenderFlush();
|
|
46
|
+
runNextCommand();
|
|
47
|
+
})();
|
|
48
|
+
}, [waitUntilRenderFlush]);
|
|
49
|
+
|
|
50
|
+
return …;
|
|
51
|
+
};
|
|
52
|
+
```
|
|
53
|
+
*/
|
|
54
|
+
readonly waitUntilRenderFlush: () => Promise<void>;
|
|
55
|
+
};
|
|
56
|
+
export { Props as P, TerminalSuspension as T };
|
|
@@ -6,38 +6,38 @@ type CellStyle = {
|
|
|
6
6
|
readonly dim?: boolean;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
-
* Reverse of the encoder. 0 → undefined; any other id returns the original
|
|
10
|
-
* CanvasColor (preserving number vs string distinction).
|
|
11
|
-
*/
|
|
9
|
+
* Reverse of the encoder. 0 → undefined; any other id returns the original
|
|
10
|
+
* CanvasColor (preserving number vs string distinction).
|
|
11
|
+
*/
|
|
12
12
|
type ColorDecoder = (id: number) => CanvasColor;
|
|
13
13
|
type CanvasContext = {
|
|
14
14
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
* Clear every cell back to space + default style.
|
|
16
|
+
*/
|
|
17
17
|
readonly clear: () => void;
|
|
18
18
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
* Draw a horizontal bar using fractional block glyphs (▏▎▍▌▋▊▉█).
|
|
20
|
+
* `fillRatio` in [0, 1] determines the filled portion.
|
|
21
|
+
*/
|
|
22
22
|
readonly drawHBar: (x: number, y: number, w: number, fillRatio: number, style?: CellStyle) => void;
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
* Draw a filled rectangle using a single character.
|
|
25
|
+
*/
|
|
26
26
|
readonly drawRect: (x: number, y: number, w: number, h: number, char: number | string, style?: CellStyle) => void;
|
|
27
27
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
* Render a string left-to-right starting at (x, y). Non-printable or
|
|
29
|
+
* multi-byte codepoints are preserved but advance the cursor by 1 cell.
|
|
30
|
+
*/
|
|
31
31
|
readonly drawText: (x: number, y: number, text: string, style?: CellStyle) => void;
|
|
32
32
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
* Draw a vertical bar using fractional block glyphs (▁▂▃▄▅▆▇█).
|
|
34
|
+
* `fillRatio` in [0, 1] determines the filled portion.
|
|
35
|
+
*/
|
|
36
36
|
readonly drawVBar: (x: number, y: number, h: number, fillRatio: number, style?: CellStyle) => void;
|
|
37
37
|
readonly height: number;
|
|
38
38
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
* Set a single cell at (x, y). Out-of-bounds writes are silently ignored.
|
|
40
|
+
*/
|
|
41
41
|
readonly setCell: (x: number, y: number, char: number | string, style?: CellStyle) => void;
|
|
42
42
|
readonly width: number;
|
|
43
43
|
};
|
|
@@ -53,15 +53,15 @@ type CanvasBuffer = {
|
|
|
53
53
|
readonly width: number;
|
|
54
54
|
};
|
|
55
55
|
/**
|
|
56
|
-
* Allocate a canvas buffer and return a context that mutates it in place.
|
|
57
|
-
* The buffer is typed-array backed; all mutations O(1) per cell with no
|
|
58
|
-
* object allocation.
|
|
59
|
-
*/
|
|
56
|
+
* Allocate a canvas buffer and return a context that mutates it in place.
|
|
57
|
+
* The buffer is typed-array backed; all mutations O(1) per cell with no
|
|
58
|
+
* object allocation.
|
|
59
|
+
*/
|
|
60
60
|
declare const createCanvasBuffer: (width: number, height: number) => CanvasBuffer;
|
|
61
61
|
/**
|
|
62
|
-
* Serialize a buffer row into an ANSI string, coalescing adjacent cells that
|
|
63
|
-
* share the same style. Call directly when you need to re-emit rows; row
|
|
64
|
-
* caching lives one level up in Canvas.tsx.
|
|
65
|
-
*/
|
|
62
|
+
* Serialize a buffer row into an ANSI string, coalescing adjacent cells that
|
|
63
|
+
* share the same style. Call directly when you need to re-emit rows; row
|
|
64
|
+
* caching lives one level up in Canvas.tsx.
|
|
65
|
+
*/
|
|
66
66
|
declare const serializeRow: (buffer: CanvasBuffer, row: number) => string;
|
|
67
67
|
export { CanvasContext as C, CanvasColor as a, CellStyle as b, CanvasBuffer as c, createCanvasBuffer as d, serializeRow as s };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Writable } from 'node:stream';
|
|
2
|
+
/**
|
|
3
|
+
* Clipboard targets as defined by the OSC 52 spec.
|
|
4
|
+
* - `c` — system clipboard
|
|
5
|
+
* - `p` — primary selection (X11 only)
|
|
6
|
+
* - `s` — secondary selection (X11 only)
|
|
7
|
+
*/
|
|
8
|
+
type ClipboardTarget = "c" | "p" | "s";
|
|
9
|
+
/**
|
|
10
|
+
* Check whether the current terminal likely supports OSC 52.
|
|
11
|
+
*
|
|
12
|
+
* Detection is best-effort based on `TERM_PROGRAM` and other env vars.
|
|
13
|
+
* Returns `true` for known-supported terminals, `false` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
declare const isOsc52Supported: () => boolean;
|
|
16
|
+
declare const writeOsc52: (stream: Writable, text: string, target?: ClipboardTarget) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Clear the clipboard via OSC 52.
|
|
19
|
+
* @param stream The writable stream to write the escape sequence to.
|
|
20
|
+
* @param target The clipboard target. Defaults to `"c"`.
|
|
21
|
+
*/
|
|
22
|
+
declare const clearOsc52: (stream: Writable, target?: ClipboardTarget) => void;
|
|
23
|
+
export { ClipboardTarget as C, clearOsc52 as c, isOsc52Supported as i, writeOsc52 as w };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color matrix transforms for color blindness simulation and compensation.
|
|
3
|
+
*
|
|
4
|
+
* Matrices sourced from research by Brettel, Viénot, and Mollon (1997)
|
|
5
|
+
* and Machado, Oliveira, and Fernandes (2009).
|
|
6
|
+
* @see https://www.inf.ufrgs.br/~oliveira/pubs_files/CVD_Simulation/CVD_Simulation.html
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 3x3 color transformation matrix operating on linear RGB values (0-255).
|
|
10
|
+
*/
|
|
11
|
+
type ColorMatrix = readonly [readonly [number, number, number], readonly [number, number, number], readonly [number, number, number]];
|
|
12
|
+
type ColorBlindnessType = "achromatopsia" | "deuteranopia" | "protanopia" | "tritanopia";
|
|
13
|
+
/**
|
|
14
|
+
* Simulation matrices — show how colors appear to users with color vision deficiency.
|
|
15
|
+
*/
|
|
16
|
+
declare const COLOR_BLINDNESS_SIMULATION: Record<ColorBlindnessType, ColorMatrix>;
|
|
17
|
+
/**
|
|
18
|
+
* Compensation matrices — shift colors into a distinguishable range for affected users.
|
|
19
|
+
* These remap problematic colors to alternatives the user can perceive.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Compensation matrices — enhance distinguishability for affected users
|
|
23
|
+
* by redistributing the lost channel's energy into perceivable channels.
|
|
24
|
+
* Based on Daltonization approach (Fidaner et al., 2005).
|
|
25
|
+
*/
|
|
26
|
+
declare const COLOR_BLINDNESS_COMPENSATION: Record<Exclude<ColorBlindnessType, "achromatopsia">, ColorMatrix>;
|
|
27
|
+
/**
|
|
28
|
+
* Identity matrix (no transformation).
|
|
29
|
+
*/
|
|
30
|
+
declare const IDENTITY_MATRIX: ColorMatrix;
|
|
31
|
+
/**
|
|
32
|
+
* Apply a 3x3 color matrix to an RGB triplet.
|
|
33
|
+
* @param r Red channel (0-255)
|
|
34
|
+
* @param g Green channel (0-255)
|
|
35
|
+
* @param b Blue channel (0-255)
|
|
36
|
+
* @param matrix The 3x3 transformation matrix
|
|
37
|
+
* @returns Transformed [r, g, b] triplet, clamped to 0-255
|
|
38
|
+
*/
|
|
39
|
+
declare const applyColorMatrix: (r: number, g: number, b: number, matrix: ColorMatrix) => [number, number, number];
|
|
40
|
+
declare const hexToRgb: (hex: string) => [number, number, number] | null;
|
|
41
|
+
/**
|
|
42
|
+
* Convert RGB components to a hex color string.
|
|
43
|
+
*/
|
|
44
|
+
declare const rgbToHex: (r: number, g: number, b: number) => string;
|
|
45
|
+
/**
|
|
46
|
+
* Transform a hex color through a color blindness simulation or compensation matrix.
|
|
47
|
+
* Returns the original color if parsing fails.
|
|
48
|
+
*/
|
|
49
|
+
declare const transformHexColor: (hex: string, matrix: ColorMatrix) => string;
|
|
50
|
+
export { ColorBlindnessType as C, IDENTITY_MATRIX as I, ColorMatrix as a, COLOR_BLINDNESS_COMPENSATION as b, COLOR_BLINDNESS_SIMULATION as c, applyColorMatrix as d, hexToRgb as h, rgbToHex as r, transformHexColor as t };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createDecMode as G,setMode as w,resetMode as T,BracketedPasteMode as M,cursorHide as Y,REQUEST_CURSOR_POSITION as b,cursorPosition as u,eraseLine as g,cursorShow as A,cursorUp as B,cursorToColumn1 as C}from"@visulima/ansi";import{terminalSize as D,Renderer as L}from"./Renderer-BeS49FNq.js";const R=G(2026),_=w(R),k=T(R),z=w(M),H=T(M);function q(S,c={}){const E=c.rows??10,O=c.fps??60,h=c.onExit??"preserve",{onStop:y}=c;let i=null,r=null,l=null,a=80,t=10,N=0,n=1,f=!1,o=null;function e(s){r.writeRaw(s)}function p(){l.fill(0),S(l,a,t,N++),e(_);try{r.render(l)}finally{e(k)}}function P(s){n=s-t,e(B(t)+C),r.setRowOffset(n),p(),i=setInterval(()=>{p()},Math.round(1e3/O))}function U(){const s=D();a=s.cols;const v=s.rows;t=Math.min(E,v),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.setEncoding("utf8"),r=new L(a,t),l=new Uint32Array(a*t*2),e(Y),e(z),e(`
|
|
2
|
+
`.repeat(t)),e(b),process.on("SIGINT",d);let m="";o=x=>{m+=x;const I=m.match(/\u001B\[(\d+);(\d+)R/);I&&(o&&(process.stdin.off("data",o),o=null),P(Number.parseInt(I[1],10)))},process.stdin.on("data",o)}function d(){if(!f){if(f=!0,i&&(clearInterval(i),i=null),process.off("SIGINT",d),o&&(process.stdin.off("data",o),o=null),r){if(h==="destroy"){for(let s=0;s<t;s++)e(u(n+1+s,1)+g);e(u(n+1,1))}else e(u(n+t+1,1));e(H),e(A)}process.stdin.isTTY&&process.stdin.setRawMode(!1),process.stdin.pause(),y?.()}}return{start:U,stop:d}}export{q as createInlineLoop};
|