termion/sys/unix/tty.rs
1use std::{fs, io};
2use std::os::unix::io::AsRawFd;
3
4use super::libc;
5
6
7/// Is this stream a TTY?
8pub fn is_tty<T: AsRawFd>(stream: &T) -> bool {
9 unsafe { libc::isatty(stream.as_raw_fd()) == 1 }
10}
11
12/// Get the TTY device.
13///
14/// This allows for getting stdio representing _only_ the TTY, and not other streams.
15pub fn get_tty() -> io::Result<fs::File> {
16 fs::OpenOptions::new().read(true).write(true).open("/dev/tty")
17}