summaryrefslogtreecommitdiffstats
path: root/src/ui/widgets/tui_topbar.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/widgets/tui_topbar.rs')
-rw-r--r--src/ui/widgets/tui_topbar.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/ui/widgets/tui_topbar.rs b/src/ui/widgets/tui_topbar.rs
index be35c7f..0b9c7e8 100644
--- a/src/ui/widgets/tui_topbar.rs
+++ b/src/ui/widgets/tui_topbar.rs
@@ -6,15 +6,17 @@ use tui::style::{Color, Modifier, Style};
use tui::text::{Span, Spans};
use tui::widgets::{Paragraph, Widget};
-use crate::{HOSTNAME, USERNAME};
+use crate::context::JoshutoContext;
+use crate::{HOME_DIR, HOSTNAME, USERNAME};
pub struct TuiTopBar<'a> {
+ pub context: &'a JoshutoContext,
path: &'a Path,
}
impl<'a> TuiTopBar<'a> {
- pub fn new(path: &'a Path) -> Self {
- Self { path }
+ pub fn new(context: &'a JoshutoContext, path: &'a Path) -> Self {
+ Self { context, path }
}
}
@@ -29,17 +31,23 @@ impl<'a> Widget for TuiTopBar<'a> {
.add_modifier(Modifier::BOLD);
let mut ellipses = None;
- let mut curr_path_str = self.path.to_string_lossy();
+ let mut curr_path_str = self.path.to_string_lossy().into_owned();
if curr_path_str.len() > area.width as usize {
match self.path.file_name() {
Some(s) => {
- curr_path_str = s.to_string_lossy();
+ curr_path_str = s.to_string_lossy().into_owned();
ellipses = Some(Span::styled("…", path_style));
}
None => {}
}
}
+ if self.context.config_ref().tilde_in_titlebar {
+ if let Some(home_dir) = HOME_DIR.as_ref() {
+ let home_dir_str = home_dir.to_string_lossy().into_owned();
+ curr_path_str = curr_path_str.replace(&home_dir_str, "~");
+ }
+ }
let text = match ellipses {
Some(s) => Spans::from(vec![