@@ -170,40 +170,33 @@ impl Browser {
170
170
171
171
/// Get directory content preview window as a vector of strings
172
172
fn get_preview ( & self ) -> Vec < String > {
173
- let mut ret : Vec < String > = Vec :: new ( ) ;
173
+ let empty : Vec < String > = Vec :: new ( ) ;
174
174
175
175
if self . current_dir . len ( ) == 0 {
176
- return ret ;
176
+ return empty ;
177
177
}
178
178
179
- let mut dir_under_cursor = self . current_path . clone ( ) ;
180
- dir_under_cursor. push ( & self . current_dir [ self . cursor ] ) ;
181
-
182
- if dir_under_cursor. is_dir ( ) == false {
183
- return ret;
179
+ let mut _dir = self . current_path . clone ( ) ;
180
+ _dir. push ( & self . current_dir [ self . cursor ] ) ;
181
+ if _dir. is_dir ( ) == false {
182
+ return empty;
184
183
}
185
184
186
- if let Ok ( entries) = read_dir ( & dir_under_cursor) {
187
- for entry in entries {
188
- let entry = entry. expect ( & format ! (
189
- "Failed to interate through {}" ,
190
- dir_under_cursor. to_str( ) . unwrap( )
191
- ) ) ;
192
-
193
- let s = entry. file_name ( ) . into_string ( ) ;
194
-
195
- match s {
196
- Ok ( v) => {
197
- ret. push ( v) ;
198
- }
199
- Err ( _) => {
200
- let str = entry. file_name ( ) . to_string_lossy ( ) . into_owned ( ) ;
201
- ret. push ( str) ;
202
- }
203
- }
204
- }
205
- }
206
- ret
185
+ let dir = _dir. to_str ( ) . expect ( "Failed to construct preview path" ) ;
186
+
187
+ let mut preview = read_dir ( & dir)
188
+ . expect ( & format ! ( "Failed to read files from {}" , dir) )
189
+ . map ( |e| {
190
+ e. expect ( "Failed to get preview entry" )
191
+ . file_name ( )
192
+ . into_string ( )
193
+ . expect ( "Failed to get preview file name" )
194
+ } )
195
+ . collect :: < Vec < String > > ( ) ;
196
+
197
+ preview. sort_by ( |d1, d2| d1. to_lowercase ( ) . cmp ( & d2. to_lowercase ( ) ) ) ;
198
+
199
+ preview
207
200
}
208
201
209
202
/// Set cursor position, centered in the window
@@ -452,7 +445,7 @@ impl Browser {
452
445
/// Read the file and directory names in the current directory
453
446
fn read_current_dir ( & mut self , path : & String ) {
454
447
self . current_dir = read_dir ( path)
455
- . expect ( & format ! ( "Read files from {} failed " , path) )
448
+ . expect ( & format ! ( "Failed to read files from {}" , path) )
456
449
. map ( |_e| {
457
450
let e = _e. expect ( & format ! ( "Failed to read a file from {}" , path) ) ;
458
451
match e. file_name ( ) . into_string ( ) {
@@ -462,7 +455,8 @@ impl Browser {
462
455
} )
463
456
. collect :: < Vec < String > > ( ) ;
464
457
465
- self . current_dir . sort_by ( |d1, d2| d1. to_lowercase ( ) . cmp ( & d2. to_lowercase ( ) ) ) ;
458
+ self . current_dir
459
+ . sort_by ( |d1, d2| d1. to_lowercase ( ) . cmp ( & d2. to_lowercase ( ) ) ) ;
466
460
}
467
461
468
462
/// Goto the directory in the left side window, while quitting trans
0 commit comments