diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-02-03 14:35:30 -0500 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-02-03 14:49:37 -0500 |
commit | d6ec8d8de081cca73a851d5bba9828ee3923470c (patch) | |
tree | bebd66d227bdc02ad833f7b83028c05b443f2047 /src/ui | |
parent | 7be7c13a739e0b43f10af91d4a062e60da13260c (diff) |
rework how folder view behaves
- instead of remembering to print less pixels,
we set it at folder_view
- rework how tab printing works
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/views/tui_folder_view.rs | 57 | ||||
-rw-r--r-- | src/ui/widgets/tui_dirlist.rs | 12 | ||||
-rw-r--r-- | src/ui/widgets/tui_dirlist_detailed.rs | 12 | ||||
-rw-r--r-- | src/ui/widgets/tui_tab.rs | 13 |
4 files changed, 43 insertions, 51 deletions
diff --git a/src/ui/views/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs index ddb658d..f34fa9f 100644 --- a/src/ui/views/tui_folder_view.rs +++ b/src/ui/views/tui_folder_view.rs @@ -12,17 +12,13 @@ const TAB_VIEW_WIDTH: u16 = 15; pub struct TuiFolderView<'a> { pub context: &'a JoshutoContext, pub show_bottom_status: bool, - pub show_borders: bool, - pub collapse_preview: bool, } impl<'a> TuiFolderView<'a> { pub fn new(context: &'a JoshutoContext) -> Self { Self { context, - collapse_preview: context.config_ref().collapse_preview, show_bottom_status: true, - show_borders: context.config_ref().show_borders, } } } @@ -35,7 +31,7 @@ impl<'a> Widget for TuiFolderView<'a> { let parent_list = curr_tab.parent_list_ref(); let child_list = curr_tab.child_list_ref(); - let constraints: &[Constraint; 3] = if !self.collapse_preview { + let constraints: &[Constraint; 3] = if !self.context.config_ref().collapse_preview { &self.context.config_ref().default_layout } else { match child_list { @@ -44,12 +40,11 @@ impl<'a> Widget for TuiFolderView<'a> { } }; - let layout_rect = if self.show_borders { + let layout_rect = if self.context.config_ref().show_borders { let area = Rect { - x: area.left(), y: area.top() + 1, - width: area.right(), - height: area.bottom() - 2, + height: area.height - 2, + ..area }; let block = Block::default().borders(Borders::ALL); let inner = block.inner(area.clone()); @@ -70,11 +65,21 @@ impl<'a> Widget for TuiFolderView<'a> { vec![inner1, layout_rect[1], inner3] } else { - Layout::default() + let mut layout_rect = Layout::default() .direction(Direction::Horizontal) .vertical_margin(1) .constraints(constraints.as_ref()) - .split(area) + .split(area); + + layout_rect[0] = Rect { + width: layout_rect[0].width - 1, + ..layout_rect[0] + }; + layout_rect[1] = Rect { + width: layout_rect[1].width - 1, + ..layout_rect[1] + }; + layout_rect }; // render parent view @@ -92,9 +97,8 @@ impl<'a> Widget for TuiFolderView<'a> { height: 1, }; - let message_style = Style::default().fg(Color::Yellow); - if self.show_bottom_status { + let message_style = Style::default().fg(Color::Yellow); /* draw the bottom status bar */ if let Some(msg) = self.context.worker_msg() { let text = Span::styled(msg, message_style); @@ -117,6 +121,15 @@ impl<'a> Widget for TuiFolderView<'a> { TuiDirList::new(&list).render(layout_rect[2], buf); }; + let topbar_width = area.width; + let rect = Rect { + x: 0, + y: 0, + width: topbar_width, + height: 1, + }; + TuiTopBar::new(self.context, curr_tab.pwd()).render(rect, buf); + // render tabs if self.context.tab_context_ref().len() > 1 { let topbar_width = if area.width > TAB_VIEW_WIDTH { @@ -126,14 +139,6 @@ impl<'a> Widget for TuiFolderView<'a> { }; let rect = Rect { - x: 0, - y: 0, - width: topbar_width, - height: 1, - }; - TuiTopBar::new(self.context, curr_tab.pwd()).render(rect, buf); - - let rect = Rect { x: topbar_width, y: 0, width: TAB_VIEW_WIDTH, @@ -150,16 +155,6 @@ impl<'a> Widget for TuiFolderView<'a> { self.context.tab_context_ref().len(), ) .render(rect, buf); - } else { - let topbar_width = area.width; - - let rect = Rect { - x: 0, - y: 0, - width: topbar_width, - height: 1, - }; - TuiTopBar::new(self.context, curr_tab.pwd()).render(rect, buf); } } } diff --git a/src/ui/widgets/tui_dirlist.rs b/src/ui/widgets/tui_dirlist.rs index 15ceabb..8d410dc 100644 --- a/src/ui/widgets/tui_dirlist.rs +++ b/src/ui/widgets/tui_dirlist.rs @@ -38,7 +38,7 @@ impl<'a> Widget for TuiDirList<'a> { let curr_index = self.dirlist.index.unwrap(); let skip_dist = curr_index / area.height as usize * area.height as usize; - let drawing_width = area.width as usize - 2; + let drawing_width = area.width as usize; for (i, entry) in self .dirlist .iter() @@ -47,15 +47,15 @@ impl<'a> Widget for TuiDirList<'a> { .take(area.height as usize) { let style = entry.get_style(); - print_entry(buf, entry, style, (x + 1, y + i as u16), drawing_width); + print_entry(buf, entry, style, (x + 1, y + i as u16), drawing_width - 1); } { let screen_index = curr_index % area.height as usize; - let space_fill = " ".repeat(drawing_width + 1); let entry = self.dirlist.curr_entry_ref().unwrap(); let style = { let s = entry.get_style().add_modifier(Modifier::REVERSED); + let space_fill = " ".repeat(drawing_width); buf.set_string(x, y + screen_index as u16, space_fill.as_str(), s); s }; @@ -64,7 +64,7 @@ impl<'a> Widget for TuiDirList<'a> { entry, style, (x + 1, y + screen_index as u16), - drawing_width, + drawing_width - 1, ); } } @@ -83,7 +83,7 @@ fn print_entry( match entry.metadata.file_type() { FileType::Directory => { // print filename - buf.set_stringn(x, y, name, drawing_width - 1, style); + buf.set_stringn(x, y, name, drawing_width, style); if name_width > drawing_width { buf.set_string(x + drawing_width as u16 - 1, y, ELLIPSIS, style); } @@ -111,7 +111,7 @@ fn print_entry( let ext_width = extension.width(); buf.set_stringn(x, y, stem, file_drawing_width, style); if stem_width + ext_width > file_drawing_width { - let ext_start_idx = if file_drawing_width + 1 < ext_width { + let ext_start_idx = if file_drawing_width < ext_width { 0 } else { (file_drawing_width - ext_width) as u16 diff --git a/src/ui/widgets/tui_dirlist_detailed.rs b/src/ui/widgets/tui_dirlist_detailed.rs index c6cd9ba..33f6c5f 100644 --- a/src/ui/widgets/tui_dirlist_detailed.rs +++ b/src/ui/widgets/tui_dirlist_detailed.rs @@ -38,7 +38,7 @@ impl<'a> Widget for TuiDirListDetailed<'a> { } }; - let drawing_width = area.width as usize - 2; + let drawing_width = area.width as usize; let skip_dist = curr_index / area.height as usize * area.height as usize; for (i, entry) in self .dirlist @@ -48,15 +48,15 @@ impl<'a> Widget for TuiDirListDetailed<'a> { .take(area.height as usize) { let style = entry.get_style(); - print_entry(buf, entry, style, (x + 1, y + i as u16), drawing_width); + print_entry(buf, entry, style, (x + 1, y + i as u16), drawing_width - 1); } { let screen_index = curr_index % area.height as usize; - let space_fill = " ".repeat(drawing_width + 1); let entry = self.dirlist.curr_entry_ref().unwrap(); let style = { let s = entry.get_style().add_modifier(Modifier::REVERSED); + let space_fill = " ".repeat(drawing_width); buf.set_string(x, y + screen_index as u16, space_fill.as_str(), s); s }; @@ -65,7 +65,7 @@ impl<'a> Widget for TuiDirListDetailed<'a> { entry, style, (x + 1, y + screen_index as u16), - drawing_width, + drawing_width - 1, ); } } @@ -84,14 +84,14 @@ fn print_entry( match entry.metadata.file_type() { FileType::Directory => { // print filename - buf.set_stringn(x, y, name, drawing_width - 1, style); + buf.set_stringn(x, y, name, drawing_width, style); if name_width > drawing_width { buf.set_string(x + drawing_width as u16 - 1, y, ELLIPSIS, style); } } FileType::Symlink(_) => { // print filename - buf.set_stringn(x, y, name, drawing_width - 1, style); + buf.set_stringn(x, y, name, drawing_width, style); buf.set_string(x + drawing_width as u16 - 4, y, "->", style); if name_width >= drawing_width - 4 { buf.set_string(x + drawing_width as u16 - 1, y, ELLIPSIS, style); diff --git a/src/ui/widgets/tui_tab.rs b/src/ui/widgets/tui_tab.rs index d3e27f6..ce16887 100644 --- a/src/ui/widgets/tui_tab.rs +++ b/src/ui/widgets/tui_tab.rs @@ -1,6 +1,6 @@ use tui::buffer::Buffer; use tui::layout::Rect; -use tui::style::{Modifier, Style}; +use tui::style::{Color, Modifier, Style}; use tui::text::{Span, Spans}; use tui::widgets::{Paragraph, Widget, Wrap}; @@ -20,7 +20,9 @@ impl<'a> TuiTabBar<'a> { impl<'a> Widget for TuiTabBar<'a> { fn render(self, area: Rect, buf: &mut Buffer) { - let selected = Style::default().add_modifier(Modifier::REVERSED); + let selected = Style::default() + .fg(Color::White) + .add_modifier(Modifier::REVERSED); let str1 = format!("{}/{}", self.curr + 1, self.len); let str2 = { @@ -35,13 +37,8 @@ impl<'a> Widget for TuiTabBar<'a> { "…" } }; - let text = Spans::from(vec![ - Span::styled(str1, selected), - Span::styled(": ", selected), - Span::styled(str2, selected), - ]); - Paragraph::new(text) + Paragraph::new(Span::styled(format!("{}: {}", str1, str2), selected)) .wrap(Wrap { trim: true }) .render(area, buf); } |