command running, raw mode and history

This commit is contained in:
Raptorox 2025-09-20 18:50:06 +02:00
parent e9d64b38cd
commit ec1a840bb6
No known key found for this signature in database
GPG key ID: 8B3556FC3ED1F6D8
7 changed files with 366 additions and 2 deletions

24
src/raw.rs Normal file
View file

@ -0,0 +1,24 @@
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);
}
}