@@ -66,54 +66,84 @@ pub mod terminfo;
66
66
#[ cfg( windows) ]
67
67
mod win;
68
68
69
+ /// A hack to work around the fact that `Box<Writer + Send>` does not
70
+ /// currently implement `Writer`.
71
+ pub struct WriterWrapper {
72
+ wrapped : Box < Writer + Send > ,
73
+ }
74
+
75
+ impl Writer for WriterWrapper {
76
+ #[ inline]
77
+ fn write ( & mut self , buf : & [ u8 ] ) -> IoResult < ( ) > {
78
+ self . wrapped . write ( buf)
79
+ }
80
+
81
+ #[ inline]
82
+ fn flush ( & mut self ) -> IoResult < ( ) > {
83
+ self . wrapped . flush ( )
84
+ }
85
+ }
86
+
69
87
#[ cfg( not( windows) ) ]
70
88
/// Return a Terminal wrapping stdout, or None if a terminal couldn't be
71
89
/// opened.
72
- pub fn stdout ( ) -> Option < Box < Terminal < Box < Writer + Send > > + Send > > {
73
- let ti: Option < TerminfoTerminal < Box < Writer + Send > > >
74
- = Terminal :: new ( box std:: io:: stdout ( ) as Box < Writer + Send > ) ;
75
- ti. map ( |t| box t as Box < Terminal < Box < Writer + Send > + Send > + Send > )
90
+ pub fn stdout ( ) -> Option < Box < Terminal < WriterWrapper > + Send > > {
91
+ let ti: Option < TerminfoTerminal < WriterWrapper > >
92
+ = Terminal :: new ( WriterWrapper {
93
+ wrapped : box std:: io:: stdout ( ) as Box < Writer + Send > ,
94
+ } ) ;
95
+ ti. map ( |t| box t as Box < Terminal < WriterWrapper > + Send > )
76
96
}
77
97
78
98
#[ cfg( windows) ]
79
99
/// Return a Terminal wrapping stdout, or None if a terminal couldn't be
80
100
/// opened.
81
- pub fn stdout ( ) -> Option < Box < Terminal < Box < Writer + Send > + Send > + Send > > {
82
- let ti: Option < TerminfoTerminal < Box < Writer + Send > > >
83
- = Terminal :: new ( box std:: io:: stdout ( ) as Box < Writer + Send > ) ;
101
+ pub fn stdout ( ) -> Option < Box < Terminal < WriterWrapper > + Send > > {
102
+ let ti: Option < TerminfoTerminal < WriterWrapper > >
103
+ = Terminal :: new ( WriterWrapper {
104
+ wrapped : box std:: io:: stdout ( ) as Box < Writer + Send > ,
105
+ } ) ;
84
106
85
107
match ti {
86
- Some ( t) => Some ( box t as Box < Terminal < Box < Writer + Send > + Send > + Send > ) ,
108
+ Some ( t) => Some ( box t as Box < Terminal < WriterWrapper > + Send > ) ,
87
109
None => {
88
- let wc: Option < WinConsole < Box < Writer + Send > > >
89
- = Terminal :: new ( box std:: io:: stdout ( ) as Box < Writer + Send > ) ;
90
- wc. map ( |w| box w as Box < Terminal < Box < Writer + Send > + Send > + Send > )
110
+ let wc: Option < WinConsole < WriterWrapper > >
111
+ = Terminal :: new ( WriterWrapper {
112
+ wrapped : box std:: io:: stdout ( ) as Box < Writer + Send > ,
113
+ } ) ;
114
+ wc. map ( |w| box w as Box < Terminal < WriterWrapper > + Send > )
91
115
}
92
116
}
93
117
}
94
118
95
119
#[ cfg( not( windows) ) ]
96
120
/// Return a Terminal wrapping stderr, or None if a terminal couldn't be
97
121
/// opened.
98
- pub fn stderr ( ) -> Option < Box < Terminal < Box < Writer + Send > + Send > + Send > + Send > {
99
- let ti: Option < TerminfoTerminal < Box < Writer + Send > > >
100
- = Terminal :: new ( box std:: io:: stderr ( ) as Box < Writer + Send > ) ;
101
- ti. map ( |t| box t as Box < Terminal < Box < Writer + Send > + Send > + Send > )
122
+ pub fn stderr ( ) -> Option < Box < Terminal < WriterWrapper > + Send > + Send > {
123
+ let ti: Option < TerminfoTerminal < WriterWrapper > >
124
+ = Terminal :: new ( WriterWrapper {
125
+ wrapped : box std:: io:: stderr ( ) as Box < Writer + Send > ,
126
+ } ) ;
127
+ ti. map ( |t| box t as Box < Terminal < WriterWrapper > + Send > )
102
128
}
103
129
104
130
#[ cfg( windows) ]
105
131
/// Return a Terminal wrapping stderr, or None if a terminal couldn't be
106
132
/// opened.
107
- pub fn stderr ( ) -> Option < Box < Terminal < Box < Writer + Send > + Send > + Send > > {
108
- let ti: Option < TerminfoTerminal < Box < Writer + Send > > >
109
- = Terminal :: new ( box std:: io:: stderr ( ) as Box < Writer + Send > ) ;
133
+ pub fn stderr ( ) -> Option < Box < Terminal < WriterWrapper > + Send > + Send > {
134
+ let ti: Option < TerminfoTerminal < WriterWrapper > >
135
+ = Terminal :: new ( WriterWrapper {
136
+ wrapped : box std:: io:: stderr ( ) as Box < Writer + Send > ,
137
+ } ) ;
110
138
111
139
match ti {
112
- Some ( t) => Some ( box t as Box < Terminal < Box < Writer + Send > + Send > + Send > ) ,
140
+ Some ( t) => Some ( box t as Box < Terminal < WriterWrapper > + Send > ) ,
113
141
None => {
114
- let wc: Option < WinConsole < Box < Writer + Send > > >
115
- = Terminal :: new ( box std:: io:: stderr ( ) as Box < Writer + Send > ) ;
116
- wc. map ( |w| box w as Box < Terminal < Box < Writer + Send > + Send > + Send > )
142
+ let wc: Option < WinConsole < WriterWrapper > >
143
+ = Terminal :: new ( WriterWrapper {
144
+ wrapped : box std:: io:: stderr ( ) as Box < Writer + Send > ,
145
+ } ) ;
146
+ wc. map ( |w| box w as Box < Terminal < WriterWrapper > + Send > )
117
147
}
118
148
}
119
149
}
0 commit comments