mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix(node): make process.stdout.isTTY
writable (#26130)
Fixes https://github.com/denoland/deno/issues/26123
This commit is contained in:
parent
94b588ce66
commit
9117a9a43c
2 changed files with 19 additions and 1 deletions
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue