diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-07-02 11:08:21 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-02 11:08:21 -0700 |
| commit | ff1dd44b40a7243f43a8d32ba8bd6026197c320b (patch) | |
| tree | 4460cbf0a917a289d1d3744d9645c5ab131ea9df /src/libterm | |
| parent | aa1163b92de7717eb7c5eba002b4012e0574a7fe (diff) | |
| parent | ca2778ede7c21efc3cf2e4e1152875ec09360770 (diff) | |
| download | rust-ff1dd44b40a7243f43a8d32ba8bd6026197c320b.tar.gz rust-ff1dd44b40a7243f43a8d32ba8bd6026197c320b.zip | |
Merge remote-tracking branch 'origin/master' into 0.11.0-release
Conflicts: src/libstd/lib.rs
Diffstat (limited to 'src/libterm')
| -rw-r--r-- | src/libterm/lib.rs | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 7eeb2dd26a9..56694e28b66 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -66,28 +66,52 @@ pub mod terminfo; #[cfg(windows)] mod win; +/// A hack to work around the fact that `Box<Writer + Send>` does not +/// currently implement `Writer`. +pub struct WriterWrapper { + wrapped: Box<Writer + Send>, +} + +impl Writer for WriterWrapper { + #[inline] + fn write(&mut self, buf: &[u8]) -> IoResult<()> { + self.wrapped.write(buf) + } + + #[inline] + fn flush(&mut self) -> IoResult<()> { + self.wrapped.flush() + } +} + #[cfg(not(windows))] /// Return a Terminal wrapping stdout, or None if a terminal couldn't be /// opened. -pub fn stdout() -> Option<Box<Terminal<Box<Writer + Send>> + Send>> { - let ti: Option<TerminfoTerminal<Box<Writer + Send>>> - = Terminal::new(box std::io::stdout() as Box<Writer + Send>); - ti.map(|t| box t as Box<Terminal<Box<Writer + Send> + Send> + Send>) +pub fn stdout() -> Option<Box<Terminal<WriterWrapper> + Send>> { + let ti: Option<TerminfoTerminal<WriterWrapper>> + = Terminal::new(WriterWrapper { + wrapped: box std::io::stdout() as Box<Writer + Send>, + }); + ti.map(|t| box t as Box<Terminal<WriterWrapper> + Send>) } #[cfg(windows)] /// Return a Terminal wrapping stdout, or None if a terminal couldn't be /// opened. -pub fn stdout() -> Option<Box<Terminal<Box<Writer + Send> + Send> + Send>> { - let ti: Option<TerminfoTerminal<Box<Writer + Send>>> - = Terminal::new(box std::io::stdout() as Box<Writer + Send>); +pub fn stdout() -> Option<Box<Terminal<WriterWrapper> + Send>> { + let ti: Option<TerminfoTerminal<WriterWrapper>> + = Terminal::new(WriterWrapper { + wrapped: box std::io::stdout() as Box<Writer + Send>, + }); match ti { - Some(t) => Some(box t as Box<Terminal<Box<Writer + Send> + Send> + Send>), + Some(t) => Some(box t as Box<Terminal<WriterWrapper> + Send>), None => { - let wc: Option<WinConsole<Box<Writer + Send>>> - = Terminal::new(box std::io::stdout() as Box<Writer + Send>); - wc.map(|w| box w as Box<Terminal<Box<Writer + Send> + Send> + Send>) + let wc: Option<WinConsole<WriterWrapper>> + = Terminal::new(WriterWrapper { + wrapped: box std::io::stdout() as Box<Writer + Send>, + }); + wc.map(|w| box w as Box<Terminal<WriterWrapper> + Send>) } } } @@ -95,25 +119,31 @@ pub fn stdout() -> Option<Box<Terminal<Box<Writer + Send> + Send> + Send>> { #[cfg(not(windows))] /// Return a Terminal wrapping stderr, or None if a terminal couldn't be /// opened. -pub fn stderr() -> Option<Box<Terminal<Box<Writer + Send> + Send> + Send> + Send> { - let ti: Option<TerminfoTerminal<Box<Writer + Send>>> - = Terminal::new(box std::io::stderr() as Box<Writer + Send>); - ti.map(|t| box t as Box<Terminal<Box<Writer + Send> + Send> + Send>) +pub fn stderr() -> Option<Box<Terminal<WriterWrapper> + Send> + Send> { + let ti: Option<TerminfoTerminal<WriterWrapper>> + = Terminal::new(WriterWrapper { + wrapped: box std::io::stderr() as Box<Writer + Send>, + }); + ti.map(|t| box t as Box<Terminal<WriterWrapper> + Send>) } #[cfg(windows)] /// Return a Terminal wrapping stderr, or None if a terminal couldn't be /// opened. -pub fn stderr() -> Option<Box<Terminal<Box<Writer + Send> + Send> + Send>> { - let ti: Option<TerminfoTerminal<Box<Writer + Send>>> - = Terminal::new(box std::io::stderr() as Box<Writer + Send>); +pub fn stderr() -> Option<Box<Terminal<WriterWrapper> + Send> + Send> { + let ti: Option<TerminfoTerminal<WriterWrapper>> + = Terminal::new(WriterWrapper { + wrapped: box std::io::stderr() as Box<Writer + Send>, + }); match ti { - Some(t) => Some(box t as Box<Terminal<Box<Writer + Send> + Send> + Send>), + Some(t) => Some(box t as Box<Terminal<WriterWrapper> + Send>), None => { - let wc: Option<WinConsole<Box<Writer + Send>>> - = Terminal::new(box std::io::stderr() as Box<Writer + Send>); - wc.map(|w| box w as Box<Terminal<Box<Writer + Send> + Send> + Send>) + let wc: Option<WinConsole<WriterWrapper>> + = Terminal::new(WriterWrapper { + wrapped: box std::io::stderr() as Box<Writer + Send>, + }); + wc.map(|w| box w as Box<Terminal<WriterWrapper> + Send>) } } } |
