mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 09:56:23 +00:00
17 lines
437 B
TypeScript
17 lines
437 B
TypeScript
import { Writable } from "node:stream";
|
|
|
|
export const captureOutput = (terminal = false) => {
|
|
const chunks: Buffer[] = [];
|
|
const destination = new Writable({
|
|
write(chunk: Buffer, _encoding, callback) {
|
|
chunks.push(chunk);
|
|
callback();
|
|
},
|
|
});
|
|
if (terminal) Object.defineProperty(destination, "isTTY", { value: true });
|
|
return {
|
|
destination,
|
|
text: () => Buffer.concat(chunks).toString("utf8"),
|
|
};
|
|
};
|