Skip to content

Commit d5bc0cc

Browse files
committed
interanl: remove quiet
1 parent e1b0e92 commit d5bc0cc

File tree

3 files changed

+29
-51
lines changed

3 files changed

+29
-51
lines changed

Diff for: benches/parse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn bench_parse_synthetic(c: &mut Criterion) {
5454
fn bench_parse_file(c: &mut Criterion, input: &[u8]) {
5555
c.bench_function("parse benches/build.ninja", |b| {
5656
b.iter(|| {
57-
let mut parser = n2::parse::Parser::new(&input);
57+
let mut parser = n2::parse::Parser::new(input);
5858
loop {
5959
if parser.read().unwrap().is_none() {
6060
break;

Diff for: src/progress.rs

+26-48
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ pub trait Progress {
4242
/// used when a task fails; we want the final output to show that failed
4343
/// task's output even if we do more work after it fails.
4444
fn log(&mut self, msg: &str);
45-
fn log_ignore_quiet(&mut self, msg: &str);
45+
46+
fn log_when_failed(&mut self, msg: &str);
4647
}
4748

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

7272
impl DumbConsoleProgress {
73-
pub fn new(verbose: bool, quiet: bool, callback: Option<Box<dyn Fn(&str) + Send>>) -> Self {
73+
pub fn new(verbose: bool, callback: Option<Box<dyn Fn(&str) + Send>>) -> Self {
7474
Self {
7575
verbose,
7676
last_started: None,
77-
quiet,
7877
callback,
7978
}
8079
}
@@ -108,13 +107,11 @@ impl Progress for DumbConsoleProgress {
108107
}
109108
}
110109
Termination::Interrupted => {
111-
self.log_ignore_quiet(&format!("interrupted: {}", build_message(build)))
110+
self.log_when_failed(&format!("interrupted: {}", build_message(build)))
111+
}
112+
Termination::Failure => {
113+
self.log_when_failed(&format!("failed: {}", build_message(build)))
112114
}
113-
Termination::Failure => self.log_ignore_quiet(&format!(
114-
"{} {}",
115-
"failed:".red().bold(),
116-
build_message(build)
117-
)),
118115
};
119116
if !result.output.is_empty() {
120117
if let Some(ref callback) = self.callback {
@@ -127,21 +124,13 @@ impl Progress for DumbConsoleProgress {
127124
}
128125

129126
fn log(&mut self, msg: &str) {
130-
if !self.quiet {
131-
if let Some(ref callback) = self.callback {
132-
callback(msg);
133-
} else {
134-
println!("{}", msg);
135-
}
127+
if self.callback.is_none() {
128+
println!("{}", msg);
136129
}
137130
}
138131

139-
fn log_ignore_quiet(&mut self, msg: &str) {
140-
if let Some(ref callback) = self.callback {
141-
callback(msg);
142-
} else {
143-
println!("{}", msg);
144-
}
132+
fn log_when_failed(&mut self, msg: &str) {
133+
println!("{}", msg);
145134
}
146135
}
147136

@@ -159,7 +148,7 @@ pub struct FancyConsoleProgress {
159148
const UPDATE_DELAY: Duration = std::time::Duration::from_millis(50);
160149

161150
impl FancyConsoleProgress {
162-
pub fn new(verbose: bool, quiet: bool, callback: Option<Box<dyn Fn(&str) + Send>>) -> Self {
151+
pub fn new(verbose: bool, callback: Option<Box<dyn Fn(&str) + Send>>) -> Self {
163152
let dirty_cond = Arc::new(Condvar::new());
164153
let state = Arc::new(Mutex::new(FancyState {
165154
done: false,
@@ -168,7 +157,6 @@ impl FancyConsoleProgress {
168157
counts: StateCounts::default(),
169158
tasks: VecDeque::new(),
170159
verbose,
171-
quiet,
172160
callback,
173161
}));
174162

@@ -224,14 +212,11 @@ impl Progress for FancyConsoleProgress {
224212
}
225213

226214
fn log(&mut self, msg: &str) {
227-
if self.state.lock().unwrap().quiet {
228-
return;
229-
}
230215
self.state.lock().unwrap().log(msg);
231216
}
232217

233-
fn log_ignore_quiet(&mut self, msg: &str) {
234-
self.state.lock().unwrap().log(msg);
218+
fn log_when_failed(&mut self, msg: &str) {
219+
self.state.lock().unwrap().log_when_failed(msg);
235220
}
236221
}
237222

@@ -253,7 +238,6 @@ struct FancyState {
253238
tasks: VecDeque<Task>,
254239
/// Whether to print command lines of started programs.
255240
verbose: bool,
256-
quiet: bool,
257241
callback: Option<Box<dyn Fn(&str) + Send>>,
258242
}
259243

@@ -299,10 +283,12 @@ impl FancyState {
299283
self.log(build_message(build))
300284
}
301285
}
302-
Termination::Interrupted => {
303-
self.log_ignore_quiet(&format!("interrupted: {}", build_message(build)))
304-
}
305-
Termination::Failure => self.log_ignore_quiet(&format!(
286+
Termination::Interrupted => self.log_when_failed(&format!(
287+
"{} {}",
288+
"interrupted:".red(),
289+
build_message(build)
290+
)),
291+
Termination::Failure => self.log_when_failed(&format!(
306292
"{} {}",
307293
"failed:".red().bold(),
308294
build_message(build)
@@ -320,25 +306,16 @@ impl FancyState {
320306
}
321307

322308
fn log(&mut self, msg: &str) {
323-
if self.quiet {
324-
return;
325-
}
326309
self.clear_progress();
327-
if let Some(ref callback) = self.callback {
328-
callback(msg);
329-
} else {
310+
if self.callback.is_none() {
330311
println!("{}", msg);
331312
}
332313
self.dirty();
333314
}
334315

335-
fn log_ignore_quiet(&mut self, msg: &str) {
316+
fn log_when_failed(&mut self, msg: &str) {
336317
self.clear_progress();
337-
if let Some(ref c) = self.callback {
338-
c(msg);
339-
} else {
340-
println!("{}", msg);
341-
}
318+
println!("{}", msg);
342319
self.dirty();
343320
}
344321

@@ -352,13 +329,14 @@ impl FancyState {
352329
// If the user hit ctl-c, it may have printed something on the line.
353330
// So \r to go to first column first, then clear anything below.
354331
std::io::stdout().write_all(b"\r\x1b[J").unwrap();
332+
let _ = std::io::stdout().flush();
355333
}
356334

357335
fn print_progress(&mut self) {
358-
if self.quiet {
336+
self.clear_progress();
337+
if self.done {
359338
return;
360339
}
361-
self.clear_progress();
362340
let failed = self.counts.get(BuildState::Failed);
363341
let mut progress_line = format!(
364342
"[{}] {}/{} done, ",

Diff for: src/run.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ fn build(
1414
) -> anyhow::Result<Option<usize>> {
1515
let (mut dumb_console, mut fancy_console);
1616
let progress: &mut dyn Progress = if terminal::use_fancy() {
17-
fancy_console = FancyConsoleProgress::new(verbose, false, None);
17+
fancy_console = FancyConsoleProgress::new(verbose, None);
1818
&mut fancy_console
1919
} else {
20-
dumb_console = DumbConsoleProgress::new(verbose, false, None);
20+
dumb_console = DumbConsoleProgress::new(verbose, None);
2121
&mut dumb_console
2222
};
2323

0 commit comments

Comments
 (0)