Skip to content

Commit

Permalink
refactor: remove quiet
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash committed Jul 2, 2024
1 parent e1b0e92 commit fe66f5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 51 deletions.
58 changes: 9 additions & 49 deletions src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub trait Progress {
/// used when a task fails; we want the final output to show that failed
/// task's output even if we do more work after it fails.
fn log(&mut self, msg: &str);
fn log_ignore_quiet(&mut self, msg: &str);
}

/// Currently running build task, as tracked for progress updates.
Expand All @@ -65,16 +64,14 @@ pub struct DumbConsoleProgress {
/// The id of the last command printed, used to avoid printing it twice
/// when we have two updates from the same command in a row.
last_started: Option<BuildId>,
quiet: bool,
callback: Option<Box<dyn Fn(&str) + Send>>,
}

impl DumbConsoleProgress {
pub fn new(verbose: bool, quiet: bool, callback: Option<Box<dyn Fn(&str) + Send>>) -> Self {
pub fn new(verbose: bool, callback: Option<Box<dyn Fn(&str) + Send>>) -> Self {
Self {
verbose,
last_started: None,
quiet,
callback,
}
}
Expand Down Expand Up @@ -108,9 +105,9 @@ impl Progress for DumbConsoleProgress {
}
}
Termination::Interrupted => {
self.log_ignore_quiet(&format!("interrupted: {}", build_message(build)))
self.log(&format!("interrupted: {}", build_message(build)))
}
Termination::Failure => self.log_ignore_quiet(&format!(
Termination::Failure => self.log(&format!(
"{} {}",
"failed:".red().bold(),
build_message(build)
Expand All @@ -127,22 +124,11 @@ impl Progress for DumbConsoleProgress {
}

fn log(&mut self, msg: &str) {
if !self.quiet {
if let Some(ref callback) = self.callback {
callback(msg);
} else {
println!("{}", msg);
}
}
}

fn log_ignore_quiet(&mut self, msg: &str) {
if let Some(ref callback) = self.callback {
callback(msg);
} else {
if self.callback.is_none() {
println!("{}", msg);
}
}

}

/// Progress implementation for "fancy" console, with progress bar etc.
Expand All @@ -159,7 +145,7 @@ pub struct FancyConsoleProgress {
const UPDATE_DELAY: Duration = std::time::Duration::from_millis(50);

impl FancyConsoleProgress {
pub fn new(verbose: bool, quiet: bool, callback: Option<Box<dyn Fn(&str) + Send>>) -> Self {
pub fn new(verbose: bool, callback: Option<Box<dyn Fn(&str) + Send>>) -> Self {
let dirty_cond = Arc::new(Condvar::new());
let state = Arc::new(Mutex::new(FancyState {
done: false,
Expand All @@ -168,7 +154,6 @@ impl FancyConsoleProgress {
counts: StateCounts::default(),
tasks: VecDeque::new(),
verbose,
quiet,
callback,
}));

Expand Down Expand Up @@ -224,15 +209,9 @@ impl Progress for FancyConsoleProgress {
}

fn log(&mut self, msg: &str) {
if self.state.lock().unwrap().quiet {
return;
}
self.state.lock().unwrap().log(msg);
}

fn log_ignore_quiet(&mut self, msg: &str) {
self.state.lock().unwrap().log(msg);
}
}

impl Drop for FancyConsoleProgress {
Expand All @@ -253,7 +232,6 @@ struct FancyState {
tasks: VecDeque<Task>,
/// Whether to print command lines of started programs.
verbose: bool,
quiet: bool,
callback: Option<Box<dyn Fn(&str) + Send>>,
}

Expand Down Expand Up @@ -300,9 +278,9 @@ impl FancyState {
}
}
Termination::Interrupted => {
self.log_ignore_quiet(&format!("interrupted: {}", build_message(build)))
self.log(&format!("interrupted: {}", build_message(build)))
}
Termination::Failure => self.log_ignore_quiet(&format!(
Termination::Failure => self.log(&format!(
"{} {}",
"failed:".red().bold(),
build_message(build)
Expand All @@ -320,23 +298,8 @@ impl FancyState {
}

fn log(&mut self, msg: &str) {
if self.quiet {
return;
}
self.clear_progress();
if let Some(ref callback) = self.callback {
callback(msg);
} else {
println!("{}", msg);
}
self.dirty();
}

fn log_ignore_quiet(&mut self, msg: &str) {
self.clear_progress();
if let Some(ref c) = self.callback {
c(msg);
} else {
if self.callback.is_none() {
println!("{}", msg);
}
self.dirty();
Expand All @@ -355,9 +318,6 @@ impl FancyState {
}

fn print_progress(&mut self) {
if self.quiet {
return;
}
self.clear_progress();
let failed = self.counts.get(BuildState::Failed);
let mut progress_line = format!(
Expand Down
4 changes: 2 additions & 2 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ fn build(
) -> anyhow::Result<Option<usize>> {
let (mut dumb_console, mut fancy_console);
let progress: &mut dyn Progress = if terminal::use_fancy() {
fancy_console = FancyConsoleProgress::new(verbose, false, None);
fancy_console = FancyConsoleProgress::new(verbose, None);
&mut fancy_console
} else {
dumb_console = DumbConsoleProgress::new(verbose, false, None);
dumb_console = DumbConsoleProgress::new(verbose, None);
&mut dumb_console
};

Expand Down

0 comments on commit fe66f5b

Please sign in to comment.