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