@gjsify/process 0.7.3 → 0.7.5
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/lib/esm/streams.js +1 -1
- package/lib/types/streams.d.ts +3 -1
- package/package.json +7 -6
package/lib/esm/streams.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{getGioNamespace as e,getGjsGlobal as t}from"./internal/gjs.js";import{nativeTerminal as n}from"@gjsify/terminal-native";import{EventEmitter as r}from"@gjsify/events";import{ensureMainLoop as i,quitMainLoop as a}from"@gjsify/utils";const
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{getGioNamespace as e,getGjsGlobal as t}from"./internal/gjs.js";import{nativeTerminal as n}from"@gjsify/terminal-native";import{EventEmitter as r}from"@gjsify/events";import{ensureMainLoop as i,quitMainLoop as a}from"@gjsify/utils";import{StringDecoder as o}from"@gjsify/string_decoder";const s=new TextEncoder;var ProcessWriteStream=class extends r{fd;writable=!0;_outGio=null;constructor(t){super(),this.fd=t;let n=e();if(n){let e=n.UnixOutputStream??n.OutputStream;if(e)try{this._outGio=e.new(this.fd,!1)}catch{}}}write(e){if(this._outGio)try{let t=typeof e==`string`?s.encode(e):e;return this._outGio.write_all(t,null),!0}catch{}return this.fd===2?console.error(e):console.log(e),!0}get isTTY(){if(n)return n.Terminal.is_tty(this.fd);try{let e=t().imports?.gi?.GLib;if(e)return!!e.log_writer_supports_color(this.fd)}catch{}return!1}get columns(){if(n){let[e,,t]=n.Terminal.get_size(this.fd);if(e&&t>0)return t}try{let e=t().imports?.gi?.GLib;if(e){let t=parseInt(e.getenv(`COLUMNS`)??`0`,10);if(t>0)return t}}catch{}return 80}end(){}destroy(){}get rows(){if(n){let[e,t]=n.Terminal.get_size(this.fd);if(e&&t>0)return t}try{let e=t().imports?.gi?.GLib;if(e){let t=parseInt(e.getenv(`LINES`)??`0`,10);if(t>0)return t}}catch{}return 24}},ProcessReadStream=class extends r{fd;isRaw=!1;_gio=null;_stdinGio=null;_reading=!1;_flowing=!1;_sttyCleanupRegistered=!1;_mainLoopHeld=!1;_pendingRead=!1;_decoder=null;constructor(t){super(),this.fd=t,this._gio=e()}get isTTY(){return n?n.Terminal.is_tty(this.fd):!1}setRawMode(e){return n&&n.Terminal.set_raw_mode(this.fd,e)?(this.isRaw=e,this):(this._setRawModeViaStty(e),this.isRaw=e,this)}_setRawModeViaStty(e){try{let t=globalThis.imports?.gi,n=t?.Gio??t?.Gio;if(!n)return;let r=n.SubprocessFlags?.STDIN_INHERIT??2,i=e?[`stty`,`-icanon`,`-echo`,`-icrnl`,`min`,`1`,`time`,`0`]:[`stty`,`icanon`,`echo`,`icrnl`];if(new n.SubprocessLauncher({flags:r}).spawnv(i).wait(null),e&&!this._sttyCleanupRegistered){this._sttyCleanupRegistered=!0;let e=globalThis.process;e?.once&&typeof e.once==`function`&&e.once(`exit`,()=>this._setRawModeViaStty(!1))}}catch{}}setEncoding(e){return this._decoder=new o(e),this}_pushData(e){if(this._decoder){let t=this._decoder.write(e);t.length>0&&this.emit(`data`,t)}else this.emit(`data`,e)}on(e,t){let n=e===`data`&&this.listenerCount(`data`)===0;return super.on(e,t),n&&e===`data`&&this.resume(),this}addListener(e,t){return this.on(e,t)}once(e,t){return super.once(e,t),this}removeListener(e,t){return super.removeListener(e,t),e===`data`&&this.listenerCount(`data`)===0&&this.pause(),this}off(e,t){return this.removeListener(e,t)}removeAllListeners(e){let t=e===void 0||e===`data`?this.listenerCount(`data`)>0:!1;return super.removeAllListeners(e),t&&this.listenerCount(`data`)===0&&this.pause(),this}resume(){return this._flowing=!0,this._gio&&this.fd===0&&!this._reading&&this._startReading(),this}pause(){if(this._flowing=!1,this._reading=!1,this._mainLoopHeld){this._mainLoopHeld=!1;let e=globalThis.imports?.gi,t=e?.GLib??e?.GLib;t?.idle_add?t.idle_add(300,()=>(this._mainLoopHeld||a(),!1)):a()}return this}read(){return null}_startReading(){if(!this._gio||this._reading)return;if(this._pendingRead){this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,i());return}if(this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,i()),!this._stdinGio){let e=this._gio.UnixInputStream??this._gio.InputStream;if(!e){this._reading=!1;return}try{this._stdinGio=e.new(this.fd,!1)}catch{this._reading=!1;return}}let loop=()=>{if(!this._reading){this._pendingRead=!1;return}this._pendingRead=!0,this._stdinGio.read_bytes_async(4096,0,null,(e,t)=>{this._pendingRead=!1;try{let n=e.read_bytes_finish(t)?.get_data?.()??null;if(n&&n.byteLength>0)this._pushData(Buffer.from(n));else if(n!==null&&n.byteLength===0){if(this._reading=!1,this._decoder){let e=this._decoder.end();e.length>0&&this.emit(`data`,e)}this.emit(`end`);return}}catch{this._reading=!1;return}this._reading&&loop()})};loop()}};export{ProcessReadStream,ProcessWriteStream};
|
package/lib/types/streams.d.ts
CHANGED
|
@@ -21,11 +21,13 @@ export declare class ProcessReadStream extends EventEmitter {
|
|
|
21
21
|
private _sttyCleanupRegistered;
|
|
22
22
|
private _mainLoopHeld;
|
|
23
23
|
private _pendingRead;
|
|
24
|
+
private _decoder;
|
|
24
25
|
constructor(fd: number);
|
|
25
26
|
get isTTY(): boolean;
|
|
26
27
|
setRawMode(mode: boolean): this;
|
|
27
28
|
private _setRawModeViaStty;
|
|
28
|
-
setEncoding(
|
|
29
|
+
setEncoding(enc: string): this;
|
|
30
|
+
protected _pushData(buf: Buffer): void;
|
|
29
31
|
on(type: string | symbol, listener: (...args: unknown[]) => void): this;
|
|
30
32
|
addListener(type: string | symbol, listener: (...args: unknown[]) => void): this;
|
|
31
33
|
once(type: string | symbol, listener: (...args: unknown[]) => void): this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/process",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"description": "Node.js process module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -40,13 +40,14 @@
|
|
|
40
40
|
"process"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@gjsify/events": "^0.7.
|
|
44
|
-
"@gjsify/
|
|
45
|
-
"@gjsify/
|
|
43
|
+
"@gjsify/events": "^0.7.5",
|
|
44
|
+
"@gjsify/string_decoder": "^0.7.5",
|
|
45
|
+
"@gjsify/terminal-native": "^0.7.5",
|
|
46
|
+
"@gjsify/utils": "^0.7.5"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@gjsify/cli": "^0.7.
|
|
49
|
-
"@gjsify/unit": "^0.7.
|
|
49
|
+
"@gjsify/cli": "^0.7.5",
|
|
50
|
+
"@gjsify/unit": "^0.7.5",
|
|
50
51
|
"@types/node": "^25.9.2",
|
|
51
52
|
"typescript": "^6.0.3"
|
|
52
53
|
},
|