diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-12-21 18:01:39 -0500 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-12-27 22:05:51 -0500 |
commit | fee0ce69e528ad157c86405e98f4906d07de3409 (patch) | |
tree | 749a79a9d6397944a9f49a01a0da8a868e8e9bc2 /src/ui | |
parent | b24f37c36a88b91c7f3ca915af63bd082458cd1f (diff) |
only process previews if preview shown and remove scripts are present in config
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/mod.rs | 8 | ||||
-rw-r--r-- | src/ui/views/tui_folder_view.rs | 30 | ||||
-rw-r--r-- | src/ui/widgets/mod.rs | 2 | ||||
-rw-r--r-- | src/ui/widgets/tui_dirlist_loading.rs | 30 |
4 files changed, 54 insertions, 16 deletions
diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 4580c0b..c71feb6 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -15,14 +15,14 @@ pub struct Rect { } #[derive(Debug, Clone)] -pub struct RenderResult { +pub struct PreviewArea { pub file_preview_path: path::PathBuf, pub preview_area: Rect, } -impl RenderResult { - pub fn new(file_preview_path: path::PathBuf, preview_area: Rect) -> RenderResult { - RenderResult { +impl PreviewArea { + pub fn new(file_preview_path: path::PathBuf, preview_area: Rect) -> Self { + Self { file_preview_path, preview_area, } diff --git a/src/ui/views/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs index f867d48..1be9367 100644 --- a/src/ui/views/tui_folder_view.rs +++ b/src/ui/views/tui_folder_view.rs @@ -8,9 +8,10 @@ use tui::widgets::{Block, Borders, Paragraph, Widget, Wrap}; use crate::context::AppContext; use crate::ui; use crate::ui::widgets::{ - TuiDirList, TuiDirListDetailed, TuiFilePreview, TuiFooter, TuiTabBar, TuiTopBar, + TuiDirList, TuiDirListDetailed, TuiDirListLoading, TuiFilePreview, TuiFooter, TuiTabBar, + TuiTopBar, }; -use crate::ui::RenderResult; +use crate::ui::PreviewArea; const TAB_VIEW_WIDTH: u16 = 15; @@ -142,20 +143,22 @@ impl<'a> Widget for TuiFolderView<'a> { if let Some(list) = child_list.as_ref() { TuiDirList::new(list).render(layout_rect[2], buf); } else if curr_entry.is_some() { - let render_result = calculate_preview(self.context, layout_rect[2]); - if let Some(render_result) = render_result { + let preview_area = calculate_preview(self.context, layout_rect[2]); + if let Some(preview_area) = preview_area { let area = Rect { - x: render_result.preview_area.x, - y: render_result.preview_area.y, - width: render_result.preview_area.width, - height: render_result.preview_area.height, + x: preview_area.preview_area.x, + y: preview_area.preview_area.y, + width: preview_area.preview_area.width, + height: preview_area.preview_area.height, }; if let Some(Some(preview)) = - preview_context.get_preview_ref(&render_result.file_preview_path) + preview_context.get_preview_ref(&preview_area.file_preview_path) { TuiFilePreview::new(preview).render(area, buf); } } + } else { + TuiDirListLoading::new().render(layout_rect[2], buf); } let topbar_width = area.width; @@ -236,7 +239,10 @@ pub fn get_constraints(context: &AppContext) -> &[Constraint; 3] { Some(_) => &display_options.default_layout, None => match curr_entry { None => &display_options.no_preview_layout, - Some(e) => match preview_context.get_preview_ref(e.file_path()) { + Some(entry) if entry.metadata.file_type().is_dir() => { + &display_options.default_layout + } + Some(entry) => match preview_context.get_preview_ref(entry.file_path()) { Some(Some(p)) if p.status.code() != Some(1) => &display_options.default_layout, _ => &display_options.no_preview_layout, }, @@ -280,7 +286,7 @@ pub fn calculate_layout_with_borders(area: Rect, constraints: &[Constraint; 3]) vec![inner1, layout_rect[1], inner3] } -pub fn calculate_preview(context: &AppContext, rect: Rect) -> Option<RenderResult> { +pub fn calculate_preview(context: &AppContext, rect: Rect) -> Option<PreviewArea> { let preview_context = context.preview_context_ref(); let curr_tab = context.tab_context_ref().curr_tab_ref(); @@ -303,7 +309,7 @@ pub fn calculate_preview(context: &AppContext, rect: Rect) -> Option<RenderResul width: rect.width, height: rect.height, }; - Some(RenderResult::new(file_preview_path, preview_area)) + Some(PreviewArea::new(file_preview_path, preview_area)) } } } else { diff --git a/src/ui/widgets/mod.rs b/src/ui/widgets/mod.rs index 12e65b4..ab74629 100644 --- a/src/ui/widgets/mod.rs +++ b/src/ui/widgets/mod.rs @@ -1,5 +1,6 @@ mod tui_dirlist; mod tui_dirlist_detailed; +mod tui_dirlist_loading; mod tui_file_preview; mod tui_footer; mod tui_help; @@ -12,6 +13,7 @@ mod tui_worker; pub use self::tui_dirlist::TuiDirList; pub use self::tui_dirlist_detailed::{trim_file_label, TuiDirListDetailed}; +pub use self::tui_dirlist_loading::TuiDirListLoading; pub use self::tui_file_preview::TuiFilePreview; pub use self::tui_footer::TuiFooter; pub use self::tui_help::{get_keymap_table, TuiHelp}; diff --git a/src/ui/widgets/tui_dirlist_loading.rs b/src/ui/widgets/tui_dirlist_loading.rs new file mode 100644 index 0000000..5e5257a --- /dev/null +++ b/src/ui/widgets/tui_dirlist_loading.rs @@ -0,0 +1,30 @@ +use tui::buffer::Buffer; +use tui::layout::Rect; +use tui::style::{Color, Modifier, Style}; +use tui::widgets::Widget; +use unicode_width::UnicodeWidthStr; + +use crate::fs::{JoshutoDirEntry, JoshutoDirList}; +use crate::ui::widgets::trim_file_label; +use crate::util::style; + +pub struct TuiDirListLoading; + +impl TuiDirListLoading { + pub fn new() -> Self { + Self {} + } +} + +impl Widget for TuiDirListLoading { + fn render(self, area: Rect, buf: &mut Buffer) { + if area.width < 4 || area.height < 1 { + return; + } + let x = area.left(); + let y = area.top(); + + let style = Style::default().fg(Color::Yellow); + buf.set_stringn(x, y, "loading...", area.width as usize, style); + } +} |