about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2014-10-22 17:42:13 +1300
committerNick Cameron <ncameron@mozilla.com>2014-10-30 16:12:59 +1300
commit88a250d194d7a7995c0740d706d9eb19007a85ee (patch)
tree45c97d1a1f2b7a74cd85b76f4cef6011d4a64748
parent3adb7554d63a66cc00323898a9b260fc616e94e2 (diff)
downloadrust-88a250d194d7a7995c0740d706d9eb19007a85ee.tar.gz
rust-88a250d194d7a7995c0740d706d9eb19007a85ee.zip
Try and fix Windows terminal
-rw-r--r--src/libterm/win.rs46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/libterm/win.rs b/src/libterm/win.rs
index 60b811db8fc..7ce6fb658b5 100644
--- a/src/libterm/win.rs
+++ b/src/libterm/win.rs
@@ -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 @@ impl<T: Writer> WinConsole<T> {
             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 @@ impl<T: Writer> Writer for WinConsole<T> {
     }
 }
 
-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 @@ impl<T: Writer> Terminal<T> for WinConsole<T> {
     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 }
 }