diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-12-14 10:59:13 -0500 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-12-14 10:59:13 -0500 |
commit | f4b150b9e17a74f23a5472690759af59b4c18b8d (patch) | |
tree | 3be34d2785eda3672bd3f466d350cf8e392e6e9a | |
parent | 5ea87f65df0b0744ee1d01fd40e240e6abf0da77 (diff) |
change tab render
-rw-r--r-- | src/ui/views/tui_folder_view.rs | 8 | ||||
-rw-r--r-- | src/ui/views/tui_hsplit_view.rs | 6 | ||||
-rw-r--r-- | src/ui/widgets/tui_tab.rs | 41 |
3 files changed, 30 insertions, 25 deletions
diff --git a/src/ui/views/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs index 1f7fa1e..f08f125 100644 --- a/src/ui/views/tui_folder_view.rs +++ b/src/ui/views/tui_folder_view.rs @@ -112,7 +112,7 @@ impl<'a> TuiFolderView<'a> { pub fn tab_area(&self, area: &Rect, num_tabs: usize) -> Rect { // render tabs - let tab_width = (num_tabs * 5) as u16; + let tab_width = (num_tabs * 8) as u16; let tab_width = if tab_width > area.width { area.width } else { @@ -240,11 +240,7 @@ impl<'a> Widget for TuiFolderView<'a> { // render tabs let tab_area = self.tab_area(&area, self.context.tab_context_ref().len()); - TuiTabBar::new( - self.context.tab_context_ref().tab_order.as_slice(), - self.context.tab_context_ref().index, - ) - .render(tab_area, buf); + TuiTabBar::new(self.context.tab_context_ref()).render(tab_area, buf); } } diff --git a/src/ui/views/tui_hsplit_view.rs b/src/ui/views/tui_hsplit_view.rs index 99dde1e..702b4f0 100644 --- a/src/ui/views/tui_hsplit_view.rs +++ b/src/ui/views/tui_hsplit_view.rs @@ -125,11 +125,7 @@ impl<'a> Widget for TuiHSplitView<'a> { width: TAB_VIEW_WIDTH, height: 1, }; - TuiTabBar::new( - self.context.tab_context_ref().tab_order.as_slice(), - self.context.tab_context_ref().index, - ) - .render(rect, buf); + TuiTabBar::new(self.context.tab_context_ref()).render(rect, buf); } } diff --git a/src/ui/widgets/tui_tab.rs b/src/ui/widgets/tui_tab.rs index 24003c1..1640d78 100644 --- a/src/ui/widgets/tui_tab.rs +++ b/src/ui/widgets/tui_tab.rs @@ -1,19 +1,20 @@ +use std::ffi::OsStr; + use tui::buffer::Buffer; use tui::layout::Rect; use tui::style::{Color, Modifier, Style}; use tui::text::{Span, Spans}; use tui::widgets::{Paragraph, Widget, Wrap}; -use uuid::Uuid; +use crate::context::TabContext; pub struct TuiTabBar<'a> { - tabs: &'a [Uuid], - index: usize, + context: &'a TabContext, } impl<'a> TuiTabBar<'a> { - pub fn new(tabs: &'a [Uuid], index: usize) -> Self { - Self { tabs, index } + pub fn new(context: &'a TabContext) -> Self { + Self { context } } } @@ -24,18 +25,30 @@ impl<'a> Widget for TuiTabBar<'a> { .fg(Color::White) .add_modifier(Modifier::REVERSED); + let index = self.context.index; + let tab_order = self.context.tab_order.as_slice(); + let mut spans_vec = vec![]; - for i in 0..self.tabs.len() { - if i == self.index { - spans_vec.push(Span::styled( - self.tabs[i].to_string()[..4].to_string(), - selected_style, - )); - spans_vec.push(Span::styled(" ", regular_style)); + for i in 0..tab_order.len() { + let curr_style = if i == index { + selected_style } else { + regular_style + }; + let tab_id = &tab_order[i]; + if let Some(curr_tab) = self.context.tab_ref(tab_id) { + let preview_text: String = curr_tab + .cwd() + .file_name() + .unwrap_or(OsStr::new("/")) + .to_string_lossy() + .chars() + .take(4) + .collect(); + spans_vec.push(Span::styled( - self.tabs[i].to_string()[..4].to_string(), - regular_style, + format!("{}: {}", i + 1, preview_text), + curr_style, )); spans_vec.push(Span::styled(" ", regular_style)); } |