2016-07-29 18:49:29 +01:00
|
|
|
use std::{fs, io};
|
2016-07-23 15:40:27 +01:00
|
|
|
use std::os::unix::io::AsRawFd;
|
|
|
|
|
|
|
|
/// Is this stream an TTY?
|
|
|
|
#[cfg(not(target_os = "redox"))]
|
|
|
|
pub fn is_tty<T: AsRawFd>(stream: T) -> bool {
|
|
|
|
use libc;
|
|
|
|
|
|
|
|
unsafe { libc::isatty(stream.as_raw_fd()) == 1}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This will panic.
|
|
|
|
#[cfg(target_os = "redox")]
|
|
|
|
pub fn is_tty<T: AsRawFd>(_stream: T) -> bool {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2016-07-29 18:49:29 +01:00
|
|
|
|
|
|
|
/// Get the TTY device.
|
|
|
|
///
|
|
|
|
/// This allows for getting stdio representing _only_ the TTY, and not other streams.
|
|
|
|
#[cfg(target_os = "redox")]
|
|
|
|
pub fn get_tty() -> io::Result<fs::File> {
|
2016-07-30 10:48:27 +01:00
|
|
|
use std::env;
|
2016-07-29 20:56:33 +01:00
|
|
|
fs::OpenOptions::new().read(true).write(true).open(try!(env::var("TTY")))
|
2016-07-29 18:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the TTY device.
|
|
|
|
///
|
|
|
|
/// This allows for getting stdio representing _only_ the TTY, and not other streams.
|
|
|
|
#[cfg(not(target_os = "redox"))]
|
|
|
|
pub fn get_tty() -> io::Result<fs::File> {
|
|
|
|
fs::OpenOptions::new().read(true).write(true).open("/dev/tty")
|
|
|
|
}
|