From dc921c14332d4b1df61eb859d6c6d55da6bd0482 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Tue, 20 May 2014 20:04:16 -0700 Subject: [PATCH] Add .isatty() method to StdReader StdWriter has .isatty(). StdReader can trivially vend the same function, and someone asked today on IRC how to call isatty() on stdin. --- src/libstd/io/stdio.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index e6d416164d008..991f3992dd1bd 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -290,6 +290,16 @@ pub struct StdReader { inner: StdSource } +impl StdReader { + /// Returns whether this stream is attached to a TTY instance or not. + pub fn isatty(&self) -> bool { + match self.inner { + TTY(..) => true, + File(..) => false, + } + } +} + impl Reader for StdReader { fn read(&mut self, buf: &mut [u8]) -> IoResult { let ret = match self.inner {