summaryrefslogtreecommitdiff
path: root/src/cli.rs
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2018-07-05 22:57:52 +0300
committerYuval Adam <_@yuv.al>2018-07-05 22:57:52 +0300
commit518508751bf842f06837a4607fdba5b6493d2476 (patch)
tree1252fcd91bb1d70c0a4955334c520e41f9ef1820 /src/cli.rs
parent5880c9d7d6fb10b9294f7e1b7a30c3ed327e076e (diff)
Restructure and remove colored
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
new file mode 100644
index 0000000..05a88bd
--- /dev/null
+++ b/src/cli.rs
@@ -0,0 +1,21 @@
+extern crate termios;
+
+use std::io;
+use std::io::{Read, Write};
+use self::termios::{Termios, TCSANOW, ECHO, ICANON, tcsetattr};
+
+pub 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
+}