summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkennycallado <kennycallado@gmail.com>2021-11-10 03:41:03 +0100
committerGitHub <noreply@github.com>2021-11-09 21:41:03 -0500
commit9da0c12de1cbc499f6b38d5fbcc40f29d575a3e4 (patch)
tree426ccb8d241a387e74a8a81f2c277fc83963e14d
parentc3a6089e9d9c83866e8c8bb2bae2695c44c5dab9 (diff)
Path shortener (#103)
* feature shortens the path when it is longer than area.width Path.component approach Co-authored-by: kenny Callado <kennycallado@hotmail.com>
-rw-r--r--src/ui/widgets/tui_topbar.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/ui/widgets/tui_topbar.rs b/src/ui/widgets/tui_topbar.rs
index 53d0280..6824fce 100644
--- a/src/ui/widgets/tui_topbar.rs
+++ b/src/ui/widgets/tui_topbar.rs
@@ -1,3 +1,4 @@
+use std::path::Component;
use std::path::Path;
use tui::buffer::Buffer;
@@ -31,8 +32,22 @@ impl<'a> Widget for TuiTopBar<'a> {
if curr_path_str.len() > area.width as usize {
if let Some(s) = self.path.file_name() {
+ let mut short_path = String::new();
+ for component in self.path.components() {
+ match component {
+ Component::RootDir => short_path.push('/'),
+ Component::Normal(s) => {
+ let ch = s.to_string_lossy().chars().next().unwrap();
+ short_path.push(ch);
+ short_path.push('/');
+ }
+ Component::Prefix(_) => {}
+ Component::CurDir => {}
+ Component::ParentDir => {}
+ }
+ }
+ ellipses = Some(Span::styled(short_path, path_style));
curr_path_str = s.to_string_lossy().into_owned();
- ellipses = Some(Span::styled("…", path_style));
}
}
if self