@@ -90,7 +90,7 @@ fn bits_to_color(bits: u16) -> color::Color {
9090 }
9191}
9292
93- impl < T : Writer > WinConsole < T > {
93+ impl < T : Writer + Send > WinConsole < T > {
9494 fn apply ( & mut self ) {
9595 let _unused = self . buf . flush ( ) ;
9696 let mut accum: libc:: WORD = 0 ;
@@ -111,6 +111,26 @@ impl<T: Writer> WinConsole<T> {
111111 SetConsoleTextAttribute ( out, accum) ;
112112 }
113113 }
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+ }
114134}
115135
116136impl < T : Writer > Writer for WinConsole < T > {
@@ -123,7 +143,7 @@ impl<T: Writer> Writer for WinConsole<T> {
123143 }
124144}
125145
126- impl < T : Writer > Terminal < T > for WinConsole < T > {
146+ impl < T : Writer + Send > Terminal < T > for WinConsole < T > {
127147 fn fg ( & mut self , color : color:: Color ) -> IoResult < bool > {
128148 self . foreground = color;
129149 self . apply ( ) ;
@@ -176,26 +196,6 @@ impl<T: Writer> Terminal<T> for WinConsole<T> {
176196 fn get_mut < ' a > ( & ' a mut self ) -> & ' a mut T { & mut self . buf }
177197}
178198
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 > {
200200 fn unwrap ( self ) -> T { self . buf }
201201}
0 commit comments