24 lines
No EOL
748 B
Rust
24 lines
No EOL
748 B
Rust
pub fn enable_raw_mode() -> libc::termios {
|
|
unsafe {
|
|
let fd = libc::STDIN_FILENO;
|
|
let mut termios = std::mem::zeroed();
|
|
libc::tcgetattr(fd, &mut termios);
|
|
|
|
let mut raw = termios;
|
|
raw.c_iflag &= !(libc::BRKINT | libc::ICRNL | libc::INPCK | libc::ISTRIP | libc::IXON);
|
|
raw.c_oflag &= !(libc::OPOST);
|
|
raw.c_cflag |= libc::CS8;
|
|
raw.c_lflag &= !(libc::ECHO | libc::ICANON | libc::IEXTEN | libc::ISIG);
|
|
raw.c_cc[libc::VMIN] = 1;
|
|
raw.c_cc[libc::VTIME] = 0;
|
|
libc::tcsetattr(fd, libc::TCSAFLUSH, &raw);
|
|
|
|
termios
|
|
}
|
|
}
|
|
|
|
pub fn disable_raw_mode(orig: &libc::termios) {
|
|
unsafe {
|
|
libc::tcsetattr(libc::STDIN_FILENO, libc::TCSAFLUSH, orig);
|
|
}
|
|
} |