summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 8c025af..d3d5f1d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,11 +1,32 @@
extern crate clap;
extern crate colored;
+extern crate termios;
use colored::*;
use clap::{Arg, App};
use std::path::Path;
use std::process;
+use std::io;
+use std::io::{Read, Write};
+use termios::{Termios, TCSANOW, ECHO, ICANON, tcsetattr};
+
+fn read_char() {
+ let stdin = 0;
+ let termios = Termios::from_fd(stdin).unwrap();
+ let mut new_termios = termios.clone(); // make a mutable copy of termios that we will modify
+ new_termios.c_lflag &= !(ICANON | ECHO); // no echo and canonical mode
+ tcsetattr(stdin, TCSANOW, &mut new_termios).unwrap();
+ let stdout = io::stdout();
+ let mut reader = io::stdin();
+ let mut buffer = [0;1]; // read exactly one byte
+ print!("Hit a key! ");
+ stdout.lock().flush().unwrap();
+ reader.read_exact(&mut buffer).unwrap();
+ println!("You have hit: {:?}", buffer);
+ tcsetattr(stdin, TCSANOW, & termios).unwrap(); // reset the stdin to original termios data
+}
+
fn main() {
let app = App::new("Rustcast")
.version("0.1")
@@ -27,4 +48,6 @@ fn main() {
println!("\n{} {}\n", "Input file does not exist:".red(), infile.red());
process::exit(1);
}
+
+ read_char();
}