Pārlūkot izejas kodu

Do similar for block devices and named pipes

There doesn't seem to be an io::FileType entry for character special
devices or sockets, so these fall under the io::UnknownType entry. Which
also gets highlighted in yellow, for precisely that reason.
Ben S 11 gadi atpakaļ
vecāks
revīzija
eff87440fa
2 mainītis faili ar 6 papildinājumiem un 2 dzēšanām
  1. 1 1
      file.rs
  2. 5 1
      filetype.rs

+ 1 - 1
file.rs

@@ -145,7 +145,7 @@ impl<'a> File<'a> {
             io::TypeNamedPipe    => Yellow.paint("|"),
             io::TypeBlockSpecial => Purple.paint("s"),
             io::TypeSymlink      => Cyan.paint("l"),
-            _                    => "?".to_string(),
+            io::TypeUnknown      => "?".to_string(),
         }
     }
 

+ 5 - 1
filetype.rs

@@ -3,7 +3,7 @@ use file::File;
 use std::io;
 
 pub enum FileType {
-    Normal, Directory, Executable, Immediate, Compiled, Symlink,
+    Normal, Directory, Executable, Immediate, Compiled, Symlink, Special,
     Image, Video, Music, Lossless, Compressed, Document, Temp, Crypto,
 }
 
@@ -46,6 +46,7 @@ impl FileType {
             Normal => Plain,
             Directory => Blue.bold(),
             Symlink => Cyan.normal(),
+            Special => Yellow.normal(),
             Executable => Green.bold(),
             Image => Fixed(133).normal(),
             Video => Fixed(135).normal(),
@@ -73,6 +74,9 @@ impl<'a> HasType for File<'a> {
         else if self.stat.kind == io::TypeSymlink {
             return Symlink;
         }
+        else if self.stat.kind == io::TypeBlockSpecial || self.stat.kind == io::TypeNamedPipe || self.stat.kind == io::TypeUnknown {
+            return Special;
+        }
         else if self.stat.perm.contains(io::UserExecute) {
             return Executable;
         }