]> git.lizzy.rs Git - rust.git/commitdiff
Try and fix Windows terminal
authorNick Cameron <ncameron@mozilla.com>
Wed, 22 Oct 2014 04:42:13 +0000 (17:42 +1300)
committerNick Cameron <ncameron@mozilla.com>
Thu, 30 Oct 2014 03:12:59 +0000 (16:12 +1300)
src/libterm/win.rs

index 60b811db8fc5a9d58714b3975826f7238a9bc60f..7ce6fb658b56d36a5998da51f3507a844b3c8d60 100644 (file)
@@ -91,7 +91,7 @@ fn bits_to_color(bits: u16) -> color::Color {
     }
 }
 
-impl<T: Writer> WinConsole<T> {
+impl<T: Writer+Send> WinConsole<T> {
     fn apply(&mut self) {
         let _unused = self.buf.flush();
         let mut accum: libc::WORD = 0;
@@ -112,6 +112,26 @@ fn apply(&mut self) {
             SetConsoleTextAttribute(out, accum);
         }
     }
+
+    /// Returns `None` whenever the terminal cannot be created for some
+    /// reason.
+    pub fn new(out: T) -> Option<Box<Terminal<T>+Send+'static>> {
+        let fg;
+        let bg;
+        unsafe {
+            let mut buffer_info = ::std::mem::uninitialized();
+            if GetConsoleScreenBufferInfo(GetStdHandle(-11), &mut buffer_info) != 0 {
+                fg = bits_to_color(buffer_info.wAttributes);
+                bg = bits_to_color(buffer_info.wAttributes >> 4);
+            } else {
+                fg = color::WHITE;
+                bg = color::BLACK;
+            }
+        }
+        Some(box WinConsole { buf: out,
+                              def_foreground: fg, def_background: bg,
+                              foreground: fg, background: bg } as Box<Terminal<T>+Send>)
+    }
 }
 
 impl<T: Writer> Writer for WinConsole<T> {
@@ -124,7 +144,7 @@ fn flush(&mut self) -> IoResult<()> {
     }
 }
 
-impl<T: Writer> Terminal<T> for WinConsole<T> {
+impl<T: Writer+Send> Terminal<T> for WinConsole<T> {
     fn fg(&mut self, color: color::Color) -> IoResult<bool> {
         self.foreground = color;
         self.apply();
@@ -177,26 +197,6 @@ fn get_ref<'a>(&'a self) -> &'a T { &self.buf }
     fn get_mut<'a>(&'a mut self) -> &'a mut T { &mut self.buf }
 }
 
-impl<T: Writer> WinConsole<T> {
-     fn new(out: T) -> Option<Box<WinConsole<T>+Send+'static>> {
-        let fg;
-        let bg;
-        unsafe {
-            let mut buffer_info = ::std::mem::uninitialized();
-            if GetConsoleScreenBufferInfo(GetStdHandle(-11), &mut buffer_info) != 0 {
-                fg = bits_to_color(buffer_info.wAttributes);
-                bg = bits_to_color(buffer_info.wAttributes >> 4);
-            } else {
-                fg = color::WHITE;
-                bg = color::BLACK;
-            }
-        }
-        Some(box WinConsole { buf: out,
-                              def_foreground: fg, def_background: bg,
-                              foreground: fg, background: bg } )
-    }
-}
-
-impl<T: Writer> UnwrappableTerminal<T> for WinConsole<T> {
+impl<T: Writer+Send> UnwrappableTerminal<T> for WinConsole<T> {
     fn unwrap(self) -> T { self.buf }
 }