1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(node): make process.stdout.isTTY writable (#26130)

Fixes https://github.com/denoland/deno/issues/26123
This commit is contained in:
Marvin Hagemeister 2024-10-11 19:14:10 +02:00 committed by GitHub
parent 94b588ce66
commit 9117a9a43c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -63,6 +63,10 @@ export function createWritableStdioStream(writer, name, warmup = false) {
stream.destroySoon = stream.destroy;
stream._isStdio = true;
stream.once("close", () => writer?.close());
// We cannot call `writer?.isTerminal()` eagerly here
let getIsTTY = () => writer?.isTerminal();
ObjectDefineProperties(stream, {
columns: {
__proto__: null,
@ -81,7 +85,11 @@ export function createWritableStdioStream(writer, name, warmup = false) {
__proto__: null,
enumerable: true,
configurable: true,
get: () => writer?.isTerminal(),
// Allow users to overwrite it
get: () => getIsTTY(),
set: (value) => {
getIsTTY = () => value;
},
},
getWindowSize: {
__proto__: null,

View file

@ -691,6 +691,16 @@ Deno.test({
assertStrictEquals(process.stdout.clearLine, undefined);
assertStrictEquals(process.stdout.clearScreenDown, undefined);
}
// Allows overwriting `process.stdout.isTTY`
// https://github.com/denoland/deno/issues/26123
const original = process.stdout.isTTY;
try {
process.stdout.isTTY = !isTTY;
assertEquals(process.stdout.isTTY, !isTTY);
} finally {
process.stdout.isTTY = original;
}
},
});