]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/unix/tty.rs
doc: remove incomplete sentence
[rust.git] / src / libstd / sys / unix / tty.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use prelude::v1::*;
12
13 use sys::fs::FileDesc;
14 use libc::{mod, c_int};
15 use io::{mod, IoResult, IoError};
16 use sys_common;
17
18 pub struct TTY {
19     pub fd: FileDesc,
20 }
21
22 impl TTY {
23     pub fn new(fd: c_int) -> IoResult<TTY> {
24         if unsafe { libc::isatty(fd) } != 0 {
25             Ok(TTY { fd: FileDesc::new(fd, true) })
26         } else {
27             Err(IoError {
28                 kind: io::MismatchedFileTypeForOperation,
29                 desc: "file descriptor is not a TTY",
30                 detail: None,
31             })
32         }
33     }
34
35     pub fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
36         self.fd.read(buf)
37     }
38     pub fn write(&mut self, buf: &[u8]) -> IoResult<()> {
39         self.fd.write(buf)
40     }
41     pub fn set_raw(&mut self, _raw: bool) -> IoResult<()> {
42         Err(sys_common::unimpl())
43     }
44     pub fn get_winsize(&mut self) -> IoResult<(int, int)> {
45         Err(sys_common::unimpl())
46     }
47     pub fn isatty(&self) -> bool { false }
48 }