From 3a4d88475b40a17f2ce17b775a3f07c78be83d79 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 30 May 2019 11:07:58 -0400 Subject: Port code from Cargo and use for progress A lot of its functionality is unused still, but the goal it to slowly migrate logging functionality to it. There is also a useful progress bar which can be ported over later - it depends on this module. https://github.com/rust-lang/cargo/blob/4c1fa54d10f58d69ac9ff55be68e1b1c25ecb816/src/cargo/util/progress.rs --- cli/main.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'cli/main.rs') diff --git a/cli/main.rs b/cli/main.rs index 05748f5ab..8121e5f7c 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -35,6 +35,7 @@ mod progress; mod repl; pub mod resolve_addr; pub mod resources; +mod shell; mod signal; pub mod source_maps; mod startup_data; @@ -158,17 +159,15 @@ fn create_worker_and_state( flags: DenoFlags, argv: Vec, ) -> (Worker, ThreadSafeState) { + use crate::shell::Shell; + use std::sync::Arc; + use std::sync::Mutex; + let shell = Arc::new(Mutex::new(Shell::new())); let progress = Progress::new(); - progress.set_callback(|done, completed, total, msg| { - if !done { - eprint!("\r[{}/{}] {}", completed, total, msg); - eprint!("\x1B[K"); // Clear to end of line. - return; - } - - // print empty line only if progress bar was used - if done && total > 0 { - eprintln!(); + progress.set_callback(move |_done, _completed, _total, status, msg| { + if !status.is_empty() { + let mut s = shell.lock().unwrap(); + s.status(status, msg).expect("shell problem"); } }); let state = ThreadSafeState::new(flags, argv, ops::op_selector_std, progress); -- cgit v1.2.3