summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-10-14 14:00:02 +0530
committerGitHub <noreply@github.com>2024-10-14 14:00:02 +0530
commit68b388a93a3efe443fc5e306e883847bfb8551db (patch)
tree33d749c5488803d9b253b5cf19556412279fa92b
parentd22195e7416e7923e2868e3f250abb457f115fc6 (diff)
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
-rw-r--r--ext/node/polyfills/_process/streams.mjs9
-rw-r--r--tests/unit_node/process_test.ts5
2 files changed, 12 insertions, 2 deletions
diff --git a/ext/node/polyfills/_process/streams.mjs b/ext/node/polyfills/_process/streams.mjs
index 7936e82aa..3573956c9 100644
--- a/ext/node/polyfills/_process/streams.mjs
+++ b/ext/node/polyfills/_process/streams.mjs
@@ -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,
diff --git a/tests/unit_node/process_test.ts b/tests/unit_node/process_test.ts
index 0e0f169d6..9506fb609 100644
--- a/tests/unit_node/process_test.ts
+++ b/tests/unit_node/process_test.ts
@@ -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);
+});