@gjsify/readline 0.3.21 → 0.4.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.
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
package/lib/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{EventEmitter as e}from"node:events";import{StringDecoder as t}from"node:string_decoder";const n=/\r\n|\r|\n/;var Interface=class extends e{terminal;line=``;cursor=0;_input;_output;get input(){return this._input}get output(){return this._output}_prompt;_closed=!1;_paused=!1;history;_historySize;_crlfDelay;_lineBuffer=``;_questionCallback=null;_boundOnData=null;_boundOnEnd=null;_boundOnError=null;_boundOnKeypress=null;constructor(e,t){super();let n;n=e&&typeof e==`object`&&!(`read`in e&&typeof e.read==`function`)?e:{input:e,output:t},this._input=n.input||null,this._output=n.output||null,this._prompt=n.prompt||`> `,this.terminal=n.terminal??this._output!==null,this._historySize=n.historySize??30,this.history=[],this._crlfDelay=n.crlfDelay??100,this._input&&(this._boundOnData=e=>this._onData(e),this._boundOnEnd=()=>this._onEnd(),this._boundOnError=e=>this.emit(`error`,e),this._input.on(`data`,this._boundOnData),this._input.on(`end`,this._boundOnEnd),this._input.on(`error`,this._boundOnError),`setEncoding`in this._input&&typeof this._input.setEncoding==`function`&&this._input.setEncoding(`utf8`),this.terminal&&(emitKeypressEvents(this._input,this),`setRawMode`in this._input&&typeof this._input.setRawMode==`function`&&(this._input.isRaw||this._input.setRawMode(!0)),`resume`in this._input&&typeof this._input.resume==`function`&&this._input.resume(),this._boundOnKeypress=(e,t)=>{t&&(t.name===`backspace`||t.name===`delete`?this.cursor>0&&(this.line=this.line.slice(0,this.cursor-1)+this.line.slice(this.cursor),this.cursor--):e&&e.length===1&&!t.ctrl&&!t.meta&&t.name!==`return`&&t.name!==`enter`&&t.name!==`escape`&&(this.line=this.line.slice(0,this.cursor)+e+this.line.slice(this.cursor),this.cursor++))},this._input.on(`keypress`,this._boundOnKeypress)))}_onData(e){if(this._closed||this._paused)return;let t=typeof e==`string`?e:e.toString(`utf8`);this._lineBuffer+=t;let r;for(;(r=n.exec(this._lineBuffer))!==null;){let e=this._lineBuffer.substring(0,r.index);this._lineBuffer=this._lineBuffer.substring(r.index+r[0].length),this._onLine(e)}}_onLine(e){if(e.length>0&&this._historySize>0&&(this.history.length===0||this.history[0]!==e)&&(this.history.unshift(e),this.history.length>this._historySize&&this.history.pop()),this._questionCallback){let t=this._questionCallback;this._questionCallback=null,t(e)}this.emit(`line`,e)}_onEnd(){this._lineBuffer.length>0&&(this._onLine(this._lineBuffer),this._lineBuffer=``),this.close()}setPrompt(e){this._prompt=e}getPrompt(){return this._prompt}prompt(e){if(this._closed)throw Error(`readline was closed`);this._output?.write(this._prompt)}question(e,t,n){if(this._closed)throw Error(`readline was closed`);let r=typeof t==`function`?t:n;this._questionCallback=r,this._output?.write(e)}clearLine(e,t){return this.line=``,this.cursor=0,t&&t(),!0}write(e,t){if(!this._closed){if(t){this._input&&this._input.emit(`keypress`,e??``,t);return}if(e!=null){let t=typeof e==`string`?e:e.toString(`utf8`);t&&(this.line=this.line.slice(0,this.cursor)+t+this.line.slice(this.cursor),this.cursor+=t.length),this._output?.write(e)}}}close(){this._closed||(this._closed=!0,this._input&&(this._boundOnData&&this._input.removeListener(`data`,this._boundOnData),this._boundOnEnd&&this._input.removeListener(`end`,this._boundOnEnd),this._boundOnError&&this._input.removeListener(`error`,this._boundOnError),this._boundOnKeypress&&this._input.removeListener(`keypress`,this._boundOnKeypress),this._boundOnData=null,this._boundOnEnd=null,this._boundOnError=null,this._boundOnKeypress=null,this.terminal&&this._input.isRaw&&`setRawMode`in this._input&&typeof this._input.setRawMode==`function`&&this._input.setRawMode(!1),`pause`in this._input&&typeof this._input.pause==`function`&&this._input.pause()),this.emit(`close`))}pause(){return this._closed?this:(this._paused=!0,this._input&&`pause`in this._input&&typeof this._input.pause==`function`&&this._input.pause(),this.emit(`pause`),this)}resume(){return this._closed?this:(this._paused=!1,this._input&&`resume`in this._input&&typeof this._input.resume==`function`&&this._input.resume(),this.emit(`resume`),this)}getCursorPos(){let e=this._output?.columns??80,t=this._prompt.length+this.cursor;return{rows:Math.floor(t/e),cols:t%e}}[Symbol.asyncIterator](){let e=[],t=null,n=!1,onLine=n=>{if(t){let e=t;t=null,e({value:n,done:!1})}else e.push(n)},onClose=()=>{if(n=!0,t){let e=t;t=null,e({value:void 0,done:!0})}};return this.on(`line`,onLine),this.on(`close`,onClose),{next:()=>e.length>0?Promise.resolve({value:e.shift(),done:!1}):n?Promise.resolve({value:void 0,done:!0}):new Promise(e=>{t=e}),return:()=>(n=!0,this.removeListener(`line`,onLine),this.removeListener(`close`,onClose),Promise.resolve({value:void 0,done:!0})),[Symbol.asyncIterator](){return this}}}};function createInterface(e,t,n,r){return typeof e==`object`&&e&&!(`read`in e&&typeof e.read==`function`)?new Interface(e):new Interface({input:e,output:t,completer:n,terminal:r})}function clearLine(e,t,n){if(!e||typeof e.write!=`function`)return n&&n(),!0;let r=t<0?`\x1B[1K`:t>0?`\x1B[0K`:`\x1B[2K`;return e.write(r,n)}function clearScreenDown(e,t){return!e||typeof e.write!=`function`?(t&&t(),!0):e.write(`\x1B[0J`,t)}function cursorTo(e,t,n,r){if(!e||typeof e.write!=`function`)return typeof n==`function`?n():r&&r(),!0;typeof n==`function`&&(r=n,n=void 0);let i=typeof n==`number`?`\x1b[${n+1};${t+1}H`:`\x1b[${t+1}G`;return e.write(i,r)}function moveCursor(e,t,n,r){if(!e||typeof e.write!=`function`)return r&&r(),!0;let i=``;return t>0?i+=`\x1b[${t}C`:t<0&&(i+=`\x1b[${-t}D`),n>0?i+=`\x1b[${n}B`:n<0&&(i+=`\x1b[${-n}A`),i?e.write(i,r):(r&&r(),!0)}function*emitKeys(e){for(;;){let t=yield,n=t,r=!1,i={sequence:``,name:void 0,ctrl:!1,meta:!1,shift:!1};if(t===`\x1B`&&(r=!0,n+=t=yield,t===`\x1B`&&(n+=t=yield)),r&&(t===`O`||t===`[`)){let e=t,r=0;if(t===`O`)n+=t=yield,t>=`0`&&t<=`9`&&(r=t.charCodeAt(0)-1,n+=t=yield),e+=t;else if(t===`[`){n+=t=yield,t===`[`&&(e+=t,n+=t=yield);let i=n.length-1;t>=`0`&&t<=`9`&&(n+=t=yield,t>=`0`&&t<=`9`&&(n+=t=yield,t>=`0`&&t<=`9`&&(n+=t=yield))),t===`;`&&(n+=t=yield,t>=`0`&&t<=`9`&&(n+=yield));let a=n.slice(i),o;(o=/^(?:(\d\d?)(?:;(\d))?([~^$])|(\d{3}~))$/.exec(a))?o[4]?e+=o[4]:(e+=o[1]+o[3],r=(parseInt(o[2]??`1`,10)||1)-1):(o=/^((\d;)?(\d))?([A-Za-z])$/.exec(a))?(e+=o[4],r=(parseInt(o[3]??`1`,10)||1)-1):e+=a}switch(i.ctrl=!!(r&4),i.meta=!!(r&10),i.shift=!!(r&1),i.code=e,e){case`[P`:case`OP`:case`[11~`:case`[[A`:i.name=`f1`;break;case`[Q`:case`OQ`:case`[12~`:case`[[B`:i.name=`f2`;break;case`[R`:case`OR`:case`[13~`:case`[[C`:i.name=`f3`;break;case`[S`:case`OS`:case`[14~`:case`[[D`:i.name=`f4`;break;case`[15~`:case`[[E`:i.name=`f5`;break;case`[17~`:i.name=`f6`;break;case`[18~`:i.name=`f7`;break;case`[19~`:i.name=`f8`;break;case`[20~`:i.name=`f9`;break;case`[21~`:i.name=`f10`;break;case`[23~`:i.name=`f11`;break;case`[24~`:i.name=`f12`;break;case`[200~`:i.name=`paste-start`;break;case`[201~`:i.name=`paste-end`;break;case`[A`:case`OA`:i.name=`up`;break;case`[B`:case`OB`:i.name=`down`;break;case`[C`:case`OC`:i.name=`right`;break;case`[D`:case`OD`:i.name=`left`;break;case`[E`:case`OE`:i.name=`clear`;break;case`[F`:case`OF`:i.name=`end`;break;case`[H`:case`OH`:i.name=`home`;break;case`[1~`:i.name=`home`;break;case`[2~`:i.name=`insert`;break;case`[3~`:i.name=`delete`;break;case`[4~`:i.name=`end`;break;case`[5~`:case`[[5~`:i.name=`pageup`;break;case`[6~`:case`[[6~`:i.name=`pagedown`;break;case`[7~`:i.name=`home`;break;case`[8~`:i.name=`end`;break;case`[a`:i.name=`up`,i.shift=!0;break;case`[b`:i.name=`down`,i.shift=!0;break;case`[c`:i.name=`right`,i.shift=!0;break;case`[d`:i.name=`left`,i.shift=!0;break;case`[2$`:i.name=`insert`,i.shift=!0;break;case`[3$`:i.name=`delete`,i.shift=!0;break;case`[5$`:i.name=`pageup`,i.shift=!0;break;case`[6$`:i.name=`pagedown`,i.shift=!0;break;case`[7$`:i.name=`home`,i.shift=!0;break;case`[8$`:i.name=`end`,i.shift=!0;break;case`Oa`:i.name=`up`,i.ctrl=!0;break;case`Ob`:i.name=`down`,i.ctrl=!0;break;case`Oc`:i.name=`right`,i.ctrl=!0;break;case`Od`:i.name=`left`,i.ctrl=!0;break;case`[2^`:i.name=`insert`,i.ctrl=!0;break;case`[3^`:i.name=`delete`,i.ctrl=!0;break;case`[5^`:i.name=`pageup`,i.ctrl=!0;break;case`[6^`:i.name=`pagedown`,i.ctrl=!0;break;case`[7^`:i.name=`home`,i.ctrl=!0;break;case`[8^`:i.name=`end`,i.ctrl=!0;break;case`[Z`:i.name=`tab`,i.shift=!0;break;default:i.name=`undefined`;break}}else t===`\r`?(i.name=`return`,i.meta=r):t===`
2
- `?(i.name=`enter`,i.meta=r):t===` `?(i.name=`tab`,i.meta=r):t===`\b`||t===``?(i.name=`backspace`,i.meta=r):t===`\x1B`?(i.name=`escape`,i.meta=r):t===` `?(i.name=`space`,i.meta=r):!r&&t<=``?(i.name=String.fromCharCode(t.charCodeAt(0)+97-1),i.ctrl=!0):/^[0-9A-Za-z]$/.test(t)?(i.name=t.toLowerCase(),i.shift=/^[A-Z]$/.test(t),i.meta=r):r&&(i.name=t.length?void 0:`escape`,i.meta=!0);i.sequence=n,n.length!==0&&(i.name!==void 0||r)?e.emit(`keypress`,r?void 0:n,i):n.length===1&&e.emit(`keypress`,n,i)}}const r=Symbol(`keypress-decoder`),i=Symbol(`escape-decoder`);function emitKeypressEvents(e,n={}){if(e[r])return;e[r]=new t(`utf8`),e[i]=emitKeys(e),e[i].next();let a=n.escapeCodeTimeout??500,o,triggerEscape=()=>e[i].next(``);function onData(t){if(e.listenerCount(`keypress`)>0){let n=e[r].write(typeof t==`string`?Buffer.from(t):t);if(n){clearTimeout(o);for(let t of n)try{e[i].next(t),t===`\x1B`&&(o=setTimeout(triggerEscape,a))}catch{e[i]=emitKeys(e),e[i].next()}}}else e.removeListener(`data`,onData),delete e[r],delete e[i]}e.on(`data`,onData)}var a={Interface,createInterface,clearLine,clearScreenDown,cursorTo,moveCursor,emitKeypressEvents};export{Interface,clearLine,clearScreenDown,createInterface,cursorTo,a as default,emitKeypressEvents,moveCursor};
1
+ import"./_virtual/_rolldown/runtime.js";import{EventEmitter as e}from"node:events";import{StringDecoder as t}from"node:string_decoder";const n=/\r\n|\r|\n/;var Interface=class extends e{terminal;line=``;cursor=0;escapeCodeTimeout;_input;_output;get input(){return this._input}get output(){return this._output}_prompt;_closed=!1;_paused=!1;history;_historySize;_crlfDelay;_lineBuffer=``;_questionCallback=null;_boundOnData=null;_boundOnEnd=null;_boundOnError=null;_boundOnKeypress=null;constructor(e,t){super();let n;if(n=e&&typeof e==`object`&&!(`read`in e&&typeof e.read==`function`)?e:{input:e,output:t},this._input=n.input||null,this._output=n.output||null,this._prompt=n.prompt||`> `,this.terminal=n.terminal??this._output!==null,this._historySize=n.historySize??30,this.history=[],this._crlfDelay=n.crlfDelay??100,this.escapeCodeTimeout=n.escapeCodeTimeout,this._input&&(this._boundOnData=e=>this._onData(e),this._boundOnEnd=()=>this._onEnd(),this._boundOnError=e=>this.emit(`error`,e),this._input.on(`data`,this._boundOnData),this._input.on(`end`,this._boundOnEnd),this._input.on(`error`,this._boundOnError),`setEncoding`in this._input&&typeof this._input.setEncoding==`function`&&this._input.setEncoding(`utf8`),this.terminal)){emitKeypressEvents(this._input,this);let e=this._input;typeof e.setRawMode==`function`&&(e.isRaw||e.setRawMode(!0)),typeof this._input.resume==`function`&&this._input.resume(),this._boundOnKeypress=(e,t)=>{t&&(t.name===`backspace`||t.name===`delete`?this.cursor>0&&(this.line=this.line.slice(0,this.cursor-1)+this.line.slice(this.cursor),this.cursor--):e&&e.length===1&&!t.ctrl&&!t.meta&&t.name!==`return`&&t.name!==`enter`&&t.name!==`escape`&&(this.line=this.line.slice(0,this.cursor)+e+this.line.slice(this.cursor),this.cursor++))},this._input.on(`keypress`,this._boundOnKeypress)}}_onData(e){if(this._closed||this._paused)return;let t=typeof e==`string`?e:e.toString(`utf8`);this._lineBuffer+=t;let r;for(;(r=n.exec(this._lineBuffer))!==null;){let e=this._lineBuffer.substring(0,r.index);this._lineBuffer=this._lineBuffer.substring(r.index+r[0].length),this._onLine(e)}}_onLine(e){if(e.length>0&&this._historySize>0&&(this.history.length===0||this.history[0]!==e)&&(this.history.unshift(e),this.history.length>this._historySize&&this.history.pop()),this._questionCallback){let t=this._questionCallback;this._questionCallback=null,t(e)}this.emit(`line`,e)}_onEnd(){this._lineBuffer.length>0&&(this._onLine(this._lineBuffer),this._lineBuffer=``),this.close()}setPrompt(e){this._prompt=e}getPrompt(){return this._prompt}prompt(e){if(this._closed)throw Error(`readline was closed`);this._output?.write(this._prompt)}question(e,t,n){if(this._closed)throw Error(`readline was closed`);let r=typeof t==`function`?t:n;this._questionCallback=r,this._output?.write(e)}clearLine(e,t){return this.line=``,this.cursor=0,t&&t(),!0}write(e,t){if(!this._closed){if(t){this._input&&this._input.emit(`keypress`,e??``,t);return}if(e!=null){let t=typeof e==`string`?e:e.toString(`utf8`);t&&(this.line=this.line.slice(0,this.cursor)+t+this.line.slice(this.cursor),this.cursor+=t.length),this._output?.write(e)}}}close(){if(!this._closed){if(this._closed=!0,this._input){this._boundOnData&&this._input.removeListener(`data`,this._boundOnData),this._boundOnEnd&&this._input.removeListener(`end`,this._boundOnEnd),this._boundOnError&&this._input.removeListener(`error`,this._boundOnError),this._boundOnKeypress&&this._input.removeListener(`keypress`,this._boundOnKeypress),this._boundOnData=null,this._boundOnEnd=null,this._boundOnError=null,this._boundOnKeypress=null;let e=this._input;this.terminal&&e.isRaw&&typeof e.setRawMode==`function`&&e.setRawMode(!1),typeof this._input.pause==`function`&&this._input.pause()}this.emit(`close`)}}pause(){return this._closed?this:(this._paused=!0,this._input&&`pause`in this._input&&typeof this._input.pause==`function`&&this._input.pause(),this.emit(`pause`),this)}resume(){return this._closed?this:(this._paused=!1,this._input&&`resume`in this._input&&typeof this._input.resume==`function`&&this._input.resume(),this.emit(`resume`),this)}getCursorPos(){let e=this._output?.columns??80,t=this._prompt.length+this.cursor;return{rows:Math.floor(t/e),cols:t%e}}[Symbol.asyncIterator](){let e=[],t=null,n=!1,onLine=n=>{if(t){let e=t;t=null,e({value:n,done:!1})}else e.push(n)},onClose=()=>{if(n=!0,t){let e=t;t=null,e({value:void 0,done:!0})}};return this.on(`line`,onLine),this.on(`close`,onClose),{next:()=>e.length>0?Promise.resolve({value:e.shift(),done:!1}):n?Promise.resolve({value:void 0,done:!0}):new Promise(e=>{t=e}),return:()=>(n=!0,this.removeListener(`line`,onLine),this.removeListener(`close`,onClose),Promise.resolve({value:void 0,done:!0})),[Symbol.asyncIterator](){return this}}}};function createInterface(e,t,n,r){return typeof e==`object`&&e&&!(`read`in e&&typeof e.read==`function`)?new Interface(e):new Interface({input:e,output:t,completer:n,terminal:r})}function clearLine(e,t,n){if(!e||typeof e.write!=`function`)return n&&n(),!0;let r=t<0?`\x1B[1K`:t>0?`\x1B[0K`:`\x1B[2K`;return e.write(r,n)}function clearScreenDown(e,t){return!e||typeof e.write!=`function`?(t&&t(),!0):e.write(`\x1B[0J`,t)}function cursorTo(e,t,n,r){if(!e||typeof e.write!=`function`)return typeof n==`function`?n():r&&r(),!0;typeof n==`function`&&(r=n,n=void 0);let i=typeof n==`number`?`\x1b[${n+1};${t+1}H`:`\x1b[${t+1}G`;return e.write(i,r)}function moveCursor(e,t,n,r){if(!e||typeof e.write!=`function`)return r&&r(),!0;let i=``;return t>0?i+=`\x1b[${t}C`:t<0&&(i+=`\x1b[${-t}D`),n>0?i+=`\x1b[${n}B`:n<0&&(i+=`\x1b[${-n}A`),i?e.write(i,r):(r&&r(),!0)}function*emitKeys(e){for(;;){let t=yield,n=t,r=!1,i={sequence:``,name:void 0,ctrl:!1,meta:!1,shift:!1};if(t===`\x1B`&&(r=!0,n+=t=yield,t===`\x1B`&&(n+=t=yield)),r&&(t===`O`||t===`[`)){let e=t,r=0;if(t===`O`)n+=t=yield,t>=`0`&&t<=`9`&&(r=t.charCodeAt(0)-1,n+=t=yield),e+=t;else if(t===`[`){n+=t=yield,t===`[`&&(e+=t,n+=t=yield);let i=n.length-1;t>=`0`&&t<=`9`&&(n+=t=yield,t>=`0`&&t<=`9`&&(n+=t=yield,t>=`0`&&t<=`9`&&(n+=t=yield))),t===`;`&&(n+=t=yield,t>=`0`&&t<=`9`&&(n+=yield));let a=n.slice(i),o;(o=/^(?:(\d\d?)(?:;(\d))?([~^$])|(\d{3}~))$/.exec(a))?o[4]?e+=o[4]:(e+=o[1]+o[3],r=(parseInt(o[2]??`1`,10)||1)-1):(o=/^((\d;)?(\d))?([A-Za-z])$/.exec(a))?(e+=o[4],r=(parseInt(o[3]??`1`,10)||1)-1):e+=a}switch(i.ctrl=!!(r&4),i.meta=!!(r&10),i.shift=!!(r&1),i.code=e,e){case`[P`:case`OP`:case`[11~`:case`[[A`:i.name=`f1`;break;case`[Q`:case`OQ`:case`[12~`:case`[[B`:i.name=`f2`;break;case`[R`:case`OR`:case`[13~`:case`[[C`:i.name=`f3`;break;case`[S`:case`OS`:case`[14~`:case`[[D`:i.name=`f4`;break;case`[15~`:case`[[E`:i.name=`f5`;break;case`[17~`:i.name=`f6`;break;case`[18~`:i.name=`f7`;break;case`[19~`:i.name=`f8`;break;case`[20~`:i.name=`f9`;break;case`[21~`:i.name=`f10`;break;case`[23~`:i.name=`f11`;break;case`[24~`:i.name=`f12`;break;case`[200~`:i.name=`paste-start`;break;case`[201~`:i.name=`paste-end`;break;case`[A`:case`OA`:i.name=`up`;break;case`[B`:case`OB`:i.name=`down`;break;case`[C`:case`OC`:i.name=`right`;break;case`[D`:case`OD`:i.name=`left`;break;case`[E`:case`OE`:i.name=`clear`;break;case`[F`:case`OF`:i.name=`end`;break;case`[H`:case`OH`:i.name=`home`;break;case`[1~`:i.name=`home`;break;case`[2~`:i.name=`insert`;break;case`[3~`:i.name=`delete`;break;case`[4~`:i.name=`end`;break;case`[5~`:case`[[5~`:i.name=`pageup`;break;case`[6~`:case`[[6~`:i.name=`pagedown`;break;case`[7~`:i.name=`home`;break;case`[8~`:i.name=`end`;break;case`[a`:i.name=`up`,i.shift=!0;break;case`[b`:i.name=`down`,i.shift=!0;break;case`[c`:i.name=`right`,i.shift=!0;break;case`[d`:i.name=`left`,i.shift=!0;break;case`[2$`:i.name=`insert`,i.shift=!0;break;case`[3$`:i.name=`delete`,i.shift=!0;break;case`[5$`:i.name=`pageup`,i.shift=!0;break;case`[6$`:i.name=`pagedown`,i.shift=!0;break;case`[7$`:i.name=`home`,i.shift=!0;break;case`[8$`:i.name=`end`,i.shift=!0;break;case`Oa`:i.name=`up`,i.ctrl=!0;break;case`Ob`:i.name=`down`,i.ctrl=!0;break;case`Oc`:i.name=`right`,i.ctrl=!0;break;case`Od`:i.name=`left`,i.ctrl=!0;break;case`[2^`:i.name=`insert`,i.ctrl=!0;break;case`[3^`:i.name=`delete`,i.ctrl=!0;break;case`[5^`:i.name=`pageup`,i.ctrl=!0;break;case`[6^`:i.name=`pagedown`,i.ctrl=!0;break;case`[7^`:i.name=`home`,i.ctrl=!0;break;case`[8^`:i.name=`end`,i.ctrl=!0;break;case`[Z`:i.name=`tab`,i.shift=!0;break;default:i.name=`undefined`;break}}else t===`\r`?(i.name=`return`,i.meta=r):t===`
2
+ `?(i.name=`enter`,i.meta=r):t===` `?(i.name=`tab`,i.meta=r):t===`\b`||t===``?(i.name=`backspace`,i.meta=r):t===`\x1B`?(i.name=`escape`,i.meta=r):t===` `?(i.name=`space`,i.meta=r):!r&&t<=``?(i.name=String.fromCharCode(t.charCodeAt(0)+97-1),i.ctrl=!0):/^[0-9A-Za-z]$/.test(t)?(i.name=t.toLowerCase(),i.shift=/^[A-Z]$/.test(t),i.meta=r):r&&(i.name=t.length?void 0:`escape`,i.meta=!0);i.sequence=n,n.length!==0&&(i.name!==void 0||r)?e.emit(`keypress`,r?void 0:n,i):n.length===1&&e.emit(`keypress`,n,i)}}const r=Symbol(`keypress-decoder`),i=Symbol(`escape-decoder`);function emitKeypressEvents(e,n={}){let a=e;if(a[r])return;a[r]=new t(`utf8`),a[i]=emitKeys(e),a[i].next();let o=n.escapeCodeTimeout??500,s,triggerEscape=()=>a[i].next(``);function onData(t){if(e.listenerCount(`keypress`)>0){let n=a[r].write(typeof t==`string`?Buffer.from(t):t);if(n){clearTimeout(s);for(let t of n)try{a[i].next(t),t===`\x1B`&&(s=setTimeout(triggerEscape,o))}catch{a[i]=emitKeys(e),a[i].next()}}}else e.removeListener(`data`,onData),delete a[r],delete a[i]}e.on(`data`,onData)}var a={Interface,createInterface,clearLine,clearScreenDown,cursorTo,moveCursor,emitKeypressEvents};export{Interface,clearLine,clearScreenDown,createInterface,cursorTo,a as default,emitKeypressEvents,moveCursor};
File without changes
@@ -1 +1 @@
1
- import{Interface as e}from"./index.js";var Interface=class extends e{question(e,t){return new Promise(t=>{super.question(e,t)})}};function createInterface(e,t){return typeof e==`object`&&e&&!(`read`in e&&typeof e.read==`function`)?new Interface(e):new Interface({input:e,output:t})}var t={Interface,createInterface};export{Interface,createInterface,t as default};
1
+ import"./_virtual/_rolldown/runtime.js";import{Interface as e}from"./index.js";var Interface=class extends e{question(e,t){return new Promise(t=>{super.question(e,t)})}};function createInterface(e,t){return typeof e==`object`&&e&&!(`read`in e&&typeof e.read==`function`)?new Interface(e):new Interface({input:e,output:t})}var t={Interface,createInterface};export{Interface,createInterface,t as default};
@@ -16,6 +16,7 @@ export declare class Interface extends EventEmitter {
16
16
  terminal: boolean;
17
17
  line: string;
18
18
  cursor: number;
19
+ escapeCodeTimeout?: number;
19
20
  private _input;
20
21
  private _output;
21
22
  get input(): Readable | null;
@@ -70,7 +71,7 @@ export interface Key {
70
71
  shift: boolean;
71
72
  code?: string;
72
73
  }
73
- export declare function emitKeypressEvents(stream: Readable & Record<symbol, unknown>, iface?: {
74
+ export declare function emitKeypressEvents(stream: Readable, iface?: {
74
75
  escapeCodeTimeout?: number;
75
76
  }): void;
76
77
  declare const _default: {
@@ -0,0 +1,48 @@
1
+ import type { Readable, Writable } from 'node:stream';
2
+ import type { StringDecoder } from 'node:string_decoder';
3
+ /**
4
+ * `Readable` augmented with the TTY-specific runtime methods that exist
5
+ * on `tty.ReadStream` and on `@gjsify/process`'s `ProcessReadStream`.
6
+ * All members are optional — readline always guards with `'method' in stream`
7
+ * + `typeof stream.method === 'function'` before calling.
8
+ */
9
+ export interface GjsReadableTty extends Readable {
10
+ isRaw?: boolean;
11
+ isTTY?: boolean;
12
+ setRawMode?(enable: boolean): this;
13
+ }
14
+ /**
15
+ * `Writable` augmented with the TTY-specific runtime properties that exist
16
+ * on `tty.WriteStream` and on `@gjsify/process`'s `ProcessWriteStream`.
17
+ * All members are optional for the same reason as `GjsReadableTty`.
18
+ */
19
+ export interface GjsWritableTty extends Writable {
20
+ columns?: number;
21
+ rows?: number;
22
+ isTTY?: boolean;
23
+ getColorDepth?(env?: NodeJS.ProcessEnv): number;
24
+ hasColors?(count?: number, env?: NodeJS.ProcessEnv): boolean;
25
+ }
26
+ /**
27
+ * Symbol-keyed runtime state that `emitKeypressEvents` attaches to the
28
+ * input stream. The two private symbols carry the per-stream
29
+ * `StringDecoder` and the live `emitKeys` generator, plus a re-entrancy
30
+ * guard so the second call on the same stream is a no-op.
31
+ *
32
+ * Modeled as an intersection (rather than `extends Readable` with a
33
+ * `[key: symbol]` index signature) because `Readable` already declares
34
+ * built-in symbol keys — `EventEmitter.captureRejectionSymbol`,
35
+ * `Symbol.asyncDispose`, `Symbol.asyncIterator` — whose value types
36
+ * would conflict with a narrow union signature.
37
+ */
38
+ export type KeypressTaggedStream = Readable & {
39
+ [key: symbol]: StringDecoder | Generator<void, void, string> | undefined;
40
+ };
41
+ /**
42
+ * Minimal `EventEmitter`-like shape used by the keypress parser to dispatch
43
+ * `'keypress'` events back onto the stream. `Readable` already satisfies
44
+ * this via its `EventEmitter` ancestry.
45
+ */
46
+ export interface KeypressEmitter {
47
+ emit(event: string | symbol, ...args: unknown[]): boolean;
48
+ }
package/package.json CHANGED
@@ -1,45 +1,48 @@
1
1
  {
2
- "name": "@gjsify/readline",
3
- "version": "0.3.21",
4
- "description": "Node.js readline module for Gjs",
5
- "type": "module",
6
- "module": "lib/esm/index.js",
7
- "types": "lib/types/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./lib/types/index.d.ts",
11
- "default": "./lib/esm/index.js"
2
+ "name": "@gjsify/readline",
3
+ "version": "0.4.3",
4
+ "description": "Node.js readline module for Gjs",
5
+ "type": "module",
6
+ "module": "lib/esm/index.js",
7
+ "types": "lib/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/types/index.d.ts",
11
+ "default": "./lib/esm/index.js"
12
+ },
13
+ "./promises": {
14
+ "types": "./lib/types/promises.d.ts",
15
+ "default": "./lib/esm/promises.js"
16
+ }
12
17
  },
13
- "./promises": {
14
- "types": "./lib/types/promises.d.ts",
15
- "default": "./lib/esm/promises.js"
18
+ "files": [
19
+ "lib"
20
+ ],
21
+ "scripts": {
22
+ "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
23
+ "check": "tsc --noEmit",
24
+ "build": "gjsify run build:gjsify && gjsify run build:types",
25
+ "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
26
+ "build:types": "tsc",
27
+ "build:test": "gjsify run build:test:gjs && gjsify run build:test:node",
28
+ "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
29
+ "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
30
+ "test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:node && gjsify run test:gjs",
31
+ "test:gjs": "gjsify run test.gjs.mjs",
32
+ "test:node": "node test.node.mjs"
33
+ },
34
+ "keywords": [
35
+ "gjs",
36
+ "node",
37
+ "readline"
38
+ ],
39
+ "dependencies": {
40
+ "@gjsify/events": "workspace:^"
41
+ },
42
+ "devDependencies": {
43
+ "@gjsify/cli": "workspace:^",
44
+ "@gjsify/unit": "workspace:^",
45
+ "@types/node": "^25.6.2",
46
+ "typescript": "^6.0.3"
16
47
  }
17
- },
18
- "scripts": {
19
- "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
20
- "check": "tsc --noEmit",
21
- "build": "yarn build:gjsify && yarn build:types",
22
- "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
23
- "build:types": "tsc",
24
- "build:test": "yarn build:test:gjs && yarn build:test:node",
25
- "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
26
- "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
27
- "test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
28
- "test:gjs": "gjsify run test.gjs.mjs",
29
- "test:node": "node test.node.mjs"
30
- },
31
- "keywords": [
32
- "gjs",
33
- "node",
34
- "readline"
35
- ],
36
- "dependencies": {
37
- "@gjsify/events": "^0.3.21"
38
- },
39
- "devDependencies": {
40
- "@gjsify/cli": "^0.3.21",
41
- "@gjsify/unit": "^0.3.21",
42
- "@types/node": "^25.6.2",
43
- "typescript": "^6.0.3"
44
- }
45
- }
48
+ }