summaryrefslogtreecommitdiff
path: root/js/os.ts
diff options
context:
space:
mode:
authorDmitry Sharshakov <sh7dm@outlook.com>2019-02-03 06:05:30 +0300
committerRyan Dahl <ry@tinyclouds.org>2019-02-02 22:05:30 -0500
commit181b03273c4c9282d8176953d68713e37b50294b (patch)
treeabdc1d696c889739b9d3ac254af7fa6f673fcc68 /js/os.ts
parent1d48e025d341c9295f7ee02039eaa6c00a720344 (diff)
Add isTTY function (#1622)
Diffstat (limited to 'js/os.ts')
-rw-r--r--js/os.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/js/os.ts b/js/os.ts
index 61b6ed974..3122830cf 100644
--- a/js/os.ts
+++ b/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();