1
- use std:: io:: { self , BufRead , Read , Write } ;
2
-
3
- use super :: terminalsource:: ColorableTerminal ;
4
- use crate :: process:: Process ;
1
+ use std:: io:: { self , BufRead , Read } ;
5
2
6
3
/// Stand-in for std::io::Stdin
7
4
pub trait Stdin {
@@ -21,75 +18,13 @@ impl Stdin for io::Stdin {
21
18
}
22
19
}
23
20
24
- // -------------- stdout -------------------------------
25
-
26
- /// This is a stand-in for [`std::io::StdoutLock`] and [`std::io::StderrLock`].
27
- pub trait WriterLock : Write { }
28
-
29
- /// This is a stand-in for [`std::io::Stdout`] or [`std::io::Stderr`].
30
- /// TODO: remove Sync.
31
- pub trait Writer : Write + Send + Sync {
32
- /// This is a stand-in for [`std::io::Stdout::lock`] or [`std::io::Stderr::lock`].
33
- fn lock ( & self ) -> Box < dyn WriterLock + ' _ > ;
34
-
35
- /// Query whether a TTY is present. Used in download_tracker - we may want
36
- /// to remove this entirely with a better progress bar system (in favour of
37
- /// filtering in the Terminal layer?)
38
- fn is_a_tty ( & self , process : & Process ) -> bool ;
39
-
40
- /// Construct a terminal on this writer.
41
- fn terminal ( & self , process : & Process ) -> ColorableTerminal ;
42
- }
43
-
44
- // ----------------- OS support for writers -----------------
45
-
46
- impl WriterLock for io:: StdoutLock < ' _ > { }
47
-
48
- impl Writer for io:: Stdout {
49
- fn is_a_tty ( & self , process : & Process ) -> bool {
50
- match process {
51
- crate :: process:: Process :: OsProcess ( p) => p. stdout_is_a_tty ,
52
- #[ cfg( feature = "test" ) ]
53
- crate :: process:: Process :: TestProcess ( _) => unreachable ! ( ) ,
54
- }
55
- }
56
-
57
- fn lock ( & self ) -> Box < dyn WriterLock + ' _ > {
58
- Box :: new ( io:: Stdout :: lock ( self ) )
59
- }
60
-
61
- fn terminal ( & self , process : & Process ) -> ColorableTerminal {
62
- ColorableTerminal :: stdout ( process)
63
- }
64
- }
65
-
66
- impl WriterLock for io:: StderrLock < ' _ > { }
67
-
68
- impl Writer for io:: Stderr {
69
- fn is_a_tty ( & self , process : & Process ) -> bool {
70
- match process {
71
- crate :: process:: Process :: OsProcess ( p) => p. stderr_is_a_tty ,
72
- #[ cfg( feature = "test" ) ]
73
- crate :: process:: Process :: TestProcess ( _) => unreachable ! ( ) ,
74
- }
75
- }
76
-
77
- fn lock ( & self ) -> Box < dyn WriterLock + ' _ > {
78
- Box :: new ( io:: Stderr :: lock ( self ) )
79
- }
80
-
81
- fn terminal ( & self , process : & Process ) -> ColorableTerminal {
82
- ColorableTerminal :: stderr ( process)
83
- }
84
- }
85
-
86
21
#[ cfg( feature = "test" ) ]
87
22
pub ( crate ) use self :: test_support:: * ;
88
23
89
24
#[ cfg( feature = "test" ) ]
90
25
mod test_support {
91
26
use std:: {
92
- io:: Cursor ,
27
+ io:: { Cursor , Write } ,
93
28
sync:: { Arc , Mutex , MutexGuard } ,
94
29
} ;
95
30
@@ -136,8 +71,6 @@ mod test_support {
136
71
inner : MutexGuard < ' a , Vec < u8 > > ,
137
72
}
138
73
139
- impl WriterLock for TestWriterLock < ' _ > { }
140
-
141
74
impl Write for TestWriterLock < ' _ > {
142
75
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
143
76
self . inner . write ( buf)
@@ -164,20 +97,6 @@ mod test_support {
164
97
}
165
98
}
166
99
167
- impl Writer for TestWriter {
168
- fn is_a_tty ( & self , _: & Process ) -> bool {
169
- false
170
- }
171
-
172
- fn lock ( & self ) -> Box < dyn WriterLock + ' _ > {
173
- Box :: new ( self . lock ( ) )
174
- }
175
-
176
- fn terminal ( & self , process : & Process ) -> ColorableTerminal {
177
- ColorableTerminal :: test ( self . clone ( ) , process)
178
- }
179
- }
180
-
181
100
impl Write for TestWriter {
182
101
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
183
102
self . lock ( ) . write ( buf)
0 commit comments