@@ -42,7 +42,8 @@ pub trait Progress {
42
42
/// used when a task fails; we want the final output to show that failed
43
43
/// task's output even if we do more work after it fails.
44
44
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 ) ;
46
47
}
47
48
48
49
/// Currently running build task, as tracked for progress updates.
@@ -65,16 +66,14 @@ pub struct DumbConsoleProgress {
65
66
/// The id of the last command printed, used to avoid printing it twice
66
67
/// when we have two updates from the same command in a row.
67
68
last_started : Option < BuildId > ,
68
- quiet : bool ,
69
69
callback : Option < Box < dyn Fn ( & str ) + Send > > ,
70
70
}
71
71
72
72
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 {
74
74
Self {
75
75
verbose,
76
76
last_started : None ,
77
- quiet,
78
77
callback,
79
78
}
80
79
}
@@ -108,13 +107,11 @@ impl Progress for DumbConsoleProgress {
108
107
}
109
108
}
110
109
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) ) )
112
114
}
113
- Termination :: Failure => self . log_ignore_quiet ( & format ! (
114
- "{} {}" ,
115
- "failed:" . red( ) . bold( ) ,
116
- build_message( build)
117
- ) ) ,
118
115
} ;
119
116
if !result. output . is_empty ( ) {
120
117
if let Some ( ref callback) = self . callback {
@@ -127,21 +124,13 @@ impl Progress for DumbConsoleProgress {
127
124
}
128
125
129
126
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) ;
136
129
}
137
130
}
138
131
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) ;
145
134
}
146
135
}
147
136
@@ -159,7 +148,7 @@ pub struct FancyConsoleProgress {
159
148
const UPDATE_DELAY : Duration = std:: time:: Duration :: from_millis ( 50 ) ;
160
149
161
150
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 {
163
152
let dirty_cond = Arc :: new ( Condvar :: new ( ) ) ;
164
153
let state = Arc :: new ( Mutex :: new ( FancyState {
165
154
done : false ,
@@ -168,7 +157,6 @@ impl FancyConsoleProgress {
168
157
counts : StateCounts :: default ( ) ,
169
158
tasks : VecDeque :: new ( ) ,
170
159
verbose,
171
- quiet,
172
160
callback,
173
161
} ) ) ;
174
162
@@ -224,14 +212,11 @@ impl Progress for FancyConsoleProgress {
224
212
}
225
213
226
214
fn log ( & mut self , msg : & str ) {
227
- if self . state . lock ( ) . unwrap ( ) . quiet {
228
- return ;
229
- }
230
215
self . state . lock ( ) . unwrap ( ) . log ( msg) ;
231
216
}
232
217
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) ;
235
220
}
236
221
}
237
222
@@ -253,7 +238,6 @@ struct FancyState {
253
238
tasks : VecDeque < Task > ,
254
239
/// Whether to print command lines of started programs.
255
240
verbose : bool ,
256
- quiet : bool ,
257
241
callback : Option < Box < dyn Fn ( & str ) + Send > > ,
258
242
}
259
243
@@ -299,10 +283,12 @@ impl FancyState {
299
283
self . log ( build_message ( build) )
300
284
}
301
285
}
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 ! (
306
292
"{} {}" ,
307
293
"failed:" . red( ) . bold( ) ,
308
294
build_message( build)
@@ -320,25 +306,16 @@ impl FancyState {
320
306
}
321
307
322
308
fn log ( & mut self , msg : & str ) {
323
- if self . quiet {
324
- return ;
325
- }
326
309
self . clear_progress ( ) ;
327
- if let Some ( ref callback) = self . callback {
328
- callback ( msg) ;
329
- } else {
310
+ if self . callback . is_none ( ) {
330
311
println ! ( "{}" , msg) ;
331
312
}
332
313
self . dirty ( ) ;
333
314
}
334
315
335
- fn log_ignore_quiet ( & mut self , msg : & str ) {
316
+ fn log_when_failed ( & mut self , msg : & str ) {
336
317
self . clear_progress ( ) ;
337
- if let Some ( ref c) = self . callback {
338
- c ( msg) ;
339
- } else {
340
- println ! ( "{}" , msg) ;
341
- }
318
+ println ! ( "{}" , msg) ;
342
319
self . dirty ( ) ;
343
320
}
344
321
@@ -352,13 +329,14 @@ impl FancyState {
352
329
// If the user hit ctl-c, it may have printed something on the line.
353
330
// So \r to go to first column first, then clear anything below.
354
331
std:: io:: stdout ( ) . write_all ( b"\r \x1b [J" ) . unwrap ( ) ;
332
+ let _ = std:: io:: stdout ( ) . flush ( ) ;
355
333
}
356
334
357
335
fn print_progress ( & mut self ) {
358
- if self . quiet {
336
+ self . clear_progress ( ) ;
337
+ if self . done {
359
338
return ;
360
339
}
361
- self . clear_progress ( ) ;
362
340
let failed = self . counts . get ( BuildState :: Failed ) ;
363
341
let mut progress_line = format ! (
364
342
"[{}] {}/{} done, " ,
0 commit comments