diff options
| author | Aaron Turon <aturon@mozilla.com> | 2014-10-17 13:33:08 -0700 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2014-11-08 20:40:39 -0800 |
| commit | 431dcdc840a27f7c7418b7dff73a329eada8a407 (patch) | |
| tree | 4e77fc459607350626e306d4400faf827a9c9092 /src/libstd/sys/unix | |
| parent | b8f1193bb1bb66610f479cd78e3dc5526e93058d (diff) | |
| download | rust-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/sys/unix')
| -rw-r--r-- | src/libstd/sys/unix/fs.rs | 19 | ||||
| -rw-r--r-- | src/libstd/sys/unix/mod.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/tty.rs | 47 |
3 files changed, 48 insertions, 19 deletions
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 3dcd99859e8..2d02c34e958 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -137,25 +137,6 @@ impl FileDesc { } } -/* - -impl RtioTTY for FileDesc { - fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { - self.inner_read(buf) - } - fn write(&mut self, buf: &[u8]) -> IoResult<()> { - self.inner_write(buf) - } - fn set_raw(&mut self, _raw: bool) -> IoResult<()> { - Err(super::unimpl()) - } - fn get_winsize(&mut self) -> IoResult<(int, int)> { - Err(super::unimpl()) - } - fn isatty(&self) -> bool { false } -} -*/ - impl Drop for FileDesc { fn drop(&mut self) { // closing stdio file handles makes no sense, so never do it. Also, note diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 03a4e56f00d..4bd1dd20163 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -35,6 +35,7 @@ pub mod pipe; pub mod helper_signal; pub mod process; pub mod timer; +pub mod tty; pub mod addrinfo { pub use sys_common::net::get_host_addresses; diff --git a/src/libstd/sys/unix/tty.rs b/src/libstd/sys/unix/tty.rs new file mode 100644 index 00000000000..28c17fd4966 --- /dev/null +++ b/src/libstd/sys/unix/tty.rs @@ -0,0 +1,47 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use sys::fs::FileDesc; +use prelude::*; +use libc::{mod, c_int}; +use io::{mod, IoResult, IoError}; +use sys_common; + +pub struct TTY { + pub fd: FileDesc, +} + +impl TTY { + pub fn new(fd: c_int) -> IoResult<TTY> { + if unsafe { libc::isatty(fd) } != 0 { + Ok(TTY { fd: FileDesc::new(fd, true) }) + } else { + Err(IoError { + kind: io::MismatchedFileTypeForOperation, + desc: "file descriptor is not a TTY", + detail: None, + }) + } + } + + pub fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { + self.fd.read(buf) + } + pub fn write(&mut self, buf: &[u8]) -> IoResult<()> { + self.fd.write(buf) + } + pub fn set_raw(&mut self, _raw: bool) -> IoResult<()> { + Err(sys_common::unimpl()) + } + pub fn get_winsize(&mut self) -> IoResult<(int, int)> { + Err(sys_common::unimpl()) + } + pub fn isatty(&self) -> bool { false } +} |
