@@ -39,7 +39,7 @@ use term::Terminal;
39
39
use walkdir:: DirEntry ;
40
40
41
41
use args:: Args ;
42
- use out:: Out ;
42
+ use out:: { NoColorTerminal , Out , OutBuffer } ;
43
43
use printer:: Printer ;
44
44
use search:: InputBuffer ;
45
45
@@ -90,7 +90,8 @@ fn run(args: Args) -> Result<u64> {
90
90
return run_types ( args) ;
91
91
}
92
92
let args = Arc :: new ( args) ;
93
- let out = Arc :: new ( Mutex :: new ( args. out ( io:: stdout ( ) ) ) ) ;
93
+ let out = Arc :: new ( Mutex :: new ( args. out ( ) ) ) ;
94
+ let outbuf = args. outbuf ( ) ;
94
95
let mut workers = vec ! [ ] ;
95
96
96
97
let mut workq = {
@@ -101,7 +102,7 @@ fn run(args: Args) -> Result<u64> {
101
102
out : out. clone ( ) ,
102
103
chan_work : stealer. clone ( ) ,
103
104
inpbuf : args. input_buffer ( ) ,
104
- outbuf : Some ( vec ! [ ] ) ,
105
+ outbuf : Some ( outbuf . clone ( ) ) ,
105
106
grep : args. grep ( ) ,
106
107
match_count : 0 ,
107
108
} ;
@@ -129,7 +130,8 @@ fn run(args: Args) -> Result<u64> {
129
130
}
130
131
131
132
fn run_files ( args : Args ) -> Result < u64 > {
132
- let mut printer = args. printer ( io:: BufWriter :: new ( io:: stdout ( ) ) ) ;
133
+ let term = NoColorTerminal :: new ( io:: BufWriter :: new ( io:: stdout ( ) ) ) ;
134
+ let mut printer = args. printer ( term) ;
133
135
let mut file_count = 0 ;
134
136
for p in args. paths ( ) {
135
137
if p == Path :: new ( "-" ) {
@@ -146,7 +148,8 @@ fn run_files(args: Args) -> Result<u64> {
146
148
}
147
149
148
150
fn run_types ( args : Args ) -> Result < u64 > {
149
- let mut printer = args. printer ( io:: BufWriter :: new ( io:: stdout ( ) ) ) ;
151
+ let term = NoColorTerminal :: new ( io:: BufWriter :: new ( io:: stdout ( ) ) ) ;
152
+ let mut printer = args. printer ( term) ;
150
153
let mut ty_count = 0 ;
151
154
for def in args. type_defs ( ) {
152
155
printer. type_def ( def) ;
@@ -168,10 +171,10 @@ enum WorkReady {
168
171
169
172
struct Worker {
170
173
args : Arc < Args > ,
171
- out : Arc < Mutex < Out < io :: Stdout > > > ,
174
+ out : Arc < Mutex < Out > > ,
172
175
chan_work : Stealer < Work > ,
173
176
inpbuf : InputBuffer ,
174
- outbuf : Option < Vec < u8 > > ,
177
+ outbuf : Option < OutBuffer > ,
175
178
grep : Grep ,
176
179
match_count : u64 ,
177
180
}
@@ -203,12 +206,12 @@ impl Worker {
203
206
let mut out = self . out . lock ( ) . unwrap ( ) ;
204
207
out. write ( & outbuf) ;
205
208
}
206
- self . outbuf = Some ( outbuf. into_inner ( ) ) ;
209
+ self . outbuf = Some ( outbuf) ;
207
210
}
208
211
self . match_count
209
212
}
210
213
211
- fn do_work < W : Send + io :: Write > (
214
+ fn do_work < W : Send + Terminal > (
212
215
& mut self ,
213
216
printer : & mut Printer < W > ,
214
217
work : WorkReady ,
@@ -241,7 +244,7 @@ impl Worker {
241
244
}
242
245
}
243
246
244
- fn search < R : io:: Read , W : Send + io :: Write > (
247
+ fn search < R : io:: Read , W : Send + Terminal > (
245
248
& mut self ,
246
249
printer : & mut Printer < W > ,
247
250
path : & Path ,
@@ -256,7 +259,7 @@ impl Worker {
256
259
) . run ( ) . map_err ( From :: from)
257
260
}
258
261
259
- fn search_mmap < W : Send + io :: Write > (
262
+ fn search_mmap < W : Send + Terminal > (
260
263
& mut self ,
261
264
printer : & mut Printer < W > ,
262
265
path : & Path ,
0 commit comments