diff options
author | Dmitry Sharshakov <sh7dm@outlook.com> | 2019-02-03 06:05:30 +0300 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-02-02 22:05:30 -0500 |
commit | 181b03273c4c9282d8176953d68713e37b50294b (patch) | |
tree | abdc1d696c889739b9d3ac254af7fa6f673fcc68 /js/os.ts | |
parent | 1d48e025d341c9295f7ee02039eaa6c00a720344 (diff) |
Add isTTY function (#1622)
Diffstat (limited to 'js/os.ts')
-rw-r--r-- | js/os.ts | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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(); |