1
- use std:: { io , io :: prelude :: Write } ;
1
+ use std:: io ;
2
2
3
3
use super :: OutputFormatter ;
4
4
use crate :: {
5
5
bench:: fmt_bench_samples,
6
- console:: { ConsoleTestDiscoveryState , ConsoleTestState , OutputLocation } ,
6
+ console:: { ConsoleTestDiscoveryState , ConsoleTestState , Output } ,
7
7
term,
8
8
test_result:: TestResult ,
9
9
time,
@@ -15,8 +15,8 @@ use crate::{
15
15
// result chars leaves 12 chars for a progress count like " 11704/12853".
16
16
const QUIET_MODE_MAX_COLUMN : usize = 88 ;
17
17
18
- pub ( crate ) struct TerseFormatter < T > {
19
- out : OutputLocation < T > ,
18
+ pub ( crate ) struct TerseFormatter < ' a > {
19
+ out : & ' a mut dyn Output ,
20
20
use_color : bool ,
21
21
is_multithreaded : bool ,
22
22
/// Number of columns to fill when aligning names
@@ -27,9 +27,9 @@ pub(crate) struct TerseFormatter<T> {
27
27
total_test_count : usize ,
28
28
}
29
29
30
- impl < T : Write > TerseFormatter < T > {
30
+ impl < ' a > TerseFormatter < ' a > {
31
31
pub fn new (
32
- out : OutputLocation < T > ,
32
+ out : & ' a mut dyn Output ,
33
33
use_color : bool ,
34
34
max_name_len : usize ,
35
35
is_multithreaded : bool ,
@@ -98,29 +98,13 @@ impl<T: Write> TerseFormatter<T> {
98
98
Ok ( ( ) )
99
99
}
100
100
101
- pub fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > {
102
- match self . out {
103
- OutputLocation :: Pretty ( ref mut term) => {
104
- if self . use_color {
105
- term. fg ( color) ?;
106
- }
107
- term. write_all ( word. as_bytes ( ) ) ?;
108
- if self . use_color {
109
- term. reset ( ) ?;
110
- }
111
- term. flush ( )
112
- }
113
- OutputLocation :: Raw ( ref mut stdout) => {
114
- stdout. write_all ( word. as_bytes ( ) ) ?;
115
- stdout. flush ( )
116
- }
117
- }
101
+ fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > {
102
+ if self . use_color { self . out . write_pretty ( word, color) } else { self . out . write_plain ( word) }
118
103
}
119
104
120
- pub fn write_plain < S : AsRef < str > > ( & mut self , s : S ) -> io:: Result < ( ) > {
105
+ fn write_plain < S : AsRef < str > > ( & mut self , s : S ) -> io:: Result < ( ) > {
121
106
let s = s. as_ref ( ) ;
122
- self . out . write_all ( s. as_bytes ( ) ) ?;
123
- self . out . flush ( )
107
+ self . out . write_plain ( s)
124
108
}
125
109
126
110
pub fn write_outputs ( & mut self , state : & ConsoleTestState ) -> io:: Result < ( ) > {
@@ -187,7 +171,7 @@ impl<T: Write> TerseFormatter<T> {
187
171
}
188
172
}
189
173
190
- impl < T : Write > OutputFormatter for TerseFormatter < T > {
174
+ impl OutputFormatter for TerseFormatter < ' _ > {
191
175
fn write_discovery_start ( & mut self ) -> io:: Result < ( ) > {
192
176
Ok ( ( ) )
193
177
}
0 commit comments