@@ -91,7 +91,7 @@ fn bits_to_color(bits: u16) -> color::Color {
91
91
}
92
92
}
93
93
94
- impl < T : Writer > WinConsole < T > {
94
+ impl < T : Writer + Send > WinConsole < T > {
95
95
fn apply ( & mut self ) {
96
96
let _unused = self . buf . flush ( ) ;
97
97
let mut accum: libc:: WORD = 0 ;
@@ -112,6 +112,26 @@ impl<T: Writer> WinConsole<T> {
112
112
SetConsoleTextAttribute ( out, accum) ;
113
113
}
114
114
}
115
+
116
+ /// Returns `None` whenever the terminal cannot be created for some
117
+ /// reason.
118
+ pub fn new ( out : T ) -> Option < Box < Terminal < T > +Send +' static > > {
119
+ let fg;
120
+ let bg;
121
+ unsafe {
122
+ let mut buffer_info = :: std:: mem:: uninitialized ( ) ;
123
+ if GetConsoleScreenBufferInfo ( GetStdHandle ( -11 ) , & mut buffer_info) != 0 {
124
+ fg = bits_to_color ( buffer_info. wAttributes ) ;
125
+ bg = bits_to_color ( buffer_info. wAttributes >> 4 ) ;
126
+ } else {
127
+ fg = color:: WHITE ;
128
+ bg = color:: BLACK ;
129
+ }
130
+ }
131
+ Some ( box WinConsole { buf : out,
132
+ def_foreground : fg, def_background : bg,
133
+ foreground : fg, background : bg } as Box < Terminal < T > +Send > )
134
+ }
115
135
}
116
136
117
137
impl < T : Writer > Writer for WinConsole < T > {
@@ -124,7 +144,7 @@ impl<T: Writer> Writer for WinConsole<T> {
124
144
}
125
145
}
126
146
127
- impl < T : Writer > Terminal < T > for WinConsole < T > {
147
+ impl < T : Writer + Send > Terminal < T > for WinConsole < T > {
128
148
fn fg ( & mut self , color : color:: Color ) -> IoResult < bool > {
129
149
self . foreground = color;
130
150
self . apply ( ) ;
@@ -177,26 +197,6 @@ impl<T: Writer> Terminal<T> for WinConsole<T> {
177
197
fn get_mut < ' a > ( & ' a mut self ) -> & ' a mut T { & mut self . buf }
178
198
}
179
199
180
- impl < T : Writer > WinConsole < T > {
181
- fn new ( out : T ) -> Option < Box < WinConsole < T > +Send +' static > > {
182
- let fg;
183
- let bg;
184
- unsafe {
185
- let mut buffer_info = :: std:: mem:: uninitialized ( ) ;
186
- if GetConsoleScreenBufferInfo ( GetStdHandle ( -11 ) , & mut buffer_info) != 0 {
187
- fg = bits_to_color ( buffer_info. wAttributes ) ;
188
- bg = bits_to_color ( buffer_info. wAttributes >> 4 ) ;
189
- } else {
190
- fg = color:: WHITE ;
191
- bg = color:: BLACK ;
192
- }
193
- }
194
- Some ( box WinConsole { buf : out,
195
- def_foreground : fg, def_background : bg,
196
- foreground : fg, background : bg } )
197
- }
198
- }
199
-
200
- impl < T : Writer > UnwrappableTerminal < T > for WinConsole < T > {
200
+ impl < T : Writer +Send > UnwrappableTerminal < T > for WinConsole < T > {
201
201
fn unwrap ( self ) -> T { self . buf }
202
202
}
0 commit comments