Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tty): soft-remove Deno.isatty() #25410

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2875,25 +2875,6 @@ declare namespace Deno {
signal?: AbortSignal;
}

/**
* Check if a given resource id (`rid`) is a TTY (a terminal).
*
* ```ts
* // This example is system and context specific
* const nonTTYRid = Deno.openSync("my_file.txt").rid;
* const ttyRid = Deno.openSync("/dev/tty6").rid;
* console.log(Deno.isatty(nonTTYRid)); // false
* console.log(Deno.isatty(ttyRid)); // true
* ```
*
* @deprecated This will be soft-removed in Deno 2.0. See the
* {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide}
* for migration instructions.
*
* @category I/O
*/
export function isatty(rid: number): boolean;

/**
* A variable-sized buffer of bytes with `read()` and `write()` methods.
*
Expand Down
9 changes: 3 additions & 6 deletions runtime/js/40_tty.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, internals, primordials } from "ext:core/mod.js";
import { core, primordials } from "ext:core/mod.js";
import { op_console_size } from "ext:core/ops";
const {
Uint32Array,
Expand All @@ -15,12 +15,9 @@ function consoleSize() {
return { columns: size[0], rows: size[1] };
}

// Note: This function was soft-removed in Deno 2. Its types have been removed,
// but its implementation has been kept to avoid breaking changes.
function isatty(rid) {
internals.warnOnDeprecatedApi(
"Deno.isatty()",
new Error().stack,
"Use `Deno.stdin.isTerminal()`, `Deno.stdout.isTerminal()`, `Deno.stderr.isTerminal()` or `Deno.FsFile.isTerminal()` instead.",
);
return isTerminal(rid);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/tty_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Deno.test(
function isatty() {
// CI not under TTY, so cannot test stdin/stdout/stderr.
const f = Deno.openSync("tests/testdata/assets/hello.txt");
// @ts-ignore `Deno.isatty()` was soft-removed in Deno 2.
assert(!Deno.isatty(f.rid));
f.close();
},
Expand All @@ -29,6 +30,7 @@ Deno.test(function isattyError() {
let caught = false;
try {
// Absurdly large rid.
// @ts-ignore `Deno.isatty()` was soft-removed in Deno 2.
Deno.isatty(0x7fffffff);
} catch (e) {
caught = true;
Expand Down