First hint of raw mode

This commit is contained in:
Timothy Warren 2019-08-21 16:46:14 -04:00
parent 45fabec0e4
commit e3e187d442
1 changed files with 22 additions and 4 deletions

View File

@ -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(())
}