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 /src/ops.rs | |
parent | 1d48e025d341c9295f7ee02039eaa6c00a720344 (diff) |
Add isTTY function (#1622)
Diffstat (limited to 'src/ops.rs')
-rw-r--r-- | src/ops.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/ops.rs b/src/ops.rs index b17db87b2..b30473eb6 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -1,4 +1,5 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. + use crate::errors; use crate::errors::{DenoError, DenoResult, ErrorKind}; use crate::fs as deno_fs; @@ -18,6 +19,7 @@ use crate::resources::Resource; use crate::tokio_util; use crate::version; +use atty; use flatbuffers::FlatBufferBuilder; use futures; use futures::Async; @@ -121,6 +123,7 @@ pub fn dispatch( msg::Any::Write => op_write, msg::Any::WriteFile => op_write_file, msg::Any::Now => op_now, + msg::Any::IsTTY => op_is_tty, _ => panic!(format!( "Unhandled message {}", msg::enum_name_any(inner_type) @@ -197,6 +200,31 @@ fn op_now( )) } +fn op_is_tty( + _state: &Arc<IsolateState>, + base: &msg::Base<'_>, + _data: libdeno::deno_buf, +) -> Box<Op> { + let builder = &mut FlatBufferBuilder::new(); + let inner = msg::IsTTYRes::create( + builder, + &msg::IsTTYResArgs { + stdin: atty::is(atty::Stream::Stdin), + stdout: atty::is(atty::Stream::Stdout), + stderr: atty::is(atty::Stream::Stderr), + }, + ); + ok_future(serialize_response( + base.cmd_id(), + builder, + msg::BaseArgs { + inner: Some(inner.as_union_value()), + inner_type: msg::Any::IsTTYRes, + ..Default::default() + }, + )) +} + fn op_exit( _config: &Arc<IsolateState>, base: &msg::Base<'_>, |