@@ -66,54 +66,84 @@ pub mod terminfo;
6666#[ cfg( windows) ]
6767mod win;
6868
69+ /// A hack to work around the fact that `Box<Writer + Send>` does not
70+ /// currently implement `Writer`.
71+ pub struct WriterWrapper {
72+ wrapped : Box < Writer + Send > ,
73+ }
74+
75+ impl Writer for WriterWrapper {
76+ #[ inline]
77+ fn write ( & mut self , buf : & [ u8 ] ) -> IoResult < ( ) > {
78+ self . wrapped . write ( buf)
79+ }
80+
81+ #[ inline]
82+ fn flush ( & mut self ) -> IoResult < ( ) > {
83+ self . wrapped . flush ( )
84+ }
85+ }
86+
6987#[ cfg( not( windows) ) ]
7088/// Return a Terminal wrapping stdout, or None if a terminal couldn't be
7189/// opened.
72- pub fn stdout ( ) -> Option < Box < Terminal < Box < Writer + Send > > + Send > > {
73- let ti: Option < TerminfoTerminal < Box < Writer + Send > > >
74- = Terminal :: new ( box std:: io:: stdout ( ) as Box < Writer + Send > ) ;
75- ti. map ( |t| box t as Box < Terminal < Box < Writer + Send > + Send > + Send > )
90+ pub fn stdout ( ) -> Option < Box < Terminal < WriterWrapper > + Send > > {
91+ let ti: Option < TerminfoTerminal < WriterWrapper > >
92+ = Terminal :: new ( WriterWrapper {
93+ wrapped : box std:: io:: stdout ( ) as Box < Writer + Send > ,
94+ } ) ;
95+ ti. map ( |t| box t as Box < Terminal < WriterWrapper > + Send > )
7696}
7797
7898#[ cfg( windows) ]
7999/// Return a Terminal wrapping stdout, or None if a terminal couldn't be
80100/// opened.
81- pub fn stdout ( ) -> Option < Box < Terminal < Box < Writer + Send > + Send > + Send > > {
82- let ti: Option < TerminfoTerminal < Box < Writer + Send > > >
83- = Terminal :: new ( box std:: io:: stdout ( ) as Box < Writer + Send > ) ;
101+ pub fn stdout ( ) -> Option < Box < Terminal < WriterWrapper > + Send > > {
102+ let ti: Option < TerminfoTerminal < WriterWrapper > >
103+ = Terminal :: new ( WriterWrapper {
104+ wrapped : box std:: io:: stdout ( ) as Box < Writer + Send > ,
105+ } ) ;
84106
85107 match ti {
86- Some ( t) => Some ( box t as Box < Terminal < Box < Writer + Send > + Send > + Send > ) ,
108+ Some ( t) => Some ( box t as Box < Terminal < WriterWrapper > + Send > ) ,
87109 None => {
88- let wc: Option < WinConsole < Box < Writer + Send > > >
89- = Terminal :: new ( box std:: io:: stdout ( ) as Box < Writer + Send > ) ;
90- wc. map ( |w| box w as Box < Terminal < Box < Writer + Send > + Send > + Send > )
110+ let wc: Option < WinConsole < WriterWrapper > >
111+ = Terminal :: new ( WriterWrapper {
112+ wrapped : box std:: io:: stdout ( ) as Box < Writer + Send > ,
113+ } ) ;
114+ wc. map ( |w| box w as Box < Terminal < WriterWrapper > + Send > )
91115 }
92116 }
93117}
94118
95119#[ cfg( not( windows) ) ]
96120/// Return a Terminal wrapping stderr, or None if a terminal couldn't be
97121/// opened.
98- pub fn stderr ( ) -> Option < Box < Terminal < Box < Writer + Send > + Send > + Send > + Send > {
99- let ti: Option < TerminfoTerminal < Box < Writer + Send > > >
100- = Terminal :: new ( box std:: io:: stderr ( ) as Box < Writer + Send > ) ;
101- ti. map ( |t| box t as Box < Terminal < Box < Writer + Send > + Send > + Send > )
122+ pub fn stderr ( ) -> Option < Box < Terminal < WriterWrapper > + Send > + Send > {
123+ let ti: Option < TerminfoTerminal < WriterWrapper > >
124+ = Terminal :: new ( WriterWrapper {
125+ wrapped : box std:: io:: stderr ( ) as Box < Writer + Send > ,
126+ } ) ;
127+ ti. map ( |t| box t as Box < Terminal < WriterWrapper > + Send > )
102128}
103129
104130#[ cfg( windows) ]
105131/// Return a Terminal wrapping stderr, or None if a terminal couldn't be
106132/// opened.
107- pub fn stderr ( ) -> Option < Box < Terminal < Box < Writer + Send > + Send > + Send > > {
108- let ti: Option < TerminfoTerminal < Box < Writer + Send > > >
109- = Terminal :: new ( box std:: io:: stderr ( ) as Box < Writer + Send > ) ;
133+ pub fn stderr ( ) -> Option < Box < Terminal < WriterWrapper > + Send > + Send > {
134+ let ti: Option < TerminfoTerminal < WriterWrapper > >
135+ = Terminal :: new ( WriterWrapper {
136+ wrapped : box std:: io:: stderr ( ) as Box < Writer + Send > ,
137+ } ) ;
110138
111139 match ti {
112- Some ( t) => Some ( box t as Box < Terminal < Box < Writer + Send > + Send > + Send > ) ,
140+ Some ( t) => Some ( box t as Box < Terminal < WriterWrapper > + Send > ) ,
113141 None => {
114- let wc: Option < WinConsole < Box < Writer + Send > > >
115- = Terminal :: new ( box std:: io:: stderr ( ) as Box < Writer + Send > ) ;
116- wc. map ( |w| box w as Box < Terminal < Box < Writer + Send > + Send > + Send > )
142+ let wc: Option < WinConsole < WriterWrapper > >
143+ = Terminal :: new ( WriterWrapper {
144+ wrapped : box std:: io:: stderr ( ) as Box < Writer + Send > ,
145+ } ) ;
146+ wc. map ( |w| box w as Box < Terminal < WriterWrapper > + Send > )
117147 }
118148 }
119149}
0 commit comments