diff options
| author | Yuval Adam <_@yuv.al> | 2018-07-08 22:51:21 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2018-07-08 22:51:21 +0300 |
| commit | 0bf59b49f10cff3aff18272d624f678a7369ce35 (patch) | |
| tree | f0c2981903dea3c5e4341d60db4feb1f95f1a618 /src/main.rs | |
| parent | d1e30b39f962fb1e69184dc62ca6595e41695702 (diff) | |
Implemented a properly threaded user input loop
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 972e7b0..86d5b85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,8 @@ use colored::*; use clap::{Arg, App}; use std::path::Path; use std::process; +use std::thread; +use std::sync::mpsc; mod cli; @@ -30,6 +32,26 @@ fn main() { process::exit(1); } - // test a single char read - cli::read_char(); + let (tx, rx) = mpsc::channel(); + + let child = thread::spawn(move || { + let mut controller = cli::Controller::init(); + loop { + let c = controller.read(); + tx.send(c).unwrap(); + if c == 113 { + break; + } + } + controller.destroy(); + }); + + for received in rx { + println!("Got char: {}", received); + } + + println!("Waiting for all thread"); + let _res = child.join(); + println!("Done!"); + } |
