diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-10-26 00:23:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-26 00:23:21 +0200 |
commit | ab0c33ebf83f25b526f732e3e07de5e75a6e69bb (patch) | |
tree | b4866d8dd8ae8998429e2fdc5375c0995d92be21 /cli | |
parent | af62e0833dbb23ac0af674b57e5938be97ad57c8 (diff) |
feat: Stabilize Deno.consoleSize() API (#15933)
This commit stabilizes "Deno.consoleSize()" API.
There is one change compared to previous unstable API,
in that the API doesn't accept any arguments. Console size
is established by querying syscalls for stdio streams at fd
0, 1 and 2.
Diffstat (limited to 'cli')
-rw-r--r-- | cli/bench/tty.js | 2 | ||||
-rw-r--r-- | cli/diagnostics.rs | 1 | ||||
-rw-r--r-- | cli/dts/lib.deno.ns.d.ts | 13 | ||||
-rw-r--r-- | cli/dts/lib.deno.unstable.d.ts | 17 | ||||
-rw-r--r-- | cli/tests/unit/tty_test.ts | 22 |
5 files changed, 22 insertions, 33 deletions
diff --git a/cli/bench/tty.js b/cli/bench/tty.js index f86bcfd82..c01af255f 100644 --- a/cli/bench/tty.js +++ b/cli/bench/tty.js @@ -17,5 +17,5 @@ function bench(fun) { } bench(() => { - Deno.consoleSize(0); + Deno.consoleSize(); }); diff --git a/cli/diagnostics.rs b/cli/diagnostics.rs index 0fa35839e..7c27b62e5 100644 --- a/cli/diagnostics.rs +++ b/cli/diagnostics.rs @@ -35,7 +35,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[ "addSignalListener", "bench", "connect", - "consoleSize", "createHttpClient", "kill", "listen", diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts index 0ac06dc62..eea3c7947 100644 --- a/cli/dts/lib.deno.ns.d.ts +++ b/cli/dts/lib.deno.ns.d.ts @@ -1901,6 +1901,19 @@ declare namespace Deno { */ export const File: typeof FsFile; + /** Gets the size of the console as columns/rows. + * + * ```ts + * const { columns, rows } = Deno.consoleSize(); + * ``` + * + * @category I/O + */ + export function consoleSize(): { + columns: number; + rows: number; + }; + /** @category I/O */ export interface SetRawOptions { /** diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index c687848ca..416176564 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -228,23 +228,6 @@ declare namespace Deno { /** **UNSTABLE**: New API, yet to be vetted. * - * Gets the size of the console as columns/rows. - * - * ```ts - * const { columns, rows } = Deno.consoleSize(Deno.stdout.rid); - * ``` - * - * @category I/O - */ - export function consoleSize( - rid: number, - ): { - columns: number; - rows: number; - }; - - /** **UNSTABLE**: New API, yet to be vetted. - * * Returns the release version of the Operating System. * * ```ts diff --git a/cli/tests/unit/tty_test.ts b/cli/tests/unit/tty_test.ts index 8787db3e1..88b25d758 100644 --- a/cli/tests/unit/tty_test.ts +++ b/cli/tests/unit/tty_test.ts @@ -1,21 +1,15 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -import { assert, assertThrows } from "./test_util.ts"; +import { assert } from "./test_util.ts"; // Note tests for Deno.stdin.setRaw is in integration tests. -Deno.test({ permissions: { read: true } }, function consoleSizeFile() { - const file = Deno.openSync("cli/tests/testdata/assets/hello.txt"); - assertThrows(() => { - Deno.consoleSize(file.rid); - }, Error); - file.close(); -}); - -Deno.test(function consoleSizeError() { - assertThrows(() => { - // Absurdly large rid. - Deno.consoleSize(0x7fffffff); - }, Deno.errors.BadResource); +Deno.test(function consoleSize() { + if (!Deno.isatty(Deno.stdout.rid)) { + return; + } + const result = Deno.consoleSize(); + assert(typeof result.columns !== "undefined"); + assert(typeof result.rows !== "undefined"); }); Deno.test({ permissions: { read: true } }, function isatty() { |