Tweak cancellation logic for CLI commands
In 'parse' and 'highlight' cancel on stdin if stdin is a tty.
This commit is contained in:
parent
5caa83e020
commit
b972a7158d
6 changed files with 358 additions and 343 deletions
|
|
@ -15,14 +15,16 @@ const HTML_HEADER: &[u8] = b"<!DOCTYPE html>\n<style>svg { width: 100%; }</style
|
|||
|
||||
pub fn cancel_on_stdin() -> Arc<AtomicUsize> {
|
||||
let result = Arc::new(AtomicUsize::new(0));
|
||||
thread::spawn({
|
||||
let flag = result.clone();
|
||||
move || {
|
||||
let mut line = String::new();
|
||||
io::stdin().read_line(&mut line).unwrap();
|
||||
flag.store(1, Ordering::Relaxed);
|
||||
}
|
||||
});
|
||||
if atty::is(atty::Stream::Stdin) {
|
||||
thread::spawn({
|
||||
let flag = result.clone();
|
||||
move || {
|
||||
let mut line = String::new();
|
||||
io::stdin().read_line(&mut line).unwrap();
|
||||
flag.store(1, Ordering::Relaxed);
|
||||
}
|
||||
});
|
||||
}
|
||||
result
|
||||
}
|
||||
#[cfg(windows)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue