2017-08-01 04:17:47 +01:00
|
|
|
use std::{io, mem};
|
|
|
|
|
|
|
|
use super::{cvt, Termios};
|
|
|
|
use super::libc::c_int;
|
|
|
|
|
|
|
|
pub fn get_terminal_attr() -> io::Result<Termios> {
|
|
|
|
extern "C" {
|
|
|
|
pub fn tcgetattr(fd: c_int, termptr: *mut Termios) -> c_int;
|
|
|
|
}
|
|
|
|
unsafe {
|
|
|
|
let mut termios = mem::zeroed();
|
2019-06-12 23:59:41 +01:00
|
|
|
cvt(tcgetattr(1, &mut termios))?;
|
2017-08-01 04:17:47 +01:00
|
|
|
Ok(termios)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_terminal_attr(termios: &Termios) -> io::Result<()> {
|
|
|
|
extern "C" {
|
|
|
|
pub fn tcsetattr(fd: c_int, opt: c_int, termptr: *const Termios) -> c_int;
|
|
|
|
}
|
2019-06-12 23:59:41 +01:00
|
|
|
cvt(unsafe { tcsetattr(1, 0, termios) }).and(Ok(()))
|
2017-08-01 04:17:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn raw_terminal_attr(termios: &mut Termios) {
|
|
|
|
extern "C" {
|
|
|
|
pub fn cfmakeraw(termptr: *mut Termios);
|
|
|
|
}
|
|
|
|
unsafe { cfmakeraw(termios) }
|
|
|
|
}
|