mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
4eedac3604
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>
32 lines
871 B
TypeScript
32 lines
871 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
import { assert } from "./test_util.ts";
|
|
|
|
// Note tests for Deno.stdin.setRaw is in integration tests.
|
|
|
|
Deno.test(function consoleSize() {
|
|
if (!Deno.stdout.isTerminal()) {
|
|
return;
|
|
}
|
|
const result = Deno.consoleSize();
|
|
assert(typeof result.columns !== "undefined");
|
|
assert(typeof result.rows !== "undefined");
|
|
});
|
|
|
|
Deno.test({ permissions: { read: true } }, function isatty() {
|
|
// CI not under TTY, so cannot test stdin/stdout/stderr.
|
|
const f = Deno.openSync("cli/tests/testdata/assets/hello.txt");
|
|
assert(!Deno.isatty(f.rid));
|
|
f.close();
|
|
});
|
|
|
|
Deno.test(function isattyError() {
|
|
let caught = false;
|
|
try {
|
|
// Absurdly large rid.
|
|
Deno.isatty(0x7fffffff);
|
|
} catch (e) {
|
|
caught = true;
|
|
assert(e instanceof Deno.errors.BadResource);
|
|
}
|
|
assert(caught);
|
|
});
|