use std::fs::File;
use std::os::unix::io::{AsFd, AsRawFd};
#[cfg(unix)]
pub fn configure_raw_mode(file: &File) -> std::io::Result<()> {
use nix::sys::termios::{self, SetArg};
let mut termios = termios::tcgetattr(file.as_fd()).map_err(std::io::Error::other)?;
termios::cfmakeraw(&mut termios);
termios::tcsetattr(file.as_fd(), SetArg::TCSANOW, &termios).map_err(std::io::Error::other)?;
Ok(())
}
#[cfg(not(unix))]
pub fn configure_raw_mode(_file: &File) -> std::io::Result<()> {
Ok(())
}
#[cfg(unix)]
pub fn configure_nonblocking(file: &File) -> std::io::Result<()> {
use nix::fcntl::{self, FcntlArg, OFlag};
let flags = fcntl::fcntl(file.as_raw_fd(), FcntlArg::F_GETFL).map_err(std::io::Error::other)?;
let mut new_flags = OFlag::from_bits_truncate(flags);
new_flags.insert(OFlag::O_NONBLOCK);
fcntl::fcntl(file.as_raw_fd(), FcntlArg::F_SETFL(new_flags)).map_err(std::io::Error::other)?;
Ok(())
}
#[cfg(not(unix))]
pub fn configure_nonblocking(_file: &File) -> std::io::Result<()> {
Ok(())
}