command running, raw mode and history
This commit is contained in:
parent
e9d64b38cd
commit
ec1a840bb6
7 changed files with 366 additions and 2 deletions
24
src/raw.rs
Normal file
24
src/raw.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue