@@ -28,13 +28,13 @@ use self::parm::{expand, Number, Variables};
2828#[ derive( Debug ) ]
2929pub struct TermInfo {
3030 /// Names for the terminal
31- pub names : Vec < String > ,
31+ pub names : Vec < String > ,
3232 /// Map of capability name to boolean value
3333 pub bools : HashMap < String , bool > ,
3434 /// Map of capability name to numeric value
3535 pub numbers : HashMap < String , u16 > ,
3636 /// Map of capability name to raw (unexpanded) string
37- pub strings : HashMap < String , Vec < u8 > >
37+ pub strings : HashMap < String , Vec < u8 > > ,
3838}
3939
4040pub mod searcher;
@@ -49,19 +49,19 @@ pub mod parm;
4949
5050fn cap_for_attr ( attr : attr:: Attr ) -> & ' static str {
5151 match attr {
52- attr:: Bold => "bold" ,
53- attr:: Dim => "dim" ,
54- attr:: Italic ( true ) => "sitm" ,
55- attr:: Italic ( false ) => "ritm" ,
56- attr:: Underline ( true ) => "smul" ,
57- attr:: Underline ( false ) => "rmul" ,
58- attr:: Blink => "blink" ,
59- attr:: Standout ( true ) => "smso" ,
60- attr:: Standout ( false ) => "rmso" ,
61- attr:: Reverse => "rev" ,
62- attr:: Secure => "invis" ,
52+ attr:: Bold => "bold" ,
53+ attr:: Dim => "dim" ,
54+ attr:: Italic ( true ) => "sitm" ,
55+ attr:: Italic ( false ) => "ritm" ,
56+ attr:: Underline ( true ) => "smul" ,
57+ attr:: Underline ( false ) => "rmul" ,
58+ attr:: Blink => "blink" ,
59+ attr:: Standout ( true ) => "smso" ,
60+ attr:: Standout ( false ) => "rmso" ,
61+ attr:: Reverse => "rev" ,
62+ attr:: Secure => "invis" ,
6363 attr:: ForegroundColor ( _) => "setaf" ,
64- attr:: BackgroundColor ( _) => "setab"
64+ attr:: BackgroundColor ( _) => "setab" ,
6565 }
6666}
6767
@@ -70,7 +70,7 @@ fn cap_for_attr(attr: attr::Attr) -> &'static str {
7070pub struct TerminfoTerminal < T > {
7171 num_colors : u16 ,
7272 out : T ,
73- ti : Box < TermInfo >
73+ ti : Box < TermInfo > ,
7474}
7575
7676impl < T : Write +Send +' static > Terminal < T > for TerminfoTerminal < T > {
@@ -80,12 +80,12 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
8080 let s = expand ( self . ti
8181 . strings
8282 . get ( "setaf" )
83- . unwrap ( )
84- ,
85- & [ Number ( color as isize ) ] , & mut Variables :: new ( ) ) ;
83+ . unwrap ( ) ,
84+ & [ Number ( color as isize ) ] ,
85+ & mut Variables :: new ( ) ) ;
8686 if s. is_ok ( ) {
8787 try!( self . out . write_all ( & s. unwrap ( ) ) ) ;
88- return Ok ( true )
88+ return Ok ( true ) ;
8989 }
9090 }
9191 Ok ( false )
@@ -97,12 +97,12 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
9797 let s = expand ( self . ti
9898 . strings
9999 . get ( "setab" )
100- . unwrap ( )
101- ,
102- & [ Number ( color as isize ) ] , & mut Variables :: new ( ) ) ;
100+ . unwrap ( ) ,
101+ & [ Number ( color as isize ) ] ,
102+ & mut Variables :: new ( ) ) ;
103103 if s. is_ok ( ) {
104104 try!( self . out . write_all ( & s. unwrap ( ) ) ) ;
105- return Ok ( true )
105+ return Ok ( true ) ;
106106 }
107107 }
108108 Ok ( false )
@@ -116,12 +116,10 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
116116 let cap = cap_for_attr ( attr) ;
117117 let parm = self . ti . strings . get ( cap) ;
118118 if parm. is_some ( ) {
119- let s = expand ( parm. unwrap ( ) ,
120- & [ ] ,
121- & mut Variables :: new ( ) ) ;
119+ let s = expand ( parm. unwrap ( ) , & [ ] , & mut Variables :: new ( ) ) ;
122120 if s. is_ok ( ) {
123121 try!( self . out . write_all ( & s. unwrap ( ) ) ) ;
124- return Ok ( true )
122+ return Ok ( true ) ;
125123 }
126124 }
127125 Ok ( false )
@@ -131,9 +129,7 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
131129
132130 fn supports_attr ( & self , attr : attr:: Attr ) -> bool {
133131 match attr {
134- attr:: ForegroundColor ( _) | attr:: BackgroundColor ( _) => {
135- self . num_colors > 0
136- }
132+ attr:: ForegroundColor ( _) | attr:: BackgroundColor ( _) => self . num_colors > 0 ,
137133 _ => {
138134 let cap = cap_for_attr ( attr) ;
139135 self . ti . strings . get ( cap) . is_some ( )
@@ -151,28 +147,33 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
151147 cap = self . ti . strings . get ( "op" ) ;
152148 }
153149 }
154- let s = cap. map_or ( Err ( "can't find terminfo capability `sgr0`" . to_owned ( ) ) , |op| {
155- expand ( op, & [ ] , & mut Variables :: new ( ) )
156- } ) ;
150+ let s = cap. map_or ( Err ( "can't find terminfo capability `sgr0`" . to_owned ( ) ) ,
151+ |op| expand ( op, & [ ] , & mut Variables :: new ( ) ) ) ;
157152 if s. is_ok ( ) {
158- return self . out . write_all ( & s. unwrap ( ) )
153+ return self . out . write_all ( & s. unwrap ( ) ) ;
159154 }
160155 Ok ( ( ) )
161156 }
162157
163- fn get_ref < ' a > ( & ' a self ) -> & ' a T { & self . out }
158+ fn get_ref < ' a > ( & ' a self ) -> & ' a T {
159+ & self . out
160+ }
164161
165- fn get_mut < ' a > ( & ' a mut self ) -> & ' a mut T { & mut self . out }
162+ fn get_mut < ' a > ( & ' a mut self ) -> & ' a mut T {
163+ & mut self . out
164+ }
166165}
167166
168167impl < T : Write +Send +' static > UnwrappableTerminal < T > for TerminfoTerminal < T > {
169- fn unwrap ( self ) -> T { self . out }
168+ fn unwrap ( self ) -> T {
169+ self . out
170+ }
170171}
171172
172173impl < T : Write +Send +' static > TerminfoTerminal < T > {
173174 /// Returns `None` whenever the terminal cannot be created for some
174175 /// reason.
175- pub fn new ( out : T ) -> Option < Box < Terminal < T > + Send + ' static > > {
176+ pub fn new ( out : T ) -> Option < Box < Terminal < T > + Send + ' static > > {
176177 let term = match env:: var ( "TERM" ) {
177178 Ok ( t) => t,
178179 Err ( ..) => {
@@ -183,20 +184,22 @@ impl<T: Write+Send+'static> TerminfoTerminal<T> {
183184
184185 let mut file = match open ( & term[ ..] ) {
185186 Ok ( f) => f,
186- Err ( err) => return match env:: var ( "MSYSCON" ) {
187- Ok ( ref val) if & val[ ..] == "mintty.exe" => {
188- // msys terminal
189- Some ( box TerminfoTerminal {
190- out : out,
191- ti : msys_terminfo ( ) ,
192- num_colors : 8 ,
193- } )
194- } ,
195- _ => {
196- debug ! ( "error finding terminfo entry: {:?}" , err) ;
197- None
198- } ,
199- } ,
187+ Err ( err) => {
188+ return match env:: var ( "MSYSCON" ) {
189+ Ok ( ref val) if & val[ ..] == "mintty.exe" => {
190+ // msys terminal
191+ Some ( box TerminfoTerminal {
192+ out : out,
193+ ti : msys_terminfo ( ) ,
194+ num_colors : 8 ,
195+ } )
196+ }
197+ _ => {
198+ debug ! ( "error finding terminfo entry: {:?}" , err) ;
199+ None
200+ }
201+ } ;
202+ }
200203 } ;
201204
202205 let ti = parse ( & mut file, false ) ;
@@ -206,20 +209,25 @@ impl<T: Write+Send+'static> TerminfoTerminal<T> {
206209 }
207210
208211 let inf = ti. unwrap ( ) ;
209- let nc = if inf. strings . get ( "setaf" ) . is_some ( )
210- && inf. strings . get ( "setab" ) . is_some ( ) {
211- inf. numbers . get ( "colors" ) . map_or ( 0 , |& n| n)
212- } else { 0 } ;
213-
214- Some ( box TerminfoTerminal { out : out,
215- ti : inf,
216- num_colors : nc} )
212+ let nc = if inf. strings . get ( "setaf" ) . is_some ( ) && inf. strings . get ( "setab" ) . is_some ( ) {
213+ inf. numbers . get ( "colors" ) . map_or ( 0 , |& n| n)
214+ } else {
215+ 0
216+ } ;
217+
218+ Some ( box TerminfoTerminal {
219+ out : out,
220+ ti : inf,
221+ num_colors : nc,
222+ } )
217223 }
218224
219225 fn dim_if_necessary ( & self , color : color:: Color ) -> color:: Color {
220226 if color >= self . num_colors && color >= 8 && color < 16 {
221- color-8
222- } else { color }
227+ color - 8
228+ } else {
229+ color
230+ }
223231 }
224232}
225233
0 commit comments