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::*; // Redefine the posix constants for rust land const STDIN_FILENO: i32 = 0; const STDOUT_FILENO: i32 = 1; const STDERR_FILENO: i32 = 2; fn enable_raw_mode() -> Result<(), Error> { let raw: Result = termios::tcgetattr(STDIN_FILENO); let mut raw = raw.unwrap(); raw.local_flags.remove(termios::LocalFlags::ECHO); match termios::tcsetattr(STDIN_FILENO, 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(); let mut input = BufReader::new(stdin.take(1)); input.read_to_string(&mut in_str)?; let mut chars = in_str.chars(); let char = chars.next().unwrap(); if char == 'q' { return Ok(()); } } Ok(()) }