mirror of
https://github.com/bobwen-dev/hunter
synced 2025-04-12 00:55:41 +02:00
shorten home path for display
This commit is contained in:
parent
8b1c4db9cf
commit
7011023bab
@ -347,8 +347,13 @@ impl FileBrowser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_title(&self) -> HResult<()> {
|
pub fn set_title(&self) -> HResult<()> {
|
||||||
let cwd = &self.cwd.path.to_string_lossy();
|
let path = match self.cwd.short_path() {
|
||||||
self.screen()?.set_title(cwd)?;
|
Ok(path) => path,
|
||||||
|
Err(_) => self.cwd.path.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
let path = path.to_string_lossy().to_string();
|
||||||
|
self.screen()?.set_title(&path)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -688,7 +693,16 @@ impl Widget for FileBrowser {
|
|||||||
crate::term::highlight_color() } else {
|
crate::term::highlight_color() } else {
|
||||||
crate::term::from_lscolor(file.color.as_ref().unwrap()) };
|
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 pretty_path = format!("{}/{}{}", path, &color, name );
|
||||||
let sized_path = crate::term::sized_string(&pretty_path, xsize);
|
let sized_path = crate::term::sized_string(&pretty_path, xsize);
|
||||||
|
11
src/files.rs
11
src/files.rs
@ -602,4 +602,15 @@ impl File {
|
|||||||
= chrono::Local.timestamp(self.meta().unwrap().mtime(), 0);
|
= chrono::Local.timestamp(self.meta().unwrap().mtime(), 0);
|
||||||
Some(time.format("%F %R").to_string())
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,11 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use crate::fail::HResult;
|
use crate::fail::HResult;
|
||||||
|
|
||||||
|
pub fn home_path() -> HResult<PathBuf> {
|
||||||
|
let home = dirs_2::home_dir()?;
|
||||||
|
Ok(home)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn hunter_path() -> HResult<PathBuf> {
|
pub fn hunter_path() -> HResult<PathBuf> {
|
||||||
let mut config_dir = dirs_2::config_dir()?;
|
let mut config_dir = dirs_2::config_dir()?;
|
||||||
config_dir.push("hunter/");
|
config_dir.push("hunter/");
|
||||||
|
@ -257,7 +257,6 @@ pub trait Widget {
|
|||||||
self.refresh().log();
|
self.refresh().log();
|
||||||
self.draw().log();
|
self.draw().log();
|
||||||
self.after_draw().log();
|
self.after_draw().log();
|
||||||
self.get_core_mut()?.screen.flush().ok();
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -299,6 +298,7 @@ pub trait Widget {
|
|||||||
&self.get_header_drawlist().unwrap_or("".to_string()) +
|
&self.get_header_drawlist().unwrap_or("".to_string()) +
|
||||||
&self.get_footer_drawlist().unwrap_or("".to_string());
|
&self.get_footer_drawlist().unwrap_or("".to_string());
|
||||||
self.write_to_screen(&output).log();
|
self.write_to_screen(&output).log();
|
||||||
|
self.screen()?.flush().ok();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user