@@ -91,7 +91,7 @@ fn bits_to_color(bits: u16) -> color::Color {
9191 }
9292}
9393
94- impl < T : Writer > WinConsole < T > {
94+ impl < T : Writer + Send > WinConsole < T > {
9595 fn apply ( & mut self ) {
9696 let _unused = self . buf . flush ( ) ;
9797 let mut accum: libc:: WORD = 0 ;
@@ -112,6 +112,26 @@ impl<T: Writer> WinConsole<T> {
112112 SetConsoleTextAttribute ( out, accum) ;
113113 }
114114 }
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+ }
115135}
116136
117137impl < T : Writer > Writer for WinConsole < T > {
@@ -124,7 +144,7 @@ impl<T: Writer> Writer for WinConsole<T> {
124144 }
125145}
126146
127- impl < T : Writer > Terminal < T > for WinConsole < T > {
147+ impl < T : Writer + Send > Terminal < T > for WinConsole < T > {
128148 fn fg ( & mut self , color : color:: Color ) -> IoResult < bool > {
129149 self . foreground = color;
130150 self . apply ( ) ;
@@ -177,26 +197,6 @@ impl<T: Writer> Terminal<T> for WinConsole<T> {
177197 fn get_mut < ' a > ( & ' a mut self ) -> & ' a mut T { & mut self . buf }
178198}
179199
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 > {
201201 fn unwrap ( self ) -> T { self . buf }
202202}
0 commit comments