summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-03-31 03:28:07 +0200
committerrabite <rabite@posteo.de>2019-03-31 03:28:07 +0200
commited32c83aca9acf40b09c5fb4e7a24cbc2d76d7c9 (patch)
tree1f7105b67257fcc41ba348ce01e662540e3c672f
parented6abefc3c4876bc1ea7dade58909fc161706b60 (diff)
finally fixed memory leak
-rw-r--r--Cargo.toml1
-rw-r--r--src/files.rs12
-rw-r--r--src/hbox.rs8
-rw-r--r--src/main.rs1
-rw-r--r--src/preview.rs6
5 files changed, 22 insertions, 6 deletions
diff --git a/Cargo.toml b/Cargo.toml
index ff594f2..0c02c56 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,6 +12,7 @@ x11-clipboard = "*"
alphanumeric-sort = "1.0.6"
lscolors = { version = "0.5.0", features = [ "ansi_term" ] }
mime-detective = "*"
+tree_magic = "0.2.1"
rayon = "1.0.3"
dirs-2 = "1.1.0"
users = "0.8"
diff --git a/src/files.rs b/src/files.rs
index aa0fa72..a1c5592 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -10,7 +10,7 @@ use std::os::unix::ffi::{OsStringExt, OsStrExt};
use std::ffi::{OsStr, OsString};
use lscolors::LsColors;
-use mime_detective;
+use tree_magic;
use users::{get_current_username,
get_current_groupname,
get_user_by_uid,
@@ -717,10 +717,12 @@ impl File {
Ok((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 get_mime(&self) -> String {
+ // tree_magic::from_filepath(&self.path)
+ // }
+
+ pub fn is_text(&self) -> bool {
+ tree_magic::match_filepath("text/plain", &self.path)
}
diff --git a/src/hbox.rs b/src/hbox.rs
index 15644f5..0be0408 100644
--- a/src/hbox.rs
+++ b/src/hbox.rs
@@ -54,10 +54,18 @@ impl<T> HBox<T> where T: Widget + PartialEq {
widget
}
+ pub fn remove_widget(&mut self, index: usize) -> T {
+ self.widgets.remove(index)
+ }
+
pub fn prepend_widget(&mut self, widget: T) {
self.widgets.insert(0, widget);
}
+ pub fn insert_widget(&mut self, index: usize, widget: T) {
+ self.widgets.insert(index, widget);
+ }
+
pub fn toggle_zoom(&mut self) -> HResult<()> {
self.clear().log();
self.zoom_active = !self.zoom_active;
diff --git a/src/main.rs b/src/main.rs
index 8a55639..5a22635 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,6 +20,7 @@ extern crate libc;
extern crate notify;
extern crate parse_ansi;
extern crate signal_notify;
+extern crate tree_magic;
use failure::Fail;
diff --git a/src/preview.rs b/src/preview.rs
index 2d503c8..013b2d6 100644
--- a/src/preview.rs
+++ b/src/preview.rs
@@ -434,6 +434,10 @@ impl Previewer {
self.widget.set_stale()
}
+ pub fn get_file(&self) -> Option<&File> {
+ self.file.as_ref()
+ }
+
pub fn set_file(&mut self,
file: &File) -> HResult<()> {
if Some(file) == self.file.as_ref() && !self.widget.is_stale()? { return Ok(()) }
@@ -458,7 +462,7 @@ impl Previewer {
return preview;
}
- if file.get_mime() == Some("text".to_string()) {
+ if file.is_text() {
return Previewer::preview_text(&file, &core, stale)
}