about summary refs log tree commit diff
path: root/src/libstd/io
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2014-05-20 20:04:16 -0700
committerKevin Ballard <kevin@sb.org>2014-05-20 20:05:05 -0700
commitdc921c14332d4b1df61eb859d6c6d55da6bd0482 (patch)
treed3dacfe1c79a4c8f2d0068bd13b693833ce845b9 /src/libstd/io
parente546452727379f701f2104eb826141a29d4b39fd (diff)
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.
Diffstat (limited to 'src/libstd/io')
-rw-r--r--src/libstd/io/stdio.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs
index e6d416164d0..991f3992dd1 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<uint> {
         let ret = match self.inner {