use std::os::fd::BorrowedFd;
#[cfg(unix)]
use std::os::unix::io::AsRawFd;
#[cfg(unix)]
pub fn configure_raw_mode(fd: BorrowedFd) -> std::io::Result<()> {
use nix::sys::termios::{self, SetArg};
let mut termios = termios::tcgetattr(fd).map_err(std::io::Error::other)?;
termios::cfmakeraw(&mut termios);
termios::tcsetattr(fd, SetArg::TCSANOW, &termios).map_err(std::io::Error::other)?;
Ok(())
}
#[cfg(not(unix))]
pub fn configure_raw_mode(_fd: BorrowedFd) -> std::io::Result<()> {
Ok(())
}
#[cfg(unix)]
pub fn configure_nonblocking(fd: BorrowedFd) -> std::io::Result<()> {
use nix::fcntl::{self, FcntlArg, OFlag};
let flags = fcntl::fcntl(fd.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(fd.as_raw_fd(), FcntlArg::F_SETFL(new_flags)).map_err(std::io::Error::other)?;
Ok(())
}
#[cfg(not(unix))]
pub fn configure_nonblocking(_fd: BorrowedFd) -> std::io::Result<()> {
Ok(())
}