Allow piped stdout/stderr use uv_tty_t

There are issues with reading stdin when it is actually attached to a pipe, but
I have run into no problems in writing to stdout/stderr when they are attached
to pipes.
This commit is contained in:
Alex Crichton 2013-11-18 16:26:03 -08:00
parent 3d569df41d
commit 10b956a012
3 changed files with 8 additions and 1 deletions

View File

@ -39,7 +39,8 @@ impl TtyWatcher {
// Related:
// - https://github.com/joyent/libuv/issues/982
// - https://github.com/joyent/libuv/issues/988
if unsafe { uvll::guess_handle(fd) != uvll::UV_TTY as libc::c_int } {
let guess = unsafe { uvll::guess_handle(fd) };
if readable && guess != uvll::UV_TTY as libc::c_int {
return Err(UvError(uvll::EBADF));
}
@ -100,6 +101,10 @@ impl RtioTTY for TtyWatcher {
n => Err(uv_error_to_io_error(UvError(n)))
}
}
fn isatty(&self) -> bool {
unsafe { uvll::guess_handle(self.fd) == uvll::UV_TTY as libc::c_int }
}
}
impl UvHandle<uvll::uv_tty_t> for TtyWatcher {

View File

@ -167,6 +167,7 @@ impl rtio::RtioTTY for FileDesc {
fn get_winsize(&mut self) -> Result<(int, int), IoError> {
Err(super::unimpl())
}
fn isatty(&self) -> bool { false }
}
impl Drop for FileDesc {

View File

@ -230,6 +230,7 @@ pub trait RtioTTY {
fn write(&mut self, buf: &[u8]) -> Result<(), IoError>;
fn set_raw(&mut self, raw: bool) -> Result<(), IoError>;
fn get_winsize(&mut self) -> Result<(int, int), IoError>;
fn isatty(&self) -> bool;
}
pub trait PausibleIdleCallback {