Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839// process.stdout and process.stderr: write-only emitters over fds 1 and 2. Writes leave// at once, as Node's are synchronous for pipes and terminals. On a pty, tty.WriteStream// extends this with the terminal surface.import { EventEmitter, type EventEmitterConstructor } from "./events";
const enc = new TextEncoder();
export class StdioWriter extends (EventEmitter as unknown as EventEmitterConstructor) { readonly fd: number; readonly writable = true; /** Node leaves isTTY undefined on a pipe; tty.WriteStream sets it on its prototype. */ declare readonly isTTY?: boolean; #emit: (bytes: Uint8Array) => void; #nextTick: (fn: () => void) => void;
constructor(fd: number, emit: (bytes: Uint8Array) => void, nextTick: (fn: () => void) => void) { super(); this.fd = fd; this.#emit = emit; this.#nextTick = nextTick; }
write(chunk: string | Uint8Array, encoding?: string | (() => void), cb?: () => void): boolean { const done = typeof encoding === "function" ? encoding : cb; const bytes = typeof chunk === "string" ? enc.encode(chunk) : chunk; if (bytes.length) this.#emit(bytes); if (done) this.#nextTick(done); return true; }
// stdout and stderr never close in Node; end() writes and calls back. end(chunk?: string | Uint8Array | (() => void), cb?: () => void): this { if (typeof chunk === "function") cb = chunk; else if (chunk !== undefined) this.write(chunk); if (cb) this.#nextTick(cb); return this; }}