From d03ac1d59acb8096b12f46dfb5a397bcc4d28ce9 Mon Sep 17 00:00:00 2001 From: mgiagante <251503-mgiagante@users.noreply.gitlab.com> Date: Thu, 14 Nov 2024 22:25:26 +0000 Subject: [PATCH 1/9] If verbosity level is 1 or higher, it shows dirty files. --- crates/common/src/term.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/common/src/term.rs b/crates/common/src/term.rs index ead39b5face3..fbbc7eec0432 100644 --- a/crates/common/src/term.rs +++ b/crates/common/src/term.rs @@ -67,7 +67,7 @@ impl Spinner { pub fn tick(&mut self) { if self.no_progress { - return + return; } let indicator = self.indicator[self.idx % self.indicator.len()].green(); @@ -118,7 +118,7 @@ impl SpinnerReporter { // end with a newline let _ = sh_println!(); let _ = ack.send(()); - break + break; } Err(TryRecvError::Disconnected) => break, Err(TryRecvError::Empty) => thread::sleep(Duration::from_millis(100)), @@ -159,6 +159,16 @@ impl Reporter for SpinnerReporter { version.minor, version.patch )); + + if foundry_common::shell::verbosity() > 0 { + self.send_msg( + dirty_files + .iter() + .map(|path| path.display().to_string()) + .collect::>() + .join("\n"), + ); + } } fn on_compiler_success(&self, compiler_name: &str, version: &Version, duration: &Duration) { From c8a3362169891c575a674ff31b43e909b9e17b72 Mon Sep 17 00:00:00 2001 From: mgiagante <251503-mgiagante@users.noreply.gitlab.com> Date: Fri, 15 Nov 2024 18:04:54 +0000 Subject: [PATCH 2/9] Adds verbose message variant for compilation. --- crates/common/src/term.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/crates/common/src/term.rs b/crates/common/src/term.rs index fbbc7eec0432..3e8f7029b7b1 100644 --- a/crates/common/src/term.rs +++ b/crates/common/src/term.rs @@ -109,7 +109,7 @@ impl SpinnerReporter { loop { spinner.tick(); match rx.try_recv() { - Ok(SpinnerMsg::Msg(msg)) => { + Ok(SpinnerMsg::Msg(msg) | SpinnerMsg::VerboseMsg(msg)) => { spinner.message(msg); // new line so past messages are not overwritten let _ = sh_println!(); @@ -133,10 +133,15 @@ impl SpinnerReporter { fn send_msg(&self, msg: impl Into) { let _ = self.sender.send(SpinnerMsg::Msg(msg.into())); } + + fn send_verbose_msg(&self, msg: impl Into) { + let _ = self.sender.send(SpinnerMsg::VerboseMsg(msg.into())); + } } enum SpinnerMsg { Msg(String), + VerboseMsg(String), Shutdown(mpsc::Sender<()>), } @@ -151,23 +156,24 @@ impl Drop for SpinnerReporter { impl Reporter for SpinnerReporter { fn on_compiler_spawn(&self, compiler_name: &str, version: &Version, dirty_files: &[PathBuf]) { - self.send_msg(format!( - "Compiling {} files with {} {}.{}.{}", - dirty_files.len(), - compiler_name, - version.major, - version.minor, - version.patch - )); - if foundry_common::shell::verbosity() > 0 { - self.send_msg( + self.send_verbose_msg(format!( + "Compiling files\n{}", dirty_files .iter() .map(|path| path.display().to_string()) .collect::>() - .join("\n"), - ); + .join("\n") + )); + } else { + self.send_msg(format!( + "Compiling {} files with {} {}.{}.{}", + dirty_files.len(), + compiler_name, + version.major, + version.minor, + version.patch + )); } } From 6b64f2b3864d6e7addbb566a4b7df88085823ca6 Mon Sep 17 00:00:00 2001 From: mgiagante <251503-mgiagante@users.noreply.gitlab.com> Date: Fri, 15 Nov 2024 18:42:49 +0000 Subject: [PATCH 3/9] Removing `if..else` statement to always display `self.send_msg`. --- crates/common/src/term.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/common/src/term.rs b/crates/common/src/term.rs index 3e8f7029b7b1..3fb89a5f26c2 100644 --- a/crates/common/src/term.rs +++ b/crates/common/src/term.rs @@ -156,6 +156,15 @@ impl Drop for SpinnerReporter { impl Reporter for SpinnerReporter { fn on_compiler_spawn(&self, compiler_name: &str, version: &Version, dirty_files: &[PathBuf]) { + self.send_msg(format!( + "Compiling {} files with {} {}.{}.{}", + dirty_files.len(), + compiler_name, + version.major, + version.minor, + version.patch + )); + if foundry_common::shell::verbosity() > 0 { self.send_verbose_msg(format!( "Compiling files\n{}", @@ -165,15 +174,6 @@ impl Reporter for SpinnerReporter { .collect::>() .join("\n") )); - } else { - self.send_msg(format!( - "Compiling {} files with {} {}.{}.{}", - dirty_files.len(), - compiler_name, - version.major, - version.minor, - version.patch - )); } } From 593b75d3583a109c5c975e643abe887dd82da07e Mon Sep 17 00:00:00 2001 From: mgiagante <251503-mgiagante@users.noreply.gitlab.com> Date: Fri, 15 Nov 2024 19:23:07 +0000 Subject: [PATCH 4/9] Changes order of messages. --- crates/common/src/term.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/common/src/term.rs b/crates/common/src/term.rs index 3fb89a5f26c2..d239e49dc61b 100644 --- a/crates/common/src/term.rs +++ b/crates/common/src/term.rs @@ -156,15 +156,6 @@ impl Drop for SpinnerReporter { impl Reporter for SpinnerReporter { fn on_compiler_spawn(&self, compiler_name: &str, version: &Version, dirty_files: &[PathBuf]) { - self.send_msg(format!( - "Compiling {} files with {} {}.{}.{}", - dirty_files.len(), - compiler_name, - version.major, - version.minor, - version.patch - )); - if foundry_common::shell::verbosity() > 0 { self.send_verbose_msg(format!( "Compiling files\n{}", @@ -175,6 +166,15 @@ impl Reporter for SpinnerReporter { .join("\n") )); } + + self.send_msg(format!( + "Compiling {} files with {} {}.{}.{}", + dirty_files.len(), + compiler_name, + version.major, + version.minor, + version.patch + )); } fn on_compiler_success(&self, compiler_name: &str, version: &Version, duration: &Duration) { From f7671673ccbb0c51aaae1a047f13257dde2f08e3 Mon Sep 17 00:00:00 2001 From: mgiagante <251503-mgiagante@users.noreply.gitlab.com> Date: Sat, 16 Nov 2024 00:09:30 +0000 Subject: [PATCH 5/9] Removes semicolons and adds comment on message order. --- crates/common/src/term.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/common/src/term.rs b/crates/common/src/term.rs index d239e49dc61b..c5e640f53206 100644 --- a/crates/common/src/term.rs +++ b/crates/common/src/term.rs @@ -67,7 +67,7 @@ impl Spinner { pub fn tick(&mut self) { if self.no_progress { - return; + return } let indicator = self.indicator[self.idx % self.indicator.len()].green(); @@ -118,7 +118,7 @@ impl SpinnerReporter { // end with a newline let _ = sh_println!(); let _ = ack.send(()); - break; + break } Err(TryRecvError::Disconnected) => break, Err(TryRecvError::Empty) => thread::sleep(Duration::from_millis(100)), @@ -156,6 +156,8 @@ impl Drop for SpinnerReporter { impl Reporter for SpinnerReporter { fn on_compiler_spawn(&self, compiler_name: &str, version: &Version, dirty_files: &[PathBuf]) { + // Verbose message with dirty files displays first to avoid being overlapped + // by the spinner in .tick() which prints repeatedly over the same line. if foundry_common::shell::verbosity() > 0 { self.send_verbose_msg(format!( "Compiling files\n{}", From 0e0229af802ac5fef4bdba8f1cae408243dadbc4 Mon Sep 17 00:00:00 2001 From: mgiagante <251503-mgiagante@users.noreply.gitlab.com> Date: Mon, 18 Nov 2024 08:47:34 +0000 Subject: [PATCH 6/9] Removes verbose variant in favor of the already existing variant. --- crates/common/src/term.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/crates/common/src/term.rs b/crates/common/src/term.rs index c5e640f53206..ab7223a8484a 100644 --- a/crates/common/src/term.rs +++ b/crates/common/src/term.rs @@ -109,7 +109,7 @@ impl SpinnerReporter { loop { spinner.tick(); match rx.try_recv() { - Ok(SpinnerMsg::Msg(msg) | SpinnerMsg::VerboseMsg(msg)) => { + Ok(SpinnerMsg::Msg(msg)) => { spinner.message(msg); // new line so past messages are not overwritten let _ = sh_println!(); @@ -133,15 +133,10 @@ impl SpinnerReporter { fn send_msg(&self, msg: impl Into) { let _ = self.sender.send(SpinnerMsg::Msg(msg.into())); } - - fn send_verbose_msg(&self, msg: impl Into) { - let _ = self.sender.send(SpinnerMsg::VerboseMsg(msg.into())); - } } enum SpinnerMsg { Msg(String), - VerboseMsg(String), Shutdown(mpsc::Sender<()>), } @@ -159,7 +154,7 @@ impl Reporter for SpinnerReporter { // Verbose message with dirty files displays first to avoid being overlapped // by the spinner in .tick() which prints repeatedly over the same line. if foundry_common::shell::verbosity() > 0 { - self.send_verbose_msg(format!( + self.send_msg(format!( "Compiling files\n{}", dirty_files .iter() From 0c99ff67a388b955f3fc9854e2eddf6d99979eb3 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 18 Nov 2024 10:39:57 +0100 Subject: [PATCH 7/9] nits, sort the dirty files list and prefix with - --- Cargo.lock | 1 + crates/common/Cargo.toml | 1 + crates/common/src/term.rs | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af730814c936..bdc95b33b96d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3723,6 +3723,7 @@ dependencies = [ "foundry-compilers", "foundry-config", "foundry-macros", + "itertools 0.13.0", "num-format", "reqwest", "semver 1.0.23", diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 8fa745a13982..033c53e49dba 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -50,6 +50,7 @@ clap = { version = "4", features = ["derive", "env", "unicode", "wrap_help"] } comfy-table.workspace = true dunce.workspace = true eyre.workspace = true +itertools.workspace = true num-format.workspace = true reqwest.workspace = true semver.workspace = true diff --git a/crates/common/src/term.rs b/crates/common/src/term.rs index ab7223a8484a..70291a17769f 100644 --- a/crates/common/src/term.rs +++ b/crates/common/src/term.rs @@ -3,6 +3,8 @@ use foundry_compilers::{ artifacts::remappings::Remapping, report::{self, BasicStdoutReporter, Reporter}, }; +use foundry_config::find_project_root; +use itertools::Itertools; use semver::Version; use std::{ io, @@ -17,6 +19,8 @@ use std::{ }; use yansi::Paint; +use crate::shell; + /// Some spinners // https://github.com/gernest/wow/blob/master/spin/spinners.go pub static SPINNERS: &[&[&str]] = &[ @@ -153,12 +157,18 @@ impl Reporter for SpinnerReporter { fn on_compiler_spawn(&self, compiler_name: &str, version: &Version, dirty_files: &[PathBuf]) { // Verbose message with dirty files displays first to avoid being overlapped // by the spinner in .tick() which prints repeatedly over the same line. - if foundry_common::shell::verbosity() > 0 { + if shell::verbosity() > 0 { + let project_root = find_project_root(None); + self.send_msg(format!( - "Compiling files\n{}", + "Files to compile:\n{}", dirty_files .iter() - .map(|path| path.display().to_string()) + .map(|path| { + let trimmed_path = path.strip_prefix(&project_root).unwrap_or(path); + format!("- {}", trimmed_path.display()) + }) + .sorted() .collect::>() .join("\n") )); From 3e206b59d3a037c64e11bb7aeb246f607a07c811 Mon Sep 17 00:00:00 2001 From: mgiagante <251503-mgiagante@users.noreply.gitlab.com> Date: Mon, 18 Nov 2024 10:19:35 +0000 Subject: [PATCH 8/9] Raises verbosity level to 5+ --- crates/common/src/term.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/common/src/term.rs b/crates/common/src/term.rs index 70291a17769f..df6d3ef1a707 100644 --- a/crates/common/src/term.rs +++ b/crates/common/src/term.rs @@ -157,7 +157,7 @@ impl Reporter for SpinnerReporter { fn on_compiler_spawn(&self, compiler_name: &str, version: &Version, dirty_files: &[PathBuf]) { // Verbose message with dirty files displays first to avoid being overlapped // by the spinner in .tick() which prints repeatedly over the same line. - if shell::verbosity() > 0 { + if shell::verbosity() >= 5 { let project_root = find_project_root(None); self.send_msg(format!( From 3c95d97f7632caa9556e507a2059d933738aee11 Mon Sep 17 00:00:00 2001 From: mgiagante <5287175+mgiagante@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:20:09 +0000 Subject: [PATCH 9/9] Update crates/common/src/term.rs Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> --- crates/common/src/term.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/common/src/term.rs b/crates/common/src/term.rs index df6d3ef1a707..e673987454cb 100644 --- a/crates/common/src/term.rs +++ b/crates/common/src/term.rs @@ -169,8 +169,7 @@ impl Reporter for SpinnerReporter { format!("- {}", trimmed_path.display()) }) .sorted() - .collect::>() - .join("\n") + .format("\n") )); }