diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/io/12_io.js | 13 | ||||
-rw-r--r-- | ext/node/polyfills/_process/streams.mjs | 15 | ||||
-rw-r--r-- | ext/node/polyfills/assertion_error.ts | 4 | ||||
-rw-r--r-- | ext/node/polyfills/tty.js | 12 |
4 files changed, 31 insertions, 13 deletions
diff --git a/ext/io/12_io.js b/ext/io/12_io.js index d9b91a947..9f4a3766b 100644 --- a/ext/io/12_io.js +++ b/ext/io/12_io.js @@ -7,6 +7,7 @@ import { core, primordials } from "ext:core/mod.js"; const { op_stdin_set_raw, + op_is_terminal, } = core.ensureFastOps(true); const { Uint8Array, @@ -197,6 +198,10 @@ class Stdin { const cbreak = !!(options.cbreak ?? false); op_stdin_set_raw(mode, cbreak); } + + isTerminal() { + return op_is_terminal(this.rid); + } } class Stdout { @@ -227,6 +232,10 @@ class Stdout { } return this.#writable; } + + isTerminal() { + return op_is_terminal(this.rid); + } } class Stderr { @@ -257,6 +266,10 @@ class Stderr { } return this.#writable; } + + isTerminal() { + return op_is_terminal(this.rid); + } } const stdin = new Stdin(); diff --git a/ext/node/polyfills/_process/streams.mjs b/ext/node/polyfills/_process/streams.mjs index 14d58fcab..166d099c8 100644 --- a/ext/node/polyfills/_process/streams.mjs +++ b/ext/node/polyfills/_process/streams.mjs @@ -46,30 +46,27 @@ export function createWritableStdioStream(writer, name) { enumerable: true, configurable: true, get: () => - Deno.isatty?.(writer?.rid) ? Deno.consoleSize?.().columns : undefined, + writer?.isTerminal() ? Deno.consoleSize?.().columns : undefined, }, rows: { enumerable: true, configurable: true, - get: () => - Deno.isatty?.(writer?.rid) ? Deno.consoleSize?.().rows : undefined, + get: () => writer?.isTerminal() ? Deno.consoleSize?.().rows : undefined, }, isTTY: { enumerable: true, configurable: true, - get: () => Deno.isatty?.(writer?.rid), + get: () => writer?.isTerminal(), }, getWindowSize: { enumerable: true, configurable: true, value: () => - Deno.isatty?.(writer?.rid) - ? Object.values(Deno.consoleSize?.()) - : undefined, + writer?.isTerminal() ? Object.values(Deno.consoleSize?.()) : undefined, }, }); - if (Deno.isatty?.(writer?.rid)) { + if (writer?.isTerminal()) { // These belong on tty.WriteStream(), but the TTY streams currently have // following problems: // 1. Using them here introduces a circular dependency. @@ -180,7 +177,7 @@ export const initStdin = () => { enumerable: true, configurable: true, get() { - return Deno.isatty?.(io.stdin.rid); + return io.stdin.isTerminal(); }, }); stdin._isRawMode = false; diff --git a/ext/node/polyfills/assertion_error.ts b/ext/node/polyfills/assertion_error.ts index bec1f6ba5..ff1168dc3 100644 --- a/ext/node/polyfills/assertion_error.ts +++ b/ext/node/polyfills/assertion_error.ts @@ -163,7 +163,7 @@ export function createErrDiff( // If the stderr is a tty and the input length is lower than the current // columns per line, add a mismatch indicator below the output. If it is // not a tty, use a default value of 80 characters. - const maxLength = Deno.isatty(io.stderr.rid) ? getConsoleWidth() : 80; + const maxLength = io.stderr.isTerminal() ? getConsoleWidth() : 80; if (inputLength < maxLength) { while (actualRaw[i] === expectedRaw[i]) { i++; @@ -406,7 +406,7 @@ export class AssertionError extends Error { if (message != null) { super(String(message)); } else { - if (Deno.isatty(io.stderr.rid)) { + if (io.stderr.isTerminal()) { // Reset on each call to make sure we handle dynamically set environment // variables correct. if (Deno.noColor) { diff --git a/ext/node/polyfills/tty.js b/ext/node/polyfills/tty.js index 86fd34d7c..eae1db2d9 100644 --- a/ext/node/polyfills/tty.js +++ b/ext/node/polyfills/tty.js @@ -1,9 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { primordials } from "ext:core/mod.js"; +import { core, primordials } from "ext:core/mod.js"; const { Error, } = primordials; +const { + op_is_terminal, +} = core.ensureFastOps(true); import { ERR_INVALID_FD } from "ext:deno_node/internal/errors.ts"; import { LibuvStreamWrap } from "ext:deno_node/internal_binding/stream_wrap.ts"; @@ -17,7 +20,12 @@ function isatty(fd) { return false; } try { - return Deno.isatty(fd); + /** + * TODO: Treat `fd` as real file descriptors. Currently, `rid` 0, 1, 2 + * correspond to `fd` 0, 1, 2 (stdin, stdout, stderr). This may change in + * the future. + */ + return op_is_terminal(fd); } catch (_) { return false; } |