diff --git a/apps/cli/src/bin/unic-echo.rs b/apps/cli/src/bin/unic-echo.rs index d0939b02..c3bda519 100644 --- a/apps/cli/src/bin/unic-echo.rs +++ b/apps/cli/src/bin/unic-echo.rs @@ -14,7 +14,11 @@ extern crate clap; #[macro_use] extern crate unic_cli; -use std::io::{self, Write}; + +use std::time; +use std::thread; +use std::io::{self, Read, Write}; +use std::sync::{Arc, Mutex}; use clap::{Arg, ErrorKind}; @@ -111,6 +115,7 @@ fn run() -> Result<()> { .arg( Arg::with_name("STRINGS") .multiple(true) + .required(false) .help("Input strings (expected valid Unicode)"), ) .arg( @@ -133,12 +138,33 @@ fn run() -> Result<()> { let matches = app.get_matches(); // == Read input == - let input: String = matches + let mut input: String = matches .values_of("STRINGS") .unwrap_or_default() .collect::>() .join(" "); + if input.len() == 0 { + let done = Arc::new(Mutex::new(false)); + let done_clone = done.clone(); + + let handler = thread::spawn(move ||{ + let mut input = String::new(); + let _ = io::stdin().read_to_string(&mut input); + + *done_clone.lock().unwrap() = true; + + input + }); + + thread::sleep(time::Duration::from_millis(300)); + + if *done.lock().unwrap() { + input = handler.join().unwrap(); + } + } + + let input_format = value_t!(matches, "input_format", InputFormat).unwrap_or_else(|err| match err.kind { ErrorKind::ValueValidation => { diff --git a/apps/cli/src/bin/unic-inspector.rs b/apps/cli/src/bin/unic-inspector.rs index c41a80cc..005e7acf 100644 --- a/apps/cli/src/bin/unic-inspector.rs +++ b/apps/cli/src/bin/unic-inspector.rs @@ -21,6 +21,12 @@ use prettytable::Table; use unic::char::property::EnumeratedCharProperty; use unic::ucd::{GeneralCategory, Name}; +use std::time; +use std::thread; +use std::io::{self, Read}; +use std::sync::{Arc, Mutex}; + + fn main() { let app = app_from_crate!() .about(concat!( @@ -31,17 +37,38 @@ fn main() { .arg( Arg::with_name("STRINGS") .help("Input strings (expected valid Unicode)") + .required(false) .multiple(true), ); let matches = app.get_matches(); // == Read input == - let string: String = matches + let mut input: String = matches .values_of("STRINGS") .unwrap_or_default() .collect::>() .join(" "); + if input.len() == 0 { + let done = Arc::new(Mutex::new(false)); + let done_clone = done.clone(); + + let handler = thread::spawn(move ||{ + let mut input = String::new(); + let _ = io::stdin().read_to_string(&mut input); + + *done_clone.lock().unwrap() = true; + + input + }); + + thread::sleep(time::Duration::from_millis(300)); + + if *done.lock().unwrap() { + input = handler.join().unwrap(); + } + } + // == Write output == let mut table = Table::new(); let mut table_format = TableFormat::new(); @@ -58,7 +85,7 @@ fn main() { ]); */ - string.chars().for_each(|chr| { + input.chars().for_each(|chr| { let name = Name::of(chr) .map(|n| n.to_string()) .unwrap_or_else(|| "".to_owned());