@@ -58,92 +58,37 @@ impl PathType {
58
58
59
59
fn get_letter_for_type ( & self ) -> String {
60
60
match self {
61
- Self :: Dir => String :: from ( format ! (
62
- "{}d{}{}" ,
63
- self . get_color_for_type( ) ,
64
- termion:: color:: Fg ( termion:: color:: Reset ) ,
65
- termion:: color:: Bg ( termion:: color:: Reset )
66
- ) ) ,
67
- Self :: Symlink => String :: from ( format ! (
68
- "{}l{}{}" ,
69
- self . get_color_for_type( ) ,
70
- termion:: color:: Fg ( termion:: color:: Reset ) ,
71
- termion:: color:: Bg ( termion:: color:: Reset )
72
- ) ) ,
73
- Self :: Pipe => String :: from ( format ! (
74
- "{}|{}{}" ,
75
- self . get_color_for_type( ) ,
76
- termion:: color:: Fg ( termion:: color:: Reset ) ,
77
- termion:: color:: Bg ( termion:: color:: Reset )
78
- ) ) ,
79
- Self :: CharD => String :: from ( format ! (
80
- "{}c{}{}" ,
81
- self . get_color_for_type( ) ,
82
- termion:: color:: Fg ( termion:: color:: Reset ) ,
83
- termion:: color:: Bg ( termion:: color:: Reset )
84
- ) ) ,
85
- Self :: BlockD => String :: from ( format ! (
86
- "{}b{}{}" ,
87
- self . get_color_for_type( ) ,
88
- termion:: color:: Fg ( termion:: color:: Reset ) ,
89
- termion:: color:: Bg ( termion:: color:: Reset )
90
- ) ) ,
91
- Self :: Socket => String :: from ( format ! (
92
- "{}s{}{}" ,
93
- self . get_color_for_type( ) ,
94
- termion:: color:: Fg ( termion:: color:: Reset ) ,
95
- termion:: color:: Bg ( termion:: color:: Reset )
96
- ) ) ,
97
- _ => String :: from ( format ! (
98
- "{}.{}{}" ,
99
- self . get_color_for_type( ) ,
100
- termion:: color:: Fg ( termion:: color:: Reset ) ,
101
- termion:: color:: Bg ( termion:: color:: Reset )
102
- ) ) ,
61
+ Self :: Dir => format ! ( "{}d{}{}" , self . get_color_for_type( ) , termion:: color:: Fg ( termion:: color:: Reset ) , termion:: color:: Bg ( termion:: color:: Reset ) ) ,
62
+ Self :: Symlink => format ! ( "{}l{}{}" , self . get_color_for_type( ) , termion:: color:: Fg ( termion:: color:: Reset ) , termion:: color:: Bg ( termion:: color:: Reset ) ) ,
63
+ Self :: Pipe => format ! ( "{}|{}{}" , self . get_color_for_type( ) , termion:: color:: Fg ( termion:: color:: Reset ) , termion:: color:: Bg ( termion:: color:: Reset ) ) ,
64
+ Self :: CharD => format ! ( "{}c{}{}" , self . get_color_for_type( ) , termion:: color:: Fg ( termion:: color:: Reset ) , termion:: color:: Bg ( termion:: color:: Reset ) ) ,
65
+ Self :: BlockD => format ! ( "{}b{}{}" , self . get_color_for_type( ) , termion:: color:: Fg ( termion:: color:: Reset ) , termion:: color:: Bg ( termion:: color:: Reset ) ) ,
66
+ Self :: Socket => format ! ( "{}s{}{}" , self . get_color_for_type( ) , termion:: color:: Fg ( termion:: color:: Reset ) , termion:: color:: Bg ( termion:: color:: Reset ) ) ,
67
+ _ => format ! ( "{}.{}{}" , self . get_color_for_type( ) , termion:: color:: Fg ( termion:: color:: Reset ) , termion:: color:: Bg ( termion:: color:: Reset ) ) ,
103
68
}
104
69
}
105
70
106
71
fn get_color_for_type ( & self ) -> String {
107
72
match self {
108
- Self :: Dir => format ! ( "{}" , termion:: color:: Fg ( termion:: color:: LightBlue ) ) ,
109
- Self :: Symlink => format ! ( "{}" , termion:: color:: Fg ( termion:: color:: LightMagenta ) ) ,
110
- Self :: Path => format ! ( "{}" , termion:: color:: Fg ( termion:: color:: White ) ) ,
111
- Self :: Pipe => format ! ( "{}" , termion:: color:: Fg ( termion:: color:: Yellow ) ) ,
112
- Self :: CharD => format ! (
113
- "{}{}" ,
114
- termion:: color:: Bg ( termion:: color:: Yellow ) ,
115
- termion:: color:: Fg ( termion:: color:: LightBlue )
116
- ) ,
117
- Self :: BlockD => format ! ( "{}" , termion:: color:: Fg ( termion:: color:: LightGreen ) ) ,
118
- Self :: Socket => format ! ( "{}" , termion:: color:: Fg ( termion:: color:: LightRed ) ) ,
73
+ Self :: Dir => format ! ( "{}" , termion:: color:: Fg ( termion:: color:: LightBlue ) ) ,
74
+ Self :: Symlink => format ! ( "{}" , termion:: color:: Fg ( termion:: color:: LightMagenta ) ) ,
75
+ Self :: Path => format ! ( "{}" , termion:: color:: Fg ( termion:: color:: White ) ) ,
76
+ Self :: Pipe => format ! ( "{}" , termion:: color:: Fg ( termion:: color:: Yellow ) ) ,
77
+ Self :: CharD => format ! ( "{}{}" , termion:: color:: Bg ( termion:: color:: Yellow ) , termion:: color:: Fg ( termion:: color:: LightBlue ) ) ,
78
+ Self :: BlockD => format ! ( "{}" , termion:: color:: Fg ( termion:: color:: LightGreen ) ) ,
79
+ Self :: Socket => format ! ( "{}" , termion:: color:: Fg ( termion:: color:: LightRed ) ) ,
119
80
}
120
81
}
121
82
122
83
fn get_text_traits_for_type ( & self , name : & str , file : & std:: path:: PathBuf ) -> String {
123
84
match self {
124
- Self :: Dir => text_effects:: bold ( & format ! (
125
- "{}{}/" ,
126
- name,
127
- termion:: color:: Fg ( termion:: color:: White )
128
- ) ) ,
129
- Self :: Symlink => text_effects:: italic ( & format ! (
130
- "{} -> {}" ,
131
- name,
132
- std:: fs:: read_link( file) . unwrap( ) . display( ) . to_string( )
133
- ) ) ,
134
- Self :: Path => text_effects:: bold ( name) ,
135
- Self :: Pipe => text_effects:: bold ( & format ! (
136
- "{}{}|" ,
137
- name,
138
- termion:: color:: Fg ( termion:: color:: White )
139
- ) ) ,
140
- Self :: CharD => text_effects:: bold ( name) ,
141
- Self :: BlockD => text_effects:: bold ( name) ,
142
- Self :: Socket => text_effects:: bold ( & format ! (
143
- "{}{}=" ,
144
- name,
145
- termion:: color:: Fg ( termion:: color:: White )
146
- ) ) ,
85
+ Self :: Dir => text_effects:: bold ( & format ! ( "{}{}/" , name, termion:: color:: Fg ( termion:: color:: White ) ) ) ,
86
+ Self :: Symlink => text_effects:: italic ( & format ! ( "{} -> {}" , name, std:: fs:: read_link( file) . unwrap( ) . display( ) . to_string( ) ) ) ,
87
+ Self :: Path => text_effects:: bold ( name) ,
88
+ Self :: Pipe => text_effects:: bold ( & format ! ( "{}{}|" , name, termion:: color:: Fg ( termion:: color:: White ) ) ) ,
89
+ Self :: CharD => text_effects:: bold ( name) ,
90
+ Self :: BlockD => text_effects:: bold ( name) ,
91
+ Self :: Socket => text_effects:: bold ( & format ! ( "{}{}=" , name, termion:: color:: Fg ( termion:: color:: White ) ) ) ,
147
92
}
148
93
}
149
94
}
@@ -308,17 +253,17 @@ impl Directory {
308
253
input:: Cli :: from_args ( ) . modified ,
309
254
input:: Cli :: from_args ( ) . size ,
310
255
] ) {
311
- DirSortType :: Name => self . self_name_sort ( ) ,
312
- DirSortType :: Created => self . self_create_sort ( ) ,
256
+ DirSortType :: Name => self . self_name_sort ( ) ,
257
+ DirSortType :: Created => self . self_create_sort ( ) ,
313
258
DirSortType :: Modified => self . self_modified_sort ( ) ,
314
- DirSortType :: Size => self . self_size_sort ( ) ,
315
- DirSortType :: Not => ( ) ,
259
+ DirSortType :: Size => self . self_size_sort ( ) ,
260
+ DirSortType :: Not => ( ) ,
316
261
}
317
262
}
318
263
319
264
fn sort ( & mut self ) {
320
265
match input:: Cli :: from_args ( ) . gdf {
321
- true => self . sort_directory_then_path ( ) ,
266
+ true => self . sort_directory_then_path ( ) ,
322
267
false => self . sort_paths ( ) ,
323
268
}
324
269
}
@@ -343,15 +288,15 @@ impl Directory {
343
288
let ghold = self . paths [ p] . group . clone ( ) ;
344
289
let uhold = self . paths [ p] . user . clone ( ) ;
345
290
let shold = self . paths [ p] . size . clone ( ) ;
346
- let mut gwidth = String :: from ( "" ) ;
291
+ let mut gwidth = String :: new ( ) ;
347
292
for _ in 0 ..( gs - ghold. len ( ) ) {
348
293
gwidth. push ( ' ' )
349
294
}
350
- let mut uwidth = String :: from ( "" ) ;
295
+ let mut uwidth = String :: new ( ) ;
351
296
for _ in 0 ..( us - uhold. len ( ) ) {
352
297
uwidth. push ( ' ' )
353
298
}
354
- let mut swidth = String :: from ( "" ) ;
299
+ let mut swidth = String :: new ( ) ;
355
300
for _ in 0 ..( ss - shold. len ( ) ) {
356
301
swidth. push ( ' ' )
357
302
}
@@ -478,9 +423,9 @@ impl std::fmt::Display for Directory {
478
423
}
479
424
480
425
fn main ( ) {
481
- let mut dir = Directory :: new ( input:: Cli :: from_args ( ) . dir ) . unwrap ( ) ;
426
+ let mut dir = Directory :: new ( input:: Cli :: from_args ( ) . dir ) . expect ( "Failed to run natls" ) ;
482
427
dir. setup ( ) ;
483
- println ! ( "{}" , dir)
428
+ println ! ( "{}" , dir) ;
484
429
}
485
430
486
431
#[ cfg( test) ]
0 commit comments