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/_process/streams.mjs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'ext/node/polyfills/_process/streams.mjs') 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; -- cgit v1.2.3