summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/tty.js
diff options
context:
space:
mode:
authorAsher Gomez <ashersaupingomez@gmail.com>2024-01-24 10:01:56 +1100
committerGitHub <noreply@github.com>2024-01-24 00:01:56 +0100
commit4eedac3604dad9f366d28868077eb02eddc22661 (patch)
treedda70cd31e731aad73e986002ef30acb84692dc4 /ext/node/polyfills/tty.js
parent60688c563e6d02813b021ad91132fe1eb3f103b6 (diff)
feat: `Deno.{stdin,stdout,stderr}.isTerminal()`, deprecate `Deno.isatty()` (#22011)
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 <biwanczuk@gmail.com> Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Diffstat (limited to 'ext/node/polyfills/tty.js')
-rw-r--r--ext/node/polyfills/tty.js12
1 files changed, 10 insertions, 2 deletions
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;
}