diff options
author | Lzzzzzt <101313294+Lzzzzzt@users.noreply.github.com> | 2023-08-12 20:50:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-12 08:50:20 -0400 |
commit | 0eec61eb82d10b8b9f76c8b5c9e2a0fae0514a1e (patch) | |
tree | 7195f1d89bc046597feb76b7d8d875b116b61071 /src/ui/widgets | |
parent | fc2fdf3ca79cbfba18350dd5faaf548d7a98f96f (diff) |
feat: tab bar can show current dir name (#390)
* add user & group on footer
* linemode have more options
* linemode have more options
* linemode have more options
* make tarbar title not hardcoded
* topbar width with modified tab width
* change the ellipsis
Diffstat (limited to 'src/ui/widgets')
-rw-r--r-- | src/ui/widgets/tui_tab.rs | 36 | ||||
-rw-r--r-- | src/ui/widgets/tui_topbar.rs | 34 |
2 files changed, 34 insertions, 36 deletions
diff --git a/src/ui/widgets/tui_tab.rs b/src/ui/widgets/tui_tab.rs index f724b86..d82dcbe 100644 --- a/src/ui/widgets/tui_tab.rs +++ b/src/ui/widgets/tui_tab.rs @@ -1,11 +1,11 @@ -use std::ffi::OsStr; - use ratatui::buffer::Buffer; use ratatui::layout::Rect; use ratatui::text::{Line, Span}; use ratatui::widgets::{Paragraph, Widget, Wrap}; +use crate::config::option::TabBarDisplayMode; use crate::context::TabContext; +use crate::util::format::format_tab_bar_title_string; use crate::THEME_T; pub struct TuiTabBar<'a> { @@ -34,23 +34,27 @@ impl<'a> Widget for TuiTabBar<'a> { regular_style }; if let Some(curr_tab) = self.context.tab_ref(tab_id) { - let preview_text: String = curr_tab - .cwd() - .file_name() - .unwrap_or_else(|| OsStr::new("/")) - .to_string_lossy() - .chars() - .take(4) - .collect(); - - spans_vec.push(Span::styled( - format!("{}: {}", i + 1, preview_text), - curr_style, - )); - spans_vec.push(Span::styled(" ", regular_style)); + let preview_text = match self.context.display.mode { + TabBarDisplayMode::Number => format!(" {} ", i + 1), + TabBarDisplayMode::Directory => format_tab_bar_title_string( + self.context.display.max_len, + None, + curr_tab.tab_title(), + ), + TabBarDisplayMode::All => format_tab_bar_title_string( + self.context.display.max_len, + Some(i), + curr_tab.tab_title(), + ), + }; + + spans_vec.push(Span::styled(preview_text, curr_style)); + spans_vec.push(Span::styled(" | ", regular_style)); } } + spans_vec.pop(); + Paragraph::new(Line::from(spans_vec)) .wrap(Wrap { trim: true }) .render(area, buf); diff --git a/src/ui/widgets/tui_topbar.rs b/src/ui/widgets/tui_topbar.rs index 700f318..10ed131 100644 --- a/src/ui/widgets/tui_topbar.rs +++ b/src/ui/widgets/tui_topbar.rs @@ -32,8 +32,7 @@ impl<'a> Widget for TuiTopBar<'a> { let mut ellipses = None; let mut curr_path_str = self.path.to_string_lossy().into_owned(); - let num_tabs = self.context.tab_context_ref().len(); - let tab_width = num_tabs * 8; + let tab_width = self.context.tab_context_ref().tab_area_width(); let name_width = USERNAME.as_str().len() + HOSTNAME.as_str().len() + 2; if tab_width + name_width > area.width as usize { @@ -79,24 +78,19 @@ impl<'a> Widget for TuiTopBar<'a> { .add_modifier(Modifier::BOLD) }; - let text = match ellipses { - Some(s) => Line::from(vec![ - Span::styled(USERNAME.as_str(), username_style), - Span::styled("@", username_style), - Span::styled(HOSTNAME.as_str(), username_style), - Span::styled(" ", username_style), - s, - Span::styled(curr_path_str, path_style), - ]), - None => Line::from(vec![ - Span::styled(USERNAME.as_str(), username_style), - Span::styled("@", username_style), - Span::styled(HOSTNAME.as_str(), username_style), - Span::styled(" ", username_style), - Span::styled(curr_path_str, path_style), - ]), - }; + let mut text = vec![ + Span::styled(USERNAME.as_str(), username_style), + Span::styled("@", username_style), + Span::styled(HOSTNAME.as_str(), username_style), + Span::styled(" ", username_style), + ]; + + if let Some(s) = ellipses { + text.push(s); + } + + text.extend([Span::styled(curr_path_str, path_style)]); - Paragraph::new(text).render(area, buf); + Paragraph::new(Line::from(text)).render(area, buf); } } |