فهرست منبع

Merge pull request #137 from PThorpe92/main

feat: match folder icon to reflect contents
Christina Sørensen 2 سال پیش
والد
کامیت
9d0e2e3c4a
2فایلهای تغییر یافته به همراه22 افزوده شده و 1 حذف شده
  1. 17 0
      src/fs/file.rs
  2. 5 1
      src/output/icons.rs

+ 17 - 0
src/fs/file.rs

@@ -427,6 +427,23 @@ impl<'dir> File<'dir> {
         }
     }
 
+    // To display icons for empty folders.
+    // The naive approach, as one would think that this info may have been cached.
+    // but as mentioned in the size function comment above, different filesystems
+    // make it difficult to get any info about a dir by it's size, so this may be it.
+    #[cfg(unix)]
+    pub fn is_empty_dir(&self) -> bool {
+        if self.is_directory() {
+            match Dir::read_dir(self.path.clone()) {
+                // . & .. are skipped, if the returned iterator has .next(), it's not empty
+                Ok(has_files) => has_files.files(super::DotFilter::Dotfiles, None, false, false).next().is_none(),
+                Err(_) => false,
+            }
+        } else {
+            false
+        }
+    }
+
     #[cfg(windows)]
     pub fn size(&self) -> f::Size {
         if self.is_directory() {

+ 5 - 1
src/output/icons.rs

@@ -106,11 +106,15 @@ pub fn icon_for_file(file: &File<'_>) -> char {
 
     if let Some(icon) = MAP_BY_NAME.get(file.name.as_str()) { *icon }
     else if file.points_to_directory() {
+        if file.is_empty_dir() {
+          return '\u{f115}'  // 
+        }
         match file.name.as_str() {
             "bin"           => '\u{e5fc}', // 
             ".git"          => '\u{f1d3}', // 
             ".idea"         => '\u{e7b5}', // 
-            _               => '\u{f413}'  // 
+            _               => '\u{f07b}'  // 
+
         }
     }
     else if let Some(icon) = extensions.icon_file(file) { icon }