summaryrefslogtreecommitdiffstats
path: root/src/files.rs
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-01-30 15:26:24 +0100
committerrabite <rabite@posteo.de>2019-01-30 15:26:24 +0100
commit60468a4c660288b663506a404c922b2506fc6542 (patch)
tree24ed29962e3ca98e5430095f8a050c16978fd3fa /src/files.rs
parentb96895a2f28e1e9fead9228617cdc02fdd1f3c31 (diff)
previewing text files
Diffstat (limited to 'src/files.rs')
-rw-r--r--src/files.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/files.rs b/src/files.rs
index 1473fd5..17dc3a2 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -6,6 +6,7 @@ use std::cmp::{Ord, Ordering};
use std::time::SystemTime;
use lscolors::{LsColors, Style};
+use mime_detective;
lazy_static! {
static ref COLORS: LsColors = LsColors::from_env().unwrap();
@@ -57,7 +58,7 @@ impl Files {
let file = File::new(&name, path, kind, size as usize, mtime, color);
files.push(file)
}
-
+
let mut files = Files { files: files,
sort: SortBy::Name,
dirs_first: true };
@@ -107,7 +108,7 @@ impl Files {
SortBy::MTime => SortBy::Name
};
}
-
+
pub fn iter(&self) -> std::slice::Iter<File> {
self.files.iter()
}
@@ -195,6 +196,12 @@ impl File {
(size, unit)
}
+ pub fn get_mime(&self) -> Option<String> {
+ let detective = mime_detective::MimeDetective::new().ok()?;
+ let mime = detective.detect_filepath(&self.path).ok()?;
+ Some(mime.type_().as_str().to_string())
+ }
+
pub fn grand_parent(&self) -> Option<PathBuf> {
Some(self.path.parent()?.parent()?.to_path_buf())
}
@@ -207,4 +214,3 @@ impl File {
self.path.clone()
}
}
-