summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-03-17 01:50:38 +0100
committerrabite <rabite@posteo.de>2019-03-17 01:50:38 +0100
commit7011023babde960b8ce7a4fbbdddaab696c44649 (patch)
treecf6ca645b201eb319d10a99731bfe57cc2733e21
parent8b1c4db9cfa2ea0bf02e9e96c29b2510bbc391af (diff)
shorten home path for display
-rw-r--r--src/file_browser.rs20
-rw-r--r--src/files.rs11
-rw-r--r--src/paths.rs5
-rw-r--r--src/widget.rs2
4 files changed, 34 insertions, 4 deletions
diff --git a/src/file_browser.rs b/src/file_browser.rs
index f39772a..75027db 100644
--- a/src/file_browser.rs
+++ b/src/file_browser.rs
@@ -347,8 +347,13 @@ impl FileBrowser {
}
pub fn set_title(&self) -> HResult<()> {
- let cwd = &self.cwd.path.to_string_lossy();
- self.screen()?.set_title(cwd)?;
+ let path = match self.cwd.short_path() {
+ Ok(path) => path,
+ Err(_) => self.cwd.path.clone()
+ };
+
+ let path = path.to_string_lossy().to_string();
+ self.screen()?.set_title(&path)?;
Ok(())
}
@@ -688,7 +693,16 @@ impl Widget for FileBrowser {
crate::term::highlight_color() } else {
crate::term::from_lscolor(file.color.as_ref().unwrap()) };
- let path = file.path.parent()?.to_string_lossy().to_string();
+ let path = match self.cwd.short_path() {
+ Ok(path) => path,
+ Err(_) => file.path
+ };
+
+ let mut path = path.to_string_lossy().to_string();
+ if &path == "" { path.clear(); }
+ if &path == "~/" { path.pop(); }
+ if &path == "/" { path.pop(); }
+
let pretty_path = format!("{}/{}{}", path, &color, name );
let sized_path = crate::term::sized_string(&pretty_path, xsize);
diff --git a/src/files.rs b/src/files.rs
index 5cc7dd8..49741df 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -602,4 +602,15 @@ impl File {
= chrono::Local.timestamp(self.meta().unwrap().mtime(), 0);
Some(time.format("%F %R").to_string())
}
+
+ pub fn short_path(&self) -> HResult<PathBuf> {
+ if let Ok(home) = crate::paths::home_path() {
+ if let Ok(short) = self.path.strip_prefix(home) {
+ let mut path = PathBuf::from("~");
+ path.push(short);
+ return Ok(path);
+ }
+ }
+ return Ok(self.path.clone())
+ }
}
diff --git a/src/paths.rs b/src/paths.rs
index be40658..b3f3e1d 100644
--- a/src/paths.rs
+++ b/src/paths.rs
@@ -4,6 +4,11 @@ use std::path::PathBuf;
use crate::fail::HResult;
+pub fn home_path() -> HResult<PathBuf> {
+ let home = dirs_2::home_dir()?;
+ Ok(home)
+}
+
pub fn hunter_path() -> HResult<PathBuf> {
let mut config_dir = dirs_2::config_dir()?;
config_dir.push("hunter/");
diff --git a/src/widget.rs b/src/widget.rs
index 8c9942b..09a5d0a 100644
--- a/src/widget.rs
+++ b/src/widget.rs
@@ -257,7 +257,6 @@ pub trait Widget {
self.refresh().log();
self.draw().log();
self.after_draw().log();
- self.get_core_mut()?.screen.flush().ok();
}
Ok(())
}
@@ -299,6 +298,7 @@ pub trait Widget {
&self.get_header_drawlist().unwrap_or("".to_string()) +
&self.get_footer_drawlist().unwrap_or("".to_string());
self.write_to_screen(&output).log();
+ self.screen()?.flush().ok();
Ok(())
}