@@ -10,7 +10,6 @@ use crate::style::lsc::Pair;
10
10
#[ derive( Debug , Default , PartialEq ) ]
11
11
pub struct Colours {
12
12
pub colourful : bool ,
13
- pub scale : bool ,
14
13
15
14
pub filekinds : FileKinds ,
16
15
pub perms : Permissions ,
@@ -67,17 +66,20 @@ pub struct Permissions {
67
66
68
67
#[ derive( Clone , Copy , Debug , Default , PartialEq ) ]
69
68
pub struct Size {
70
- pub numbers : Style ,
71
- pub unit : Style ,
72
-
73
69
pub major : Style ,
74
70
pub minor : Style ,
75
71
76
- pub scale_byte : Style ,
77
- pub scale_kilo : Style ,
78
- pub scale_mega : Style ,
79
- pub scale_giga : Style ,
80
- pub scale_huge : Style ,
72
+ pub number_byte : Style ,
73
+ pub number_kilo : Style ,
74
+ pub number_mega : Style ,
75
+ pub number_giga : Style ,
76
+ pub number_huge : Style ,
77
+
78
+ pub unit_byte : Style ,
79
+ pub unit_kilo : Style ,
80
+ pub unit_mega : Style ,
81
+ pub unit_giga : Style ,
82
+ pub unit_huge : Style ,
81
83
}
82
84
83
85
#[ derive( Clone , Copy , Debug , Default , PartialEq ) ]
@@ -112,7 +114,6 @@ impl Colours {
112
114
pub fn colourful ( scale : bool ) -> Colours {
113
115
Colours {
114
116
colourful : true ,
115
- scale,
116
117
117
118
filekinds : FileKinds {
118
119
normal : Style :: default ( ) ,
@@ -146,19 +147,7 @@ impl Colours {
146
147
attribute : Style :: default ( ) ,
147
148
} ,
148
149
149
- size : Size {
150
- numbers : Green . bold ( ) ,
151
- unit : Green . normal ( ) ,
152
-
153
- major : Green . bold ( ) ,
154
- minor : Green . normal ( ) ,
155
-
156
- scale_byte : Fixed ( 118 ) . normal ( ) ,
157
- scale_kilo : Fixed ( 190 ) . normal ( ) ,
158
- scale_mega : Fixed ( 226 ) . normal ( ) ,
159
- scale_giga : Fixed ( 220 ) . normal ( ) ,
160
- scale_huge : Fixed ( 214 ) . normal ( ) ,
161
- } ,
150
+ size : Size :: colourful ( scale) ,
162
151
163
152
users : Users {
164
153
user_you : Yellow . bold ( ) ,
@@ -195,6 +184,55 @@ impl Colours {
195
184
}
196
185
}
197
186
187
+ impl Size {
188
+ pub fn colourful ( scale : bool ) -> Self {
189
+ if scale {
190
+ Self :: colourful_scale ( )
191
+ } else {
192
+ Self :: colourful_plain ( )
193
+ }
194
+ }
195
+
196
+ fn colourful_plain ( ) -> Self {
197
+ Self {
198
+ major : Green . bold ( ) ,
199
+ minor : Green . normal ( ) ,
200
+
201
+ number_byte : Green . bold ( ) ,
202
+ number_kilo : Green . bold ( ) ,
203
+ number_mega : Green . bold ( ) ,
204
+ number_giga : Green . bold ( ) ,
205
+ number_huge : Green . bold ( ) ,
206
+
207
+ unit_byte : Green . normal ( ) ,
208
+ unit_kilo : Green . normal ( ) ,
209
+ unit_mega : Green . normal ( ) ,
210
+ unit_giga : Green . normal ( ) ,
211
+ unit_huge : Green . normal ( ) ,
212
+ }
213
+ }
214
+
215
+ fn colourful_scale ( ) -> Self {
216
+ Self {
217
+ major : Green . bold ( ) ,
218
+ minor : Green . normal ( ) ,
219
+
220
+ number_byte : Fixed ( 118 ) . normal ( ) ,
221
+ number_kilo : Fixed ( 190 ) . normal ( ) ,
222
+ number_mega : Fixed ( 226 ) . normal ( ) ,
223
+ number_giga : Fixed ( 220 ) . normal ( ) ,
224
+ number_huge : Fixed ( 214 ) . normal ( ) ,
225
+
226
+ unit_byte : Green . normal ( ) ,
227
+ unit_kilo : Green . normal ( ) ,
228
+ unit_mega : Green . normal ( ) ,
229
+ unit_giga : Green . normal ( ) ,
230
+ unit_huge : Green . normal ( ) ,
231
+ }
232
+
233
+ }
234
+ }
235
+
198
236
199
237
/// Some of the styles are **overlays**: although they have the same attribute
200
238
/// set as regular styles (foreground and background colours, bold, underline,
@@ -270,8 +308,18 @@ impl Colours {
270
308
"sf" => self . perms . special_other = pair. to_style ( ) ,
271
309
"xa" => self . perms . attribute = pair. to_style ( ) ,
272
310
273
- "sn" => self . size . numbers = pair. to_style ( ) ,
274
- "sb" => self . size . unit = pair. to_style ( ) ,
311
+ "sn" => self . set_number_style ( pair. to_style ( ) ) ,
312
+ "sb" => self . set_unit_style ( pair. to_style ( ) ) ,
313
+ "nb" => self . size . number_byte = pair. to_style ( ) ,
314
+ "nk" => self . size . number_kilo = pair. to_style ( ) ,
315
+ "nm" => self . size . number_mega = pair. to_style ( ) ,
316
+ "ng" => self . size . number_giga = pair. to_style ( ) ,
317
+ "nh" => self . size . number_huge = pair. to_style ( ) ,
318
+ "ub" => self . size . unit_byte = pair. to_style ( ) ,
319
+ "uk" => self . size . unit_kilo = pair. to_style ( ) ,
320
+ "um" => self . size . unit_mega = pair. to_style ( ) ,
321
+ "ug" => self . size . unit_giga = pair. to_style ( ) ,
322
+ "uh" => self . size . unit_huge = pair. to_style ( ) ,
275
323
"df" => self . size . major = pair. to_style ( ) ,
276
324
"ds" => self . size . minor = pair. to_style ( ) ,
277
325
@@ -302,6 +350,22 @@ impl Colours {
302
350
}
303
351
true
304
352
}
353
+
354
+ pub fn set_number_style ( & mut self , style : Style ) {
355
+ self . size . number_byte = style;
356
+ self . size . number_kilo = style;
357
+ self . size . number_mega = style;
358
+ self . size . number_giga = style;
359
+ self . size . number_huge = style;
360
+ }
361
+
362
+ pub fn set_unit_style ( & mut self , style : Style ) {
363
+ self . size . unit_byte = style;
364
+ self . size . unit_kilo = style;
365
+ self . size . unit_mega = style;
366
+ self . size . unit_giga = style;
367
+ self . size . unit_huge = style;
368
+ }
305
369
}
306
370
307
371
@@ -360,30 +424,28 @@ impl render::PermissionsColours for Colours {
360
424
}
361
425
362
426
impl render:: SizeColours for Colours {
363
- fn size ( & self , size : u64 ) -> Style {
364
- if self . scale {
365
- if size < 1024 {
366
- self . size . scale_byte
367
- }
368
- else if size < 1024 * 1024 {
369
- self . size . scale_kilo
370
- }
371
- else if size < 1024 * 1024 * 1024 {
372
- self . size . scale_mega
373
- }
374
- else if size < 1024 * 1024 * 1024 * 1024 {
375
- self . size . scale_giga
376
- }
377
- else {
378
- self . size . scale_huge
379
- }
427
+ fn size ( & self , prefix : Option < number_prefix:: Prefix > ) -> Style {
428
+ use number_prefix:: Prefix :: * ;
429
+ match prefix {
430
+ None => self . size . number_byte ,
431
+ Some ( Kilo ) | Some ( Kibi ) => self . size . number_kilo ,
432
+ Some ( Mega ) | Some ( Mibi ) => self . size . number_mega ,
433
+ Some ( Giga ) | Some ( Gibi ) => self . size . number_giga ,
434
+ Some ( _) => self . size . number_huge ,
380
435
}
381
- else {
382
- self . size . numbers
436
+ }
437
+
438
+ fn unit ( & self , prefix : Option < number_prefix:: Prefix > ) -> Style {
439
+ use number_prefix:: Prefix :: * ;
440
+ match prefix {
441
+ None => self . size . unit_byte ,
442
+ Some ( Kilo ) | Some ( Kibi ) => self . size . unit_kilo ,
443
+ Some ( Mega ) | Some ( Mibi ) => self . size . unit_mega ,
444
+ Some ( Giga ) | Some ( Gibi ) => self . size . unit_giga ,
445
+ Some ( _) => self . size . unit_huge ,
383
446
}
384
447
}
385
448
386
- fn unit ( & self ) -> Style { self . size . unit }
387
449
fn no_size ( & self ) -> Style { self . punctuation }
388
450
fn major ( & self ) -> Style { self . size . major }
389
451
fn comma ( & self ) -> Style { self . punctuation }
0 commit comments