Skip to content

Commit

Permalink
Try and fix Windows terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Oct 30, 2014
1 parent 3adb755 commit 88a250d
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/libterm/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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> {
Expand All @@ -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();
Expand Down Expand Up @@ -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 }
}

5 comments on commit 88a250d

@bors
Copy link
Contributor

@bors bors commented on 88a250d Oct 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at nrc@88a250d

@bors
Copy link
Contributor

@bors bors commented on 88a250d Oct 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nick29581/rust/object-safety = 88a250d into auto

@bors
Copy link
Contributor

@bors bors commented on 88a250d Oct 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nick29581/rust/object-safety = 88a250d merged ok, testing candidate = 2d27bfa

@bors
Copy link
Contributor

@bors bors commented on 88a250d Oct 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 88a250d Oct 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 2d27bfa

Please sign in to comment.