@@ -19,13 +19,19 @@ const ANSI_RESET: &str = "\x1b[0m";
1919const ANSI_CLEAR_EOL : & str = "\x1b [K" ;
2020const EMPTY_STYLE : & str = "\x1b [m" ;
2121
22- // Unix file mode bits
23- const MODE_SETUID : u32 = 0o4000 ;
24- const MODE_SETGID : u32 = 0o2000 ;
25- const MODE_EXECUTABLE : u32 = 0o0111 ;
26- const MODE_STICKY_OTHER_WRITABLE : u32 = 0o1002 ;
27- const MODE_OTHER_WRITABLE : u32 = 0o0002 ;
28- const MODE_STICKY : u32 = 0o1000 ;
22+ #[ cfg( unix) ]
23+ mod unix_mode_bits {
24+ // Unix file mode bits
25+ pub const MODE_SETUID : u32 = 0o4000 ;
26+ pub const MODE_SETGID : u32 = 0o2000 ;
27+ pub const MODE_EXECUTABLE : u32 = 0o0111 ;
28+ pub const MODE_STICKY_OTHER_WRITABLE : u32 = 0o1002 ;
29+ pub const MODE_OTHER_WRITABLE : u32 = 0o0002 ;
30+ pub const MODE_STICKY : u32 = 0o1000 ;
31+ }
32+
33+ #[ cfg( unix) ]
34+ use unix_mode_bits:: * ;
2935
3036enum RawIndicatorStyle {
3137 Empty ,
@@ -403,8 +409,8 @@ impl<'a> StyleManager<'a> {
403409 None
404410 }
405411
412+ #[ cfg( unix) ]
406413 fn indicator_for_file ( & self , path : & PathData ) -> Option < Indicator > {
407- #[ cfg( unix) ]
408414 if self . needs_file_metadata ( ) {
409415 if let Some ( metadata) = path. metadata ( ) {
410416 let mode = metadata. mode ( ) ;
@@ -432,8 +438,17 @@ impl<'a> StyleManager<'a> {
432438 }
433439 }
434440
441+ #[ cfg( not( unix) ) ]
442+ fn indicator_for_file ( & self , _path : & PathData ) -> Option < Indicator > {
443+ if self . has_indicator_style ( Indicator :: RegularFile ) {
444+ Some ( Indicator :: RegularFile )
445+ } else {
446+ None
447+ }
448+ }
449+
450+ #[ cfg( unix) ]
435451 fn indicator_for_directory ( & self , path : & PathData ) -> Option < Indicator > {
436- #[ cfg( unix) ]
437452 if self . needs_dir_metadata ( ) {
438453 if let Some ( metadata) = path. metadata ( ) {
439454 let mode = metadata. mode ( ) ;
@@ -460,22 +475,34 @@ impl<'a> StyleManager<'a> {
460475 }
461476 }
462477
478+ #[ cfg( not( unix) ) ]
479+ fn indicator_for_directory ( & self , _path : & PathData ) -> Option < Indicator > {
480+ if self . has_indicator_style ( Indicator :: Directory ) {
481+ Some ( Indicator :: Directory )
482+ } else {
483+ None
484+ }
485+ }
486+
487+ #[ cfg( unix) ]
463488 fn indicator_for_special_file ( & self , file_type : & std:: fs:: FileType ) -> Option < Indicator > {
464- #[ cfg( unix) ]
465- {
466- if file_type. is_fifo ( ) && self . has_indicator_style ( Indicator :: FIFO ) {
467- return Some ( Indicator :: FIFO ) ;
468- }
469- if file_type. is_socket ( ) && self . has_indicator_style ( Indicator :: Socket ) {
470- return Some ( Indicator :: Socket ) ;
471- }
472- if file_type. is_block_device ( ) && self . has_indicator_style ( Indicator :: BlockDevice ) {
473- return Some ( Indicator :: BlockDevice ) ;
474- }
475- if file_type. is_char_device ( ) && self . has_indicator_style ( Indicator :: CharacterDevice ) {
476- return Some ( Indicator :: CharacterDevice ) ;
477- }
489+ if file_type. is_fifo ( ) && self . has_indicator_style ( Indicator :: FIFO ) {
490+ return Some ( Indicator :: FIFO ) ;
491+ }
492+ if file_type. is_socket ( ) && self . has_indicator_style ( Indicator :: Socket ) {
493+ return Some ( Indicator :: Socket ) ;
494+ }
495+ if file_type. is_block_device ( ) && self . has_indicator_style ( Indicator :: BlockDevice ) {
496+ return Some ( Indicator :: BlockDevice ) ;
478497 }
498+ if file_type. is_char_device ( ) && self . has_indicator_style ( Indicator :: CharacterDevice ) {
499+ return Some ( Indicator :: CharacterDevice ) ;
500+ }
501+ None
502+ }
503+
504+ #[ cfg( not( unix) ) ]
505+ fn indicator_for_special_file ( & self , _file_type : & std:: fs:: FileType ) -> Option < Indicator > {
479506 None
480507 }
481508
0 commit comments