@@ -28,13 +28,13 @@ use self::parm::{expand, Number, Variables};
28
28
#[ derive( Debug ) ]
29
29
pub struct TermInfo {
30
30
/// Names for the terminal
31
- pub names : Vec < String > ,
31
+ pub names : Vec < String > ,
32
32
/// Map of capability name to boolean value
33
33
pub bools : HashMap < String , bool > ,
34
34
/// Map of capability name to numeric value
35
35
pub numbers : HashMap < String , u16 > ,
36
36
/// Map of capability name to raw (unexpanded) string
37
- pub strings : HashMap < String , Vec < u8 > >
37
+ pub strings : HashMap < String , Vec < u8 > > ,
38
38
}
39
39
40
40
pub mod searcher;
@@ -49,19 +49,19 @@ pub mod parm;
49
49
50
50
fn cap_for_attr ( attr : attr:: Attr ) -> & ' static str {
51
51
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" ,
63
63
attr:: ForegroundColor ( _) => "setaf" ,
64
- attr:: BackgroundColor ( _) => "setab"
64
+ attr:: BackgroundColor ( _) => "setab" ,
65
65
}
66
66
}
67
67
@@ -70,7 +70,7 @@ fn cap_for_attr(attr: attr::Attr) -> &'static str {
70
70
pub struct TerminfoTerminal < T > {
71
71
num_colors : u16 ,
72
72
out : T ,
73
- ti : Box < TermInfo >
73
+ ti : Box < TermInfo > ,
74
74
}
75
75
76
76
impl < T : Write +Send +' static > Terminal < T > for TerminfoTerminal < T > {
@@ -80,12 +80,12 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
80
80
let s = expand ( self . ti
81
81
. strings
82
82
. get ( "setaf" )
83
- . unwrap ( )
84
- ,
85
- & [ Number ( color as isize ) ] , & mut Variables :: new ( ) ) ;
83
+ . unwrap ( ) ,
84
+ & [ Number ( color as isize ) ] ,
85
+ & mut Variables :: new ( ) ) ;
86
86
if s. is_ok ( ) {
87
87
try!( self . out . write_all ( & s. unwrap ( ) ) ) ;
88
- return Ok ( true )
88
+ return Ok ( true ) ;
89
89
}
90
90
}
91
91
Ok ( false )
@@ -97,12 +97,12 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
97
97
let s = expand ( self . ti
98
98
. strings
99
99
. get ( "setab" )
100
- . unwrap ( )
101
- ,
102
- & [ Number ( color as isize ) ] , & mut Variables :: new ( ) ) ;
100
+ . unwrap ( ) ,
101
+ & [ Number ( color as isize ) ] ,
102
+ & mut Variables :: new ( ) ) ;
103
103
if s. is_ok ( ) {
104
104
try!( self . out . write_all ( & s. unwrap ( ) ) ) ;
105
- return Ok ( true )
105
+ return Ok ( true ) ;
106
106
}
107
107
}
108
108
Ok ( false )
@@ -116,12 +116,10 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
116
116
let cap = cap_for_attr ( attr) ;
117
117
let parm = self . ti . strings . get ( cap) ;
118
118
if parm. is_some ( ) {
119
- let s = expand ( parm. unwrap ( ) ,
120
- & [ ] ,
121
- & mut Variables :: new ( ) ) ;
119
+ let s = expand ( parm. unwrap ( ) , & [ ] , & mut Variables :: new ( ) ) ;
122
120
if s. is_ok ( ) {
123
121
try!( self . out . write_all ( & s. unwrap ( ) ) ) ;
124
- return Ok ( true )
122
+ return Ok ( true ) ;
125
123
}
126
124
}
127
125
Ok ( false )
@@ -131,9 +129,7 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
131
129
132
130
fn supports_attr ( & self , attr : attr:: Attr ) -> bool {
133
131
match attr {
134
- attr:: ForegroundColor ( _) | attr:: BackgroundColor ( _) => {
135
- self . num_colors > 0
136
- }
132
+ attr:: ForegroundColor ( _) | attr:: BackgroundColor ( _) => self . num_colors > 0 ,
137
133
_ => {
138
134
let cap = cap_for_attr ( attr) ;
139
135
self . ti . strings . get ( cap) . is_some ( )
@@ -151,28 +147,33 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
151
147
cap = self . ti . strings . get ( "op" ) ;
152
148
}
153
149
}
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 ( ) ) ) ;
157
152
if s. is_ok ( ) {
158
- return self . out . write_all ( & s. unwrap ( ) )
153
+ return self . out . write_all ( & s. unwrap ( ) ) ;
159
154
}
160
155
Ok ( ( ) )
161
156
}
162
157
163
- fn get_ref < ' a > ( & ' a self ) -> & ' a T { & self . out }
158
+ fn get_ref < ' a > ( & ' a self ) -> & ' a T {
159
+ & self . out
160
+ }
164
161
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
+ }
166
165
}
167
166
168
167
impl < 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
+ }
170
171
}
171
172
172
173
impl < T : Write +Send +' static > TerminfoTerminal < T > {
173
174
/// Returns `None` whenever the terminal cannot be created for some
174
175
/// 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 > > {
176
177
let term = match env:: var ( "TERM" ) {
177
178
Ok ( t) => t,
178
179
Err ( ..) => {
@@ -183,20 +184,22 @@ impl<T: Write+Send+'static> TerminfoTerminal<T> {
183
184
184
185
let mut file = match open ( & term[ ..] ) {
185
186
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
+ }
200
203
} ;
201
204
202
205
let ti = parse ( & mut file, false ) ;
@@ -206,20 +209,25 @@ impl<T: Write+Send+'static> TerminfoTerminal<T> {
206
209
}
207
210
208
211
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
+ } )
217
223
}
218
224
219
225
fn dim_if_necessary ( & self , color : color:: Color ) -> color:: Color {
220
226
if color >= self . num_colors && color >= 8 && color < 16 {
221
- color-8
222
- } else { color }
227
+ color - 8
228
+ } else {
229
+ color
230
+ }
223
231
}
224
232
}
225
233
0 commit comments