diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/views/tui_folder_view.rs | 10 | ||||
-rw-r--r-- | src/ui/widgets/tui_tab.rs | 36 | ||||
-rw-r--r-- | src/ui/widgets/tui_topbar.rs | 34 |
3 files changed, 39 insertions, 41 deletions
diff --git a/src/ui/views/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs index 2a6204b..c9ffeba 100644 --- a/src/ui/views/tui_folder_view.rs +++ b/src/ui/views/tui_folder_view.rs @@ -110,13 +110,13 @@ impl<'a> TuiFolderView<'a> { } } - pub fn tab_area(&self, area: &Rect, num_tabs: usize) -> Rect { + pub fn tab_area(&self, area: &Rect, tabs_width: usize) -> Rect { // render tabs - let tab_width = (num_tabs * 8) as u16; - let tab_width = if tab_width > area.width { + let tabs_width = tabs_width as u16; + let tab_width = if tabs_width > area.width { area.width } else { - tab_width + tabs_width }; let topbar_x = area.width.saturating_sub(tab_width); @@ -239,7 +239,7 @@ impl<'a> Widget for TuiFolderView<'a> { TuiTopBar::new(self.context, curr_tab_cwd).render(topbar_area, buf); // render tabs - let tab_area = self.tab_area(&area, self.context.tab_context_ref().len()); + let tab_area = self.tab_area(&area, self.context.tab_context_ref().tab_area_width()); TuiTabBar::new(self.context.tab_context_ref()).render(tab_area, buf); } } 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); } } |