mirror of https://github.com/bobwen-dev/hunter
finally fixed memory leak
This commit is contained in:
parent
ed6abefc3c
commit
ed32c83aca
|
@ -12,6 +12,7 @@ x11-clipboard = "*"
|
||||||
alphanumeric-sort = "1.0.6"
|
alphanumeric-sort = "1.0.6"
|
||||||
lscolors = { version = "0.5.0", features = [ "ansi_term" ] }
|
lscolors = { version = "0.5.0", features = [ "ansi_term" ] }
|
||||||
mime-detective = "*"
|
mime-detective = "*"
|
||||||
|
tree_magic = "0.2.1"
|
||||||
rayon = "1.0.3"
|
rayon = "1.0.3"
|
||||||
dirs-2 = "1.1.0"
|
dirs-2 = "1.1.0"
|
||||||
users = "0.8"
|
users = "0.8"
|
||||||
|
|
12
src/files.rs
12
src/files.rs
|
@ -10,7 +10,7 @@ use std::os::unix::ffi::{OsStringExt, OsStrExt};
|
||||||
use std::ffi::{OsStr, OsString};
|
use std::ffi::{OsStr, OsString};
|
||||||
|
|
||||||
use lscolors::LsColors;
|
use lscolors::LsColors;
|
||||||
use mime_detective;
|
use tree_magic;
|
||||||
use users::{get_current_username,
|
use users::{get_current_username,
|
||||||
get_current_groupname,
|
get_current_groupname,
|
||||||
get_user_by_uid,
|
get_user_by_uid,
|
||||||
|
@ -717,10 +717,12 @@ impl File {
|
||||||
Ok((size, unit))
|
Ok((size, unit))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_mime(&self) -> Option<String> {
|
// pub fn get_mime(&self) -> String {
|
||||||
let detective = mime_detective::MimeDetective::new().ok()?;
|
// tree_magic::from_filepath(&self.path)
|
||||||
let mime = detective.detect_filepath(&self.path).ok()?;
|
// }
|
||||||
Some(mime.type_().as_str().to_string())
|
|
||||||
|
pub fn is_text(&self) -> bool {
|
||||||
|
tree_magic::match_filepath("text/plain", &self.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,18 @@ impl<T> HBox<T> where T: Widget + PartialEq {
|
||||||
widget
|
widget
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn remove_widget(&mut self, index: usize) -> T {
|
||||||
|
self.widgets.remove(index)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn prepend_widget(&mut self, widget: T) {
|
pub fn prepend_widget(&mut self, widget: T) {
|
||||||
self.widgets.insert(0, widget);
|
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<()> {
|
pub fn toggle_zoom(&mut self) -> HResult<()> {
|
||||||
self.clear().log();
|
self.clear().log();
|
||||||
self.zoom_active = !self.zoom_active;
|
self.zoom_active = !self.zoom_active;
|
||||||
|
|
|
@ -20,6 +20,7 @@ extern crate libc;
|
||||||
extern crate notify;
|
extern crate notify;
|
||||||
extern crate parse_ansi;
|
extern crate parse_ansi;
|
||||||
extern crate signal_notify;
|
extern crate signal_notify;
|
||||||
|
extern crate tree_magic;
|
||||||
|
|
||||||
use failure::Fail;
|
use failure::Fail;
|
||||||
|
|
||||||
|
|
|
@ -434,6 +434,10 @@ impl Previewer {
|
||||||
self.widget.set_stale()
|
self.widget.set_stale()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_file(&self) -> Option<&File> {
|
||||||
|
self.file.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_file(&mut self,
|
pub fn set_file(&mut self,
|
||||||
file: &File) -> HResult<()> {
|
file: &File) -> HResult<()> {
|
||||||
if Some(file) == self.file.as_ref() && !self.widget.is_stale()? { return Ok(()) }
|
if Some(file) == self.file.as_ref() && !self.widget.is_stale()? { return Ok(()) }
|
||||||
|
@ -458,7 +462,7 @@ impl Previewer {
|
||||||
return preview;
|
return preview;
|
||||||
}
|
}
|
||||||
|
|
||||||
if file.get_mime() == Some("text".to_string()) {
|
if file.is_text() {
|
||||||
return Previewer::preview_text(&file, &core, stale)
|
return Previewer::preview_text(&file, &core, stale)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue