@@ -19,13 +19,16 @@ 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 mode {
24+ // Unix file mode bits
25+ pub const SETUID : u32 = 0o4000 ;
26+ pub const SETGID : u32 = 0o2000 ;
27+ pub const EXECUTABLE : u32 = 0o0111 ;
28+ pub const STICKY_OTHER_WRITABLE : u32 = 0o1002 ;
29+ pub const OTHER_WRITABLE : u32 = 0o0002 ;
30+ pub const STICKY : u32 = 0o1000 ;
31+ }
2932
3033enum RawIndicatorStyle {
3134 Empty ,
@@ -361,7 +364,7 @@ impl<'a> StyleManager<'a> {
361364 } ;
362365
363366 if file_type. is_symlink ( ) {
364- return self . indicator_for_symlink ( path , & mut entry_exists) ;
367+ return self . indicator_for_symlink ( & mut entry_exists) ;
365368 }
366369
367370 if self . has_indicator_style ( Indicator :: MissingFile ) && !entry_exists ( ) {
@@ -377,11 +380,7 @@ impl<'a> StyleManager<'a> {
377380 }
378381 }
379382
380- fn indicator_for_symlink (
381- & self ,
382- _path : & PathData ,
383- entry_exists : & mut dyn FnMut ( ) -> bool ,
384- ) -> Option < Indicator > {
383+ fn indicator_for_symlink ( & self , entry_exists : & mut dyn FnMut ( ) -> bool ) -> Option < Indicator > {
385384 let orphan_enabled = self . has_indicator_style ( Indicator :: OrphanedSymbolicLink ) ;
386385 let missing_enabled = self . has_indicator_style ( Indicator :: MissingFile ) ;
387386 let needs_target_state = self . ln_color_from_target || orphan_enabled;
@@ -403,19 +402,19 @@ impl<'a> StyleManager<'a> {
403402 None
404403 }
405404
405+ #[ cfg( unix) ]
406406 fn indicator_for_file ( & self , path : & PathData ) -> Option < Indicator > {
407- #[ cfg( unix) ]
408407 if self . needs_file_metadata ( ) {
409408 if let Some ( metadata) = path. metadata ( ) {
410409 let mode = metadata. mode ( ) ;
411- if self . has_indicator_style ( Indicator :: Setuid ) && mode & MODE_SETUID != 0 {
410+ if self . has_indicator_style ( Indicator :: Setuid ) && mode & mode :: SETUID != 0 {
412411 return Some ( Indicator :: Setuid ) ;
413412 }
414- if self . has_indicator_style ( Indicator :: Setgid ) && mode & MODE_SETGID != 0 {
413+ if self . has_indicator_style ( Indicator :: Setgid ) && mode & mode :: SETGID != 0 {
415414 return Some ( Indicator :: Setgid ) ;
416415 }
417416 if self . has_indicator_style ( Indicator :: ExecutableFile )
418- && mode & MODE_EXECUTABLE != 0
417+ && mode & mode :: EXECUTABLE != 0
419418 {
420419 return Some ( Indicator :: ExecutableFile ) ;
421420 }
@@ -432,22 +431,31 @@ impl<'a> StyleManager<'a> {
432431 }
433432 }
434433
434+ #[ cfg( not( unix) ) ]
435+ fn indicator_for_file ( & self , _path : & PathData ) -> Option < Indicator > {
436+ if self . has_indicator_style ( Indicator :: RegularFile ) {
437+ Some ( Indicator :: RegularFile )
438+ } else {
439+ None
440+ }
441+ }
442+
443+ #[ cfg( unix) ]
435444 fn indicator_for_directory ( & self , path : & PathData ) -> Option < Indicator > {
436- #[ cfg( unix) ]
437445 if self . needs_dir_metadata ( ) {
438446 if let Some ( metadata) = path. metadata ( ) {
439447 let mode = metadata. mode ( ) ;
440448 if self . has_indicator_style ( Indicator :: StickyAndOtherWritable )
441- && mode & MODE_STICKY_OTHER_WRITABLE == MODE_STICKY_OTHER_WRITABLE
449+ && mode & mode :: STICKY_OTHER_WRITABLE == mode :: STICKY_OTHER_WRITABLE
442450 {
443451 return Some ( Indicator :: StickyAndOtherWritable ) ;
444452 }
445453 if self . has_indicator_style ( Indicator :: OtherWritable )
446- && mode & MODE_OTHER_WRITABLE != 0
454+ && mode & mode :: OTHER_WRITABLE != 0
447455 {
448456 return Some ( Indicator :: OtherWritable ) ;
449457 }
450- if self . has_indicator_style ( Indicator :: Sticky ) && mode & MODE_STICKY != 0 {
458+ if self . has_indicator_style ( Indicator :: Sticky ) && mode & mode :: STICKY != 0 {
451459 return Some ( Indicator :: Sticky ) ;
452460 }
453461 }
@@ -460,25 +468,37 @@ impl<'a> StyleManager<'a> {
460468 }
461469 }
462470
471+ #[ cfg( not( unix) ) ]
472+ fn indicator_for_directory ( & self , _path : & PathData ) -> Option < Indicator > {
473+ if self . has_indicator_style ( Indicator :: Directory ) {
474+ Some ( Indicator :: Directory )
475+ } else {
476+ None
477+ }
478+ }
479+
480+ #[ cfg( unix) ]
463481 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- }
482+ if file_type. is_fifo ( ) && self . has_indicator_style ( Indicator :: FIFO ) {
483+ return Some ( Indicator :: FIFO ) ;
484+ }
485+ if file_type. is_socket ( ) && self . has_indicator_style ( Indicator :: Socket ) {
486+ return Some ( Indicator :: Socket ) ;
487+ }
488+ if file_type. is_block_device ( ) && self . has_indicator_style ( Indicator :: BlockDevice ) {
489+ return Some ( Indicator :: BlockDevice ) ;
490+ }
491+ if file_type. is_char_device ( ) && self . has_indicator_style ( Indicator :: CharacterDevice ) {
492+ return Some ( Indicator :: CharacterDevice ) ;
478493 }
479494 None
480495 }
481496
497+ #[ cfg( not( unix) ) ]
498+ fn indicator_for_special_file ( & self , _file_type : & std:: fs:: FileType ) -> Option < Indicator > {
499+ None
500+ }
501+
482502 #[ cfg( unix) ]
483503 fn needs_file_metadata ( & self ) -> bool {
484504 self . has_indicator_style ( Indicator :: Setuid )
0 commit comments