First hint of raw mode
This commit is contained in:
parent
45fabec0e4
commit
e3e187d442
26
src/main.rs
26
src/main.rs
@ -1,14 +1,30 @@
|
||||
// use nix::sys::termios;
|
||||
use nix::Error as NixError;
|
||||
use nix::sys::termios;
|
||||
use nix::sys::termios::Termios;
|
||||
// use nix::unistd;
|
||||
use std::io;
|
||||
use std::io::{BufReader, Error};
|
||||
use std::io::prelude::*;
|
||||
|
||||
// fn enable_raw_mode() {
|
||||
//
|
||||
// }
|
||||
// For future reference
|
||||
// STDIN_FILENO = 0
|
||||
// STDOUT_FILENO = 1
|
||||
// STDERR_FILENO = 2
|
||||
|
||||
fn enable_raw_mode() -> Result<(), Error> {
|
||||
let raw: Result<Termios, NixError> = termios::tcgetattr(0);
|
||||
let mut raw = raw.unwrap();
|
||||
raw.local_flags.remove(termios::LocalFlags::ECHO);
|
||||
|
||||
match termios::tcsetattr(0, termios::SetArg::TCSAFLUSH, &raw) {
|
||||
Ok(()) => Ok(()),
|
||||
_ => panic!("Failed to set raw mode"),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
enable_raw_mode()?;
|
||||
|
||||
loop {
|
||||
let stdin = io::stdin();
|
||||
let mut in_str = String::new();
|
||||
@ -22,4 +38,6 @@ fn main() -> Result<(), Error> {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user