From d0b6810cb35386c5fd3ebfe51c626f1a95507a2d Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sun, 12 Nov 2023 23:42:39 +0800 Subject: [PATCH] .. --- yazi-core/src/context.rs | 5 ----- yazi-core/src/manager/commands/peek.rs | 10 +++------- yazi-core/src/preview/preview.rs | 12 ++++-------- yazi-fm/src/app.rs | 6 +++--- yazi-fm/src/completion/completion.rs | 6 ++++-- yazi-fm/src/executor.rs | 2 +- yazi-fm/src/help/layout.rs | 5 +++-- yazi-fm/src/input/input.rs | 6 ++++-- yazi-fm/src/main.rs | 1 + yazi-fm/src/select/select.rs | 6 ++++-- yazi-fm/src/tasks/clear.rs | 19 ------------------- yazi-fm/src/tasks/layout.rs | 4 ++-- yazi-fm/src/tasks/mod.rs | 2 -- yazi-fm/src/which/layout.rs | 5 +++-- yazi-fm/src/widgets/clear.rs | 22 ++++++++++++++++++++++ yazi-fm/src/widgets/mod.rs | 3 +++ 16 files changed, 57 insertions(+), 57 deletions(-) delete mode 100644 yazi-fm/src/tasks/clear.rs create mode 100644 yazi-fm/src/widgets/clear.rs create mode 100644 yazi-fm/src/widgets/mod.rs diff --git a/yazi-core/src/context.rs b/yazi-core/src/context.rs index 31546bb3..be4ea554 100644 --- a/yazi-core/src/context.rs +++ b/yazi-core/src/context.rs @@ -70,9 +70,4 @@ impl Ctx { } None } - - #[inline] - pub fn image_layer(&self) -> bool { - !self.which.visible && !self.help.visible && !self.tasks.visible - } } diff --git a/yazi-core/src/manager/commands/peek.rs b/yazi-core/src/manager/commands/peek.rs index da9723cd..708a0f4c 100644 --- a/yazi-core/src/manager/commands/peek.rs +++ b/yazi-core/src/manager/commands/peek.rs @@ -1,16 +1,12 @@ use crate::manager::Manager; impl Manager { - pub fn peek(&mut self, sequent: bool, show_image: bool) -> bool { + pub fn peek(&mut self, sequent: bool) -> bool { let Some(hovered) = self.hovered().cloned() else { return self.active_mut().preview.reset(|_| true); }; let url = &hovered.url; - if !show_image { - self.active_mut().preview.reset(|l| l.is_image()); - } - if hovered.is_dir() { let position = self.active().history(url).map(|f| (f.offset, f.files.len())); self.active_mut().preview.folder(url, position, sequent); @@ -22,9 +18,9 @@ impl Manager { }; if sequent { - self.active_mut().preview.sequent(url, &mime, show_image); + self.active_mut().preview.sequent(url, &mime); } else { - self.active_mut().preview.go(url, &mime, show_image); + self.active_mut().preview.go(url, &mime); } false } diff --git a/yazi-core/src/preview/preview.rs b/yazi-core/src/preview/preview.rs index c6c1ad0b..8723b893 100644 --- a/yazi-core/src/preview/preview.rs +++ b/yazi-core/src/preview/preview.rs @@ -32,11 +32,9 @@ pub enum PreviewData { } impl Preview { - pub fn go(&mut self, url: &Url, mime: &str, show_image: bool) { + pub fn go(&mut self, url: &Url, mime: &str) { let kind = MimeKind::new(mime); - if !show_image && kind.show_as_image() { - return; - } else if self.same(url, mime) { + if self.same(url, mime) { return; } @@ -104,11 +102,9 @@ impl Preview { })); } - pub fn sequent(&mut self, url: &Url, mime: &str, show_image: bool) { + pub fn sequent(&mut self, url: &Url, mime: &str) { let kind = MimeKind::new(mime); - if !show_image && kind.show_as_image() { - return; - } else if self.same(url, mime) { + if self.same(url, mime) { return; } diff --git a/yazi-fm/src/app.rs b/yazi-fm/src/app.rs index 843cdc77..c16522a5 100644 --- a/yazi-fm/src/app.rs +++ b/yazi-fm/src/app.rs @@ -97,7 +97,7 @@ impl App { self.cx.manager.current_mut().set_page(true); self.cx.manager.active_mut().preview.reset(|_| true); - self.cx.manager.peek(true, self.cx.image_layer()); + self.cx.manager.peek(true); emit!(Render); } @@ -163,9 +163,9 @@ impl App { Event::Peek(sequent) => { if let Some((max, url)) = sequent { manager.active_mut().update_peek(max, url); - self.cx.manager.peek(true, self.cx.image_layer()); + self.cx.manager.peek(true); } else { - self.cx.manager.peek(false, self.cx.image_layer()); + self.cx.manager.peek(false); } } Event::Preview(lock) => { diff --git a/yazi-fm/src/completion/completion.rs b/yazi-fm/src/completion/completion.rs index dc7495ee..a76668a5 100644 --- a/yazi-fm/src/completion/completion.rs +++ b/yazi-fm/src/completion/completion.rs @@ -1,7 +1,9 @@ -use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, Clear, List, ListItem, Widget}}; +use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, List, ListItem, Widget}}; use yazi_config::THEME; use yazi_core::{Ctx, Position}; +use crate::widgets; + pub(crate) struct Completion<'a> { cx: &'a Ctx, } @@ -54,7 +56,7 @@ impl<'a> Widget for Completion<'a> { area.height = rect.height.saturating_sub(area.y).min(area.height); } - Clear.render(area, buf); + widgets::Clear.render(area, buf); List::new(items) .block( Block::new() diff --git a/yazi-fm/src/executor.rs b/yazi-fm/src/executor.rs index 11b36e74..68dedcbe 100644 --- a/yazi-fm/src/executor.rs +++ b/yazi-fm/src/executor.rs @@ -140,7 +140,7 @@ impl<'a> Executor<'a> { b"peek" => { let step = exec.args.first().and_then(|s| s.parse().ok()).unwrap_or(0); self.cx.manager.active_mut().preview.arrow(step); - self.cx.manager.peek(true, self.cx.image_layer()) + self.cx.manager.peek(true) } // Tasks b"tasks_show" => self.cx.tasks.toggle(()), diff --git a/yazi-fm/src/help/layout.rs b/yazi-fm/src/help/layout.rs index b290e509..7aa4ab1a 100644 --- a/yazi-fm/src/help/layout.rs +++ b/yazi-fm/src/help/layout.rs @@ -1,8 +1,9 @@ -use ratatui::{buffer::Buffer, layout::{self, Rect}, prelude::{Constraint, Direction}, widgets::{Clear, Paragraph, Widget}}; +use ratatui::{buffer::Buffer, layout::{self, Rect}, prelude::{Constraint, Direction}, widgets::{Paragraph, Widget}}; use yazi_config::THEME; use yazi_core::Ctx; use super::Bindings; +use crate::widgets; pub(crate) struct Layout<'a> { cx: &'a Ctx, @@ -19,7 +20,7 @@ impl<'a> Widget for Layout<'a> { .constraints([Constraint::Min(0), Constraint::Length(1)]) .split(area); - Clear.render(area, buf); + widgets::Clear.render(area, buf); let help = &self.cx.help; Paragraph::new(help.keyword().unwrap_or_else(|| format!("{}.help", help.layer))) diff --git a/yazi-fm/src/input/input.rs b/yazi-fm/src/input/input.rs index 71590d10..bf779176 100644 --- a/yazi-fm/src/input/input.rs +++ b/yazi-fm/src/input/input.rs @@ -1,11 +1,13 @@ use std::ops::Range; use ansi_to_tui::IntoText; -use ratatui::{buffer::Buffer, layout::Rect, text::{Line, Text}, widgets::{Block, BorderType, Borders, Clear, Paragraph, Widget}}; +use ratatui::{buffer::Buffer, layout::Rect, text::{Line, Text}, widgets::{Block, BorderType, Borders, Paragraph, Widget}}; use yazi_config::THEME; use yazi_core::{input::InputMode, Ctx}; use yazi_shared::Term; +use crate::widgets; + pub(crate) struct Input<'a> { cx: &'a Ctx, } @@ -25,7 +27,7 @@ impl<'a> Widget for Input<'a> { Text::from(input.value()) }; - Clear.render(area, buf); + widgets::Clear.render(area, buf); Paragraph::new(value) .block( Block::new() diff --git a/yazi-fm/src/main.rs b/yazi-fm/src/main.rs index dcf86b74..0dbe25b4 100644 --- a/yazi-fm/src/main.rs +++ b/yazi-fm/src/main.rs @@ -12,6 +12,7 @@ mod select; mod signals; mod tasks; mod which; +mod widgets; use app::*; use executor::*; diff --git a/yazi-fm/src/select/select.rs b/yazi-fm/src/select/select.rs index 0fd3a43f..a7e94d2b 100644 --- a/yazi-fm/src/select/select.rs +++ b/yazi-fm/src/select/select.rs @@ -1,7 +1,9 @@ -use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, Clear, List, ListItem, Widget}}; +use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, List, ListItem, Widget}}; use yazi_config::THEME; use yazi_core::Ctx; +use crate::widgets; + pub(crate) struct Select<'a> { cx: &'a Ctx, } @@ -28,7 +30,7 @@ impl<'a> Widget for Select<'a> { }) .collect::>(); - Clear.render(area, buf); + widgets::Clear.render(area, buf); List::new(items) .block( Block::new() diff --git a/yazi-fm/src/tasks/clear.rs b/yazi-fm/src/tasks/clear.rs deleted file mode 100644 index 2aaa073e..00000000 --- a/yazi-fm/src/tasks/clear.rs +++ /dev/null @@ -1,19 +0,0 @@ -use ratatui::{buffer::Buffer, layout::Rect, widgets::{self, Widget}}; - -pub(super) struct Clear; - -impl Widget for Clear { - fn render(self, mut area: Rect, buf: &mut Buffer) { - if area.x > 0 { - area.x -= 1; - area.width += 2; - } - - if area.y > 0 { - area.y -= 1; - area.height += 2; - } - - widgets::Clear.render(area, buf) - } -} diff --git a/yazi-fm/src/tasks/layout.rs b/yazi-fm/src/tasks/layout.rs index 362a3fdb..7c07ab73 100644 --- a/yazi-fm/src/tasks/layout.rs +++ b/yazi-fm/src/tasks/layout.rs @@ -2,7 +2,7 @@ use ratatui::{buffer::Buffer, layout::{self, Alignment, Constraint, Direction, R use yazi_config::THEME; use yazi_core::{tasks::TASKS_PERCENT, Ctx}; -use super::Clear; +use crate::widgets; pub(crate) struct Layout<'a> { cx: &'a Ctx, @@ -36,7 +36,7 @@ impl<'a> Widget for Layout<'a> { fn render(self, area: Rect, buf: &mut Buffer) { let area = Self::area(area); - Clear.render(area, buf); + widgets::Clear.render(area, buf); let block = Block::new() .title({ let mut line = Line::from("Tasks"); diff --git a/yazi-fm/src/tasks/mod.rs b/yazi-fm/src/tasks/mod.rs index 712c459e..03520470 100644 --- a/yazi-fm/src/tasks/mod.rs +++ b/yazi-fm/src/tasks/mod.rs @@ -1,5 +1,3 @@ -mod clear; mod layout; -use clear::*; pub(super) use layout::*; diff --git a/yazi-fm/src/which/layout.rs b/yazi-fm/src/which/layout.rs index d4d2456b..d9f5f93f 100644 --- a/yazi-fm/src/which/layout.rs +++ b/yazi-fm/src/which/layout.rs @@ -1,8 +1,9 @@ -use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, widgets::{Block, Clear, Widget}}; +use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, widgets::{Block, Widget}}; use yazi_config::THEME; use yazi_core::Ctx; use super::Side; +use crate::widgets; pub(crate) struct Which<'a> { cx: &'a Ctx, @@ -38,7 +39,7 @@ impl Widget for Which<'_> { .constraints([Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)]) .split(area); - Clear.render(area, buf); + widgets::Clear.render(area, buf); Block::new().style(THEME.which.mask.into()).render(area, buf); Side::new(which.times, cands.0).render(chunks[0], buf); Side::new(which.times, cands.1).render(chunks[1], buf); diff --git a/yazi-fm/src/widgets/clear.rs b/yazi-fm/src/widgets/clear.rs new file mode 100644 index 00000000..9cbd2976 --- /dev/null +++ b/yazi-fm/src/widgets/clear.rs @@ -0,0 +1,22 @@ +use std::io::{stdout, BufWriter, Write}; + +use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget}; +use yazi_shared::Term; + +pub(crate) struct Clear; + +impl Widget for Clear { + fn render(self, area: Rect, buf: &mut Buffer) { + // let stdout = BufWriter::new(stdout().lock()); + // let s = " ".repeat(area.width as usize); + // _ = Term::move_lock(stdout, (0, 0), |stdout| { + // for y in area.top()..area.bottom() { + // Term::move_to(stdout, area.x, y)?; + // stdout.write_all(s.as_bytes())?; + // } + // Ok(()) + // }); + + ratatui::widgets::Clear.render(area, buf); + } +} diff --git a/yazi-fm/src/widgets/mod.rs b/yazi-fm/src/widgets/mod.rs new file mode 100644 index 00000000..cd6c2c51 --- /dev/null +++ b/yazi-fm/src/widgets/mod.rs @@ -0,0 +1,3 @@ +mod clear; + +pub(super) use clear::*;