summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-04-20 18:59:41 +0200
committerrabite <rabite@posteo.de>2019-04-20 18:59:41 +0200
commite46c2532f89112fab7a3a4353bef0ee2c594b209 (patch)
treee8f7ee049e9edaad900e306718a9645092378f5d /src
parent416f66bab9559d1ac337b68105f778afb4a437b2 (diff)
use libraryized pathbuftools
Diffstat (limited to 'src')
-rw-r--r--src/file_browser.rs3
-rw-r--r--src/files.rs70
-rw-r--r--src/main.rs1
3 files changed, 4 insertions, 70 deletions
diff --git a/src/file_browser.rs b/src/file_browser.rs
index 4554e4d..b74cb0d 100644
--- a/src/file_browser.rs
+++ b/src/file_browser.rs
@@ -1,4 +1,5 @@
use termion::event::Key;
+use pathbuftools::PathBufTools;
use std::io::Write;
use std::sync::{Arc, Mutex, RwLock};
@@ -6,7 +7,7 @@ use std::path::PathBuf;
use std::ffi::OsString;
use std::collections::HashSet;
-use crate::files::{File, Files, PathBufExt};
+use crate::files::{File, Files};
use crate::fscache::FsCache;
use crate::listview::ListView;
use crate::hbox::HBox;
diff --git a/src/files.rs b/src/files.rs
index c240920..a3cd0ab 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -6,8 +6,6 @@ use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, RwLock};
use std::sync::mpsc::Sender;
use std::hash::{Hash, Hasher};
-use std::os::unix::ffi::{OsStringExt, OsStrExt};
-use std::ffi::{OsStr, OsString};
use lscolors::LsColors;
use tree_magic;
@@ -20,6 +18,7 @@ use failure::Error;
use notify::DebouncedEvent;
use rayon::{ThreadPool, ThreadPoolBuilder};
use alphanumeric_sort::compare_str;
+use pathbuftools::PathBufTools;
use crate::fail::{HResult, HError, ErrorLog};
use crate::dirty::{AsyncDirtyBit, DirtyBit, Dirtyable};
@@ -997,70 +996,3 @@ impl File {
self.path.short_string()
}
}
-
-
-pub trait PathBufExt {
- fn short_path(&self) -> PathBuf;
- fn short_string(&self) -> String;
- fn name_starts_with(&self, pat: &str) -> bool;
- fn quoted_file_name(&self) -> Option<OsString>;
- fn quoted_path(&self) -> OsString;
-}
-
-impl PathBufExt for PathBuf {
- fn short_path(&self) -> PathBuf {
- if let Ok(home) = crate::paths::home_path() {
- if let Ok(short) = self.strip_prefix(home) {
- let mut path = PathBuf::from("~");
- path.push(short);
- return path
- }
- }
- return self.clone();
- }
-
- fn short_string(&self) -> String {
- self.short_path().to_string_lossy().to_string()
- }
-
- fn name_starts_with(&self, pat: &str) -> bool {
- if let Some(name) = self.file_name() {
- let nbytes = name.as_bytes();
- let pbytes = pat.as_bytes();
-
- if nbytes.starts_with(pbytes) {
- return true;
- } else {
- return false;
- }
- }
- false
- }
-
- fn quoted_file_name(&self) -> Option<OsString> {
- if let Some(name) = self.file_name() {
- let mut name = name.as_bytes().to_vec();
- let mut quote = "\"".as_bytes().to_vec();
- let mut quoted = vec![];
- quoted.append(&mut quote.clone());
- quoted.append(&mut name);
- quoted.append(&mut quote);
-
- let quoted_name = OsStr::from_bytes(&quoted).to_os_string();
- return Some(quoted_name);
- }
- None
- }
-
- fn quoted_path(&self) -> OsString {
- let mut path = self.clone().into_os_string().into_vec();
- let mut quote = "\"".as_bytes().to_vec();
-
- let mut quoted = vec![];
- quoted.append(&mut quote.clone());
- quoted.append(&mut path);
- quoted.append(&mut quote);
-
- OsString::from_vec(quoted)
- }
-}
diff --git a/src/main.rs b/src/main.rs
index ea3d908..837a9ac 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -23,6 +23,7 @@ extern crate signal_notify;
extern crate tree_magic;
extern crate systemstat;
extern crate osstrtools;
+extern crate pathbuftools;
use failure::Fail;