diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-08-31 15:05:14 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-08-31 15:05:58 -0400 |
commit | dc5c3c96dbd4948b1be7194c2f86d473d935e199 (patch) | |
tree | 8fd3c8ecbf8fd4266ec734bb9d6f3f11e73290ad /src/ui | |
parent | 78e23d75de3ece52c91bb9aeb1bceb085e1fe557 (diff) |
move numbered_command into command that can be invoked
This fixes the issue where `numbered_command` conflicts with switch_tab_index
- side: change how tabs are rendered for easier visualization
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/views/tui_folder_view.rs | 37 | ||||
-rw-r--r-- | src/ui/views/tui_hsplit_view.rs | 8 | ||||
-rw-r--r-- | src/ui/widgets/tui_tab.rs | 43 |
3 files changed, 42 insertions, 46 deletions
diff --git a/src/ui/views/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs index e4e9795..10f16c7 100644 --- a/src/ui/views/tui_folder_view.rs +++ b/src/ui/views/tui_folder_view.rs @@ -15,8 +15,6 @@ use crate::ui::widgets::{ }; use crate::ui::PreviewArea; -const TAB_VIEW_WIDTH: u16 = 15; - pub struct TuiFolderView<'a> { pub context: &'a AppContext, pub show_bottom_status: bool, @@ -35,7 +33,6 @@ impl<'a> Widget for TuiFolderView<'a> { fn render(self, area: Rect, buf: &mut Buffer) { let preview_context = self.context.preview_context_ref(); let curr_tab = self.context.tab_context_ref().curr_tab_ref(); - let curr_tab_id = self.context.tab_context_ref().curr_tab_id(); let curr_tab_cwd = curr_tab.cwd(); let curr_list = curr_tab.curr_list_ref(); @@ -199,23 +196,25 @@ impl<'a> Widget for TuiFolderView<'a> { TuiTopBar::new(self.context, curr_tab_cwd).render(rect, buf); // render tabs - if self.context.tab_context_ref().len() > 1 { - let topbar_width = area.width.saturating_sub(TAB_VIEW_WIDTH); + let topbar_width = (self.context.tab_context_ref().len() * 5) as u16; + let topbar_width = if topbar_width > area.width { + area.width + } else { + topbar_width + }; + let topbar_x = area.width.saturating_sub(topbar_width); - let rect = Rect { - x: topbar_width, - y: 0, - width: TAB_VIEW_WIDTH, - height: 1, - }; - let name = curr_tab_id.to_string(); - TuiTabBar::new( - &name[..5], - self.context.tab_context_ref().index, - self.context.tab_context_ref().len(), - ) - .render(rect, buf); - } + let rect = Rect { + x: topbar_x, + y: 0, + width: topbar_width, + height: 1, + }; + TuiTabBar::new( + self.context.tab_context_ref().tab_order.as_slice(), + self.context.tab_context_ref().index, + ) + .render(rect, buf); } } diff --git a/src/ui/views/tui_hsplit_view.rs b/src/ui/views/tui_hsplit_view.rs index 2c26bd6..d2de9d8 100644 --- a/src/ui/views/tui_hsplit_view.rs +++ b/src/ui/views/tui_hsplit_view.rs @@ -124,15 +124,9 @@ impl<'a> Widget for TuiHSplitView<'a> { width: TAB_VIEW_WIDTH, height: 1, }; - let name = if let Some(ostr) = curr_tab.cwd().file_name() { - ostr.to_str().unwrap_or("") - } else { - "" - }; TuiTabBar::new( - name, + self.context.tab_context_ref().tab_order.as_slice(), self.context.tab_context_ref().index, - self.context.tab_context_ref().len(), ) .render(rect, buf); } diff --git a/src/ui/widgets/tui_tab.rs b/src/ui/widgets/tui_tab.rs index 3ab0941..24003c1 100644 --- a/src/ui/widgets/tui_tab.rs +++ b/src/ui/widgets/tui_tab.rs @@ -1,44 +1,47 @@ use tui::buffer::Buffer; use tui::layout::Rect; use tui::style::{Color, Modifier, Style}; -use tui::text::Span; +use tui::text::{Span, Spans}; use tui::widgets::{Paragraph, Widget, Wrap}; -use unicode_width::UnicodeWidthStr; +use uuid::Uuid; pub struct TuiTabBar<'a> { - name: &'a str, - curr: usize, - len: usize, + tabs: &'a [Uuid], + index: usize, } impl<'a> TuiTabBar<'a> { - pub fn new(name: &'a str, curr: usize, len: usize) -> Self { - Self { name, curr, len } + pub fn new(tabs: &'a [Uuid], index: usize) -> Self { + Self { tabs, index } } } impl<'a> Widget for TuiTabBar<'a> { fn render(self, area: Rect, buf: &mut Buffer) { - let selected = Style::default() + let regular_style = Style::default().fg(Color::White); + let selected_style = Style::default() .fg(Color::White) .add_modifier(Modifier::REVERSED); - let str1 = format!("{}/{}", self.curr + 1, self.len); - let str2 = { - let space_avail = if str1.width() >= area.width as usize { - 0 + 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)); } else { - area.width as usize - str1.len() - }; - if space_avail >= self.name.width() { - self.name - } else { - "…" + spans_vec.push(Span::styled( + self.tabs[i].to_string()[..4].to_string(), + regular_style, + )); + spans_vec.push(Span::styled(" ", regular_style)); } - }; + } - Paragraph::new(Span::styled(format!("{}: {}", str1, str2), selected)) + Paragraph::new(Spans::from(spans_vec)) .wrap(Wrap { trim: true }) .render(area, buf); } |