mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
Add isTTY function (#1622)
This commit is contained in:
parent
1d48e025d3
commit
181b03273c
8 changed files with 91 additions and 3 deletions
17
js/os.ts
17
js/os.ts
|
@ -21,6 +21,23 @@ interface CodeInfo {
|
|||
sourceCode: string | undefined;
|
||||
}
|
||||
|
||||
/** Check if running in terminal.
|
||||
*
|
||||
* import { isTTY } from "deno";
|
||||
* console.log(isTTY().stdout);
|
||||
*/
|
||||
export function isTTY(): { stdin: boolean; stdout: boolean; stderr: boolean } {
|
||||
const builder = flatbuffers.createBuilder();
|
||||
msg.IsTTY.startIsTTY(builder);
|
||||
const inner = msg.IsTTY.endIsTTY(builder);
|
||||
const baseRes = sendSync(builder, msg.Any.IsTTY, inner)!;
|
||||
assert(msg.Any.IsTTYRes === baseRes.innerType());
|
||||
const res = new msg.IsTTYRes();
|
||||
assert(baseRes.inner(res) != null);
|
||||
|
||||
return { stdin: res.stdin(), stdout: res.stdout(), stderr: res.stderr() };
|
||||
}
|
||||
|
||||
/** Exit the Deno process with optional exit code. */
|
||||
export function exit(exitCode = 0): never {
|
||||
const builder = flatbuffers.createBuilder();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue