From 4eedac3604dad9f366d28868077eb02eddc22661 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Wed, 24 Jan 2024 10:01:56 +1100 Subject: feat: `Deno.{stdin,stdout,stderr}.isTerminal()`, deprecate `Deno.isatty()` (#22011) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change: 1. Implements `Deno.stdin.isTerminal()`, `Deno.stdout.isTerminal()` and `Deno.stderr.isTerminal()`. 2. Deprecates `Deno.isatty()` for removal in Deno v2, in favour of the above instance methods. 3. Replaces use of `Deno.isatty()` with the above instance methods. Related #21995 --------- Co-authored-by: Bartek IwaƄczuk Co-authored-by: Divy Srivastava --- ext/node/polyfills/tty.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ext/node/polyfills/tty.js') 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; } -- cgit v1.2.3