diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/tests/unit/tty_test.ts | 2 | ||||
-rw-r--r-- | cli/tests/unit_node/process_test.ts | 8 | ||||
-rw-r--r-- | cli/tests/unit_node/tty_test.ts | 10 | ||||
-rw-r--r-- | cli/tsc/dts/lib.deno.ns.d.ts | 37 |
4 files changed, 47 insertions, 10 deletions
diff --git a/cli/tests/unit/tty_test.ts b/cli/tests/unit/tty_test.ts index f6dc33b6a..8ca9a5d5b 100644 --- a/cli/tests/unit/tty_test.ts +++ b/cli/tests/unit/tty_test.ts @@ -4,7 +4,7 @@ import { assert } from "./test_util.ts"; // Note tests for Deno.stdin.setRaw is in integration tests. Deno.test(function consoleSize() { - if (!Deno.isatty(Deno.stdout.rid)) { + if (!Deno.stdout.isTerminal()) { return; } const result = Deno.consoleSize(); diff --git a/cli/tests/unit_node/process_test.ts b/cli/tests/unit_node/process_test.ts index 4cea31ed6..23bf73864 100644 --- a/cli/tests/unit_node/process_test.ts +++ b/cli/tests/unit_node/process_test.ts @@ -356,14 +356,14 @@ Deno.test({ name: "process.stdin", fn() { assertEquals(process.stdin.fd, Deno.stdin.rid); - assertEquals(process.stdin.isTTY, Deno.isatty(Deno.stdin.rid)); + assertEquals(process.stdin.isTTY, Deno.stdin.isTerminal()); }, }); Deno.test({ name: "process.stdin readable with a TTY", // TODO(PolarETech): Run this test even in non tty environment - ignore: !Deno.isatty(Deno.stdin.rid), + ignore: !Deno.stdin.isTerminal(), // stdin resource is present before the test starts. sanitizeResources: false, async fn() { @@ -535,7 +535,7 @@ Deno.test({ name: "process.stdout", fn() { assertEquals(process.stdout.fd, Deno.stdout.rid); - const isTTY = Deno.isatty(Deno.stdout.rid); + const isTTY = Deno.stdout.isTerminal(); assertEquals(process.stdout.isTTY, isTTY); const consoleSize = isTTY ? Deno.consoleSize() : undefined; assertEquals(process.stdout.columns, consoleSize?.columns); @@ -563,7 +563,7 @@ Deno.test({ name: "process.stderr", fn() { assertEquals(process.stderr.fd, Deno.stderr.rid); - const isTTY = Deno.isatty(Deno.stderr.rid); + const isTTY = Deno.stderr.isTerminal(); assertEquals(process.stderr.isTTY, isTTY); const consoleSize = isTTY ? Deno.consoleSize() : undefined; assertEquals(process.stderr.columns, consoleSize?.columns); diff --git a/cli/tests/unit_node/tty_test.ts b/cli/tests/unit_node/tty_test.ts index c393da5b3..8e2f66f9e 100644 --- a/cli/tests/unit_node/tty_test.ts +++ b/cli/tests/unit_node/tty_test.ts @@ -6,9 +6,9 @@ import { isatty } from "node:tty"; import process from "node:process"; Deno.test("[node/tty isatty] returns true when fd is a tty, false otherwise", () => { - assert(Deno.isatty(Deno.stdin.rid) === isatty(Deno.stdin.rid)); - assert(Deno.isatty(Deno.stdout.rid) === isatty(Deno.stdout.rid)); - assert(Deno.isatty(Deno.stderr.rid) === isatty(Deno.stderr.rid)); + assert(Deno.stdin.isTerminal() === isatty(Deno.stdin.rid)); + assert(Deno.stdout.isTerminal() === isatty(Deno.stdout.rid)); + assert(Deno.stderr.isTerminal() === isatty(Deno.stderr.rid)); const file = Deno.openSync("README.md"); assert(!isatty(file.rid)); @@ -32,6 +32,6 @@ Deno.test("[node/tty isatty] returns false for irrelevant values", () => { }); Deno.test("[node/tty WriteStream.isTTY] returns true when fd is a tty", () => { - assert(Deno.isatty(Deno.stdin.rid) === process.stdin.isTTY); - assert(Deno.isatty(Deno.stdout.rid) === process.stdout.isTTY); + assert(Deno.stdin.isTerminal() === process.stdin.isTTY); + assert(Deno.stdout.isTerminal() === process.stdout.isTTY); }); diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index 483c5c3d0..bc3248d02 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -2612,6 +2612,17 @@ declare namespace Deno { * @category I/O */ setRaw(mode: boolean, options?: SetRawOptions): void; + /** + * Checks if `stdin` is a TTY (terminal). + * + * ```ts + * // This example is system and context specific + * Deno.stdin.isTerminal(); // true + * ``` + * + * @category I/O + */ + isTerminal(): boolean; }; /** A reference to `stdout` which can be used to write directly to `stdout`. * It implements the Deno specific {@linkcode Writer}, {@linkcode WriterSync}, @@ -2629,6 +2640,17 @@ declare namespace Deno { readonly rid: number; /** A writable stream interface to `stdout`. */ readonly writable: WritableStream<Uint8Array>; + /** + * Checks if `stdout` is a TTY (terminal). + * + * ```ts + * // This example is system and context specific + * Deno.stdout.isTerminal(); // true + * ``` + * + * @category I/O + */ + isTerminal(): boolean; }; /** A reference to `stderr` which can be used to write directly to `stderr`. * It implements the Deno specific {@linkcode Writer}, {@linkcode WriterSync}, @@ -2646,6 +2668,17 @@ declare namespace Deno { readonly rid: number; /** A writable stream interface to `stderr`. */ readonly writable: WritableStream<Uint8Array>; + /** + * Checks if `stderr` is a TTY (terminal). + * + * ```ts + * // This example is system and context specific + * Deno.stderr.isTerminal(); // true + * ``` + * + * @category I/O + */ + isTerminal(): boolean; }; /** @@ -2728,6 +2761,10 @@ declare namespace Deno { * Deno.close(ttyRid); * ``` * + * @deprecated Use `Deno.stdin.isTerminal()`, `Deno.stdout.isTerminal()` or + * `Deno.stderr.isTerminal()` instead. + * {@linkcode Deno.isatty} will be removed in v2.0.0. + * * @category I/O */ export function isatty(rid: number): boolean; |