1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

fix(ext/node): allow writing to tty columns (#26201)

Behave similar to Node.js where modifying `stdout.columns` doesn't
really resize the terminal. Ref
https://github.com/nodejs/node/issues/17529

Fixes https://github.com/denoland/deno/issues/26196
This commit is contained in:
Divy Srivastava 2024-10-14 14:00:02 +05:30 committed by GitHub
parent d22195e741
commit 68b388a93a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -66,14 +66,19 @@ export function createWritableStdioStream(writer, name, warmup = false) {
// We cannot call `writer?.isTerminal()` eagerly here
let getIsTTY = () => writer?.isTerminal();
const getColumns = () =>
stream._columns ||
(writer?.isTerminal() ? Deno.consoleSize?.().columns : undefined);
ObjectDefineProperties(stream, {
columns: {
__proto__: null,
enumerable: true,
configurable: true,
get: () =>
writer?.isTerminal() ? Deno.consoleSize?.().columns : undefined,
get: () => getColumns(),
set: (value) => {
stream._columns = value;
},
},
rows: {
__proto__: null,

View file

@ -1175,3 +1175,8 @@ Deno.test("process.cpuUsage()", () => {
assert(typeof cpuUsage.user === "number");
assert(typeof cpuUsage.system === "number");
});
Deno.test("process.stdout.columns writable", () => {
process.stdout.columns = 80;
assertEquals(process.stdout.columns, 80);
});