From 431dcdc840a27f7c7418b7dff73a329eada8a407 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Fri, 17 Oct 2014 13:33:08 -0700 Subject: 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. --- src/libstd/io/stdio.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'src/libstd/io') 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), - File(FileDesc), + TTY(tty::TTY), + File(fs::FileDesc), } -fn src(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(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) @@ -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), }) } -- cgit 1.4.1-3-g733a5