Skip to main content

termion/sys/unix/
tty.rs

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