about summary refs log tree commit diff
path: root/src/libstd/io
diff options
context:
space:
mode:
authorAaron Turon <aturon@mozilla.com>2014-10-17 13:33:08 -0700
committerAaron Turon <aturon@mozilla.com>2014-11-08 20:40:39 -0800
commit431dcdc840a27f7c7418b7dff73a329eada8a407 (patch)
tree4e77fc459607350626e306d4400faf827a9c9092 /src/libstd/io
parentb8f1193bb1bb66610f479cd78e3dc5526e93058d (diff)
downloadrust-431dcdc840a27f7c7418b7dff73a329eada8a407.tar.gz
rust-431dcdc840a27f7c7418b7dff73a329eada8a407.zip
Runtime removal: refactor tty
This patch continues runtime removal by moving the tty implementations
into `sys`.

Because this eliminates APIs in `libnative` and `librustrt`, it is a:

[breaking-change]

This functionality is likely to be available publicly, in some form,
from `std` in the future.
Diffstat (limited to 'src/libstd/io')
-rw-r--r--src/libstd/io/stdio.rs26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs
index 98644cfc7e9..158d596ea13 100644
--- a/src/libstd/io/stdio.rs
+++ b/src/libstd/io/stdio.rs
@@ -36,7 +36,7 @@ use kinds::Send;
 use libc;
 use option::{Option, Some, None};
 use boxed::Box;
-use sys::fs::FileDesc;
+use sys::{fs, tty};
 use result::{Ok, Err};
 use rt;
 use rt::local::Local;
@@ -74,17 +74,15 @@ use uint;
 // tl;dr; TTY works on everything but when windows stdout is redirected, in that
 //        case pipe also doesn't work, but magically file does!
 enum StdSource {
-    TTY(Box<RtioTTY + Send>),
-    File(FileDesc),
+    TTY(tty::TTY),
+    File(fs::FileDesc),
 }
 
-fn src<T>(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T {
-    LocalIo::maybe_raise(|io| {
-        Ok(match io.tty_open(fd, readable) {
-            Ok(tty) => f(TTY(tty)),
-            Err(_) => f(File(FileDesc::new(fd, false))),
-        })
-    }).map_err(IoError::from_rtio_error).unwrap()
+fn src<T>(fd: libc::c_int, _readable: bool, f: |StdSource| -> T) -> T {
+    match tty::TTY::new(fd) {
+        Ok(tty) => f(TTY(tty)),
+        Err(_) => f(File(fs::FileDesc::new(fd, false))),
+    }
 }
 
 local_data_key!(local_stdout: Box<Writer + Send>)
@@ -278,7 +276,7 @@ impl Reader for StdReader {
                 // print!'d prompt not being shown until after the user hits
                 // enter.
                 flush();
-                tty.read(buf).map_err(IoError::from_rtio_error)
+                tty.read(buf).map(|i| i as uint)
             },
             File(ref mut file) => file.read(buf).map(|i| i as uint),
         };
@@ -313,7 +311,7 @@ impl StdWriter {
     pub fn winsize(&mut self) -> IoResult<(int, int)> {
         match self.inner {
             TTY(ref mut tty) => {
-                tty.get_winsize().map_err(IoError::from_rtio_error)
+                tty.get_winsize()
             }
             File(..) => {
                 Err(IoError {
@@ -335,7 +333,7 @@ impl StdWriter {
     pub fn set_raw(&mut self, raw: bool) -> IoResult<()> {
         match self.inner {
             TTY(ref mut tty) => {
-                tty.set_raw(raw).map_err(IoError::from_rtio_error)
+                tty.set_raw(raw)
             }
             File(..) => {
                 Err(IoError {
@@ -372,7 +370,7 @@ impl Writer for StdWriter {
         let max_size = if cfg!(windows) {8192} else {uint::MAX};
         for chunk in buf.chunks(max_size) {
             try!(match self.inner {
-                TTY(ref mut tty) => tty.write(chunk).map_err(IoError::from_rtio_error),
+                TTY(ref mut tty) => tty.write(chunk),
                 File(ref mut file) => file.write(chunk),
             })
         }