From 854c142d2acd2687b3951ff7aa5a36a7b6ebd18a Mon Sep 17 00:00:00 2001 From: sxyazi Date: Thu, 22 Aug 2024 22:09:52 +0800 Subject: [PATCH] .. --- Cargo.toml | 2 +- yazi-config/preset/yazi.toml | 20 ++++---- yazi-config/src/popup/offset.rs | 2 +- yazi-config/src/popup/options.rs | 64 ++++++++++++++++--------- yazi-config/src/popup/origin.rs | 2 +- yazi-config/src/popup/position.rs | 4 +- yazi-core/src/confirm/commands/arrow.rs | 17 ++++--- yazi-core/src/confirm/commands/show.rs | 2 +- yazi-core/src/confirm/confirm.rs | 5 +- yazi-core/src/manager/manager.rs | 11 +++++ yazi-core/src/tab/tab.rs | 21 ++++++++ yazi-fm/src/completion/completion.rs | 2 +- yazi-fm/src/confirm/buttons.rs | 13 +++++ yazi-fm/src/confirm/confirm.rs | 55 +++++++-------------- yazi-fm/src/confirm/content.rs | 22 +++++++++ yazi-fm/src/confirm/list.rs | 44 +++++++++++++++++ yazi-fm/src/confirm/mod.rs | 6 +++ yazi-fm/src/context.rs | 19 +------- yazi-fm/src/executor.rs | 6 +-- yazi-fm/src/input/input.rs | 2 +- yazi-fm/src/select/select.rs | 2 +- yazi-fs/src/folder.rs | 10 ---- yazi-plugin/src/utils/layer.rs | 27 ++++++----- yazi-proxy/src/confirm.rs | 1 + 24 files changed, 227 insertions(+), 132 deletions(-) create mode 100644 yazi-fm/src/confirm/buttons.rs create mode 100644 yazi-fm/src/confirm/content.rs create mode 100644 yazi-fm/src/confirm/list.rs diff --git a/Cargo.toml b/Cargo.toml index 39ac725b..3648a468 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ libc = "0.2.158" md-5 = "0.10.6" mlua = { version = "0.9.9", features = [ "lua54", "serialize", "macros", "async" ] } parking_lot = "0.12.3" -ratatui = "0.27.0" +ratatui = { version = "0.27.0", features = [ "unstable-rendered-line-info" ] } regex = "1.10.6" scopeguard = "1.2.0" serde = { version = "1.0.208", features = [ "derive" ] } diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index 9c1e99f3..06d75096 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -170,25 +170,25 @@ shell_offset = [ 0, 2, 50, 3 ] [confirm] # trash trash_title = "Trash {n} selected file{s}?" -trash_origin = "top-center" -trash_offset = [ 0, 5, 70, 20 ] +trash_origin = "center" +trash_offset = [ 0, 0, 70, 20 ] # delete delete_title = "Permanently delete {n} selected file{s}?" -delete_origin = "top-center" -delete_offset = [ 0, 5, 70, 20 ] +delete_origin = "center" +delete_offset = [ 0, 0, 70, 20 ] # overwrite overwrite_title = "Overwrite file?" -overwrite_content = "Will overwrite the following file:\n{url}" -overwrite_origin = "top-center" -overwrite_offset = [ 0, 2, 50, 20 ] +overwrite_content = "Will overwrite the following file:" +overwrite_origin = "center" +overwrite_offset = [ 0, 0, 50, 20 ] # quit quit_title = "Quit?" -quit_content = "The following task is still running, are you sure you want to quit?\n{tasks}" -quit_origin = "top-center" -quit_offset = [ 0, 2, 50, 20 ] +quit_content = "The following task is still running, are you sure you want to quit?" +quit_origin = "center" +quit_offset = [ 0, 0, 50, 20 ] [select] open_title = "Open with:" diff --git a/yazi-config/src/popup/offset.rs b/yazi-config/src/popup/offset.rs index 1a36860b..c81e5ddd 100644 --- a/yazi-config/src/popup/offset.rs +++ b/yazi-config/src/popup/offset.rs @@ -1,7 +1,7 @@ use anyhow::bail; use serde::Deserialize; -#[derive(Clone, Copy, Default, Deserialize)] +#[derive(Clone, Copy, Debug, Default, Deserialize)] #[serde(try_from = "Vec")] pub struct Offset { pub x: i16, diff --git a/yazi-config/src/popup/options.rs b/yazi-config/src/popup/options.rs index d3cd6590..6e54c247 100644 --- a/yazi-config/src/popup/options.rs +++ b/yazi-config/src/popup/options.rs @@ -1,6 +1,7 @@ +use ratatui::{text::Text, widgets::{Paragraph, Wrap}}; use yazi_shared::fs::Url; -use super::{Offset, Position}; +use super::{Offset, Origin, Position}; use crate::{CONFIRM, INPUT, SELECT}; #[derive(Default)] @@ -24,8 +25,9 @@ pub struct SelectCfg { #[derive(Default)] pub struct ConfirmCfg { pub title: String, - pub content: String, pub position: Position, + pub content: Paragraph<'static>, + pub list: Paragraph<'static>, } impl InputCfg { @@ -103,36 +105,54 @@ impl InputCfg { } impl ConfirmCfg { - pub fn trash(urls: &[yazi_shared::fs::Url]) -> Self { + fn new( + title: String, + (origin, offset): (Origin, Offset), + content: Option>, + list: Option>, + ) -> Self { Self { - title: Self::replace_number(&CONFIRM.trash_title, urls.len(), usize::MAX), - position: Position::new(CONFIRM.trash_origin, CONFIRM.trash_offset), - content: urls.iter().map(ToString::to_string).collect::>().join("\n"), + title, + position: Position::new(origin, offset), + content: content.map(|c| Paragraph::new(c).wrap(Wrap { trim: false })).unwrap_or_default(), + list: list.map(|l| Paragraph::new(l).wrap(Wrap { trim: false })).unwrap_or_default(), } } + pub fn trash(urls: &[yazi_shared::fs::Url]) -> Self { + Self::new( + Self::replace_number(&CONFIRM.trash_title, urls.len(), usize::MAX), + (CONFIRM.trash_origin, CONFIRM.trash_offset), + None, + Some(urls.iter().map(ToString::to_string).collect()), + ) + } + pub fn delete(urls: &[yazi_shared::fs::Url]) -> Self { - Self { - title: Self::replace_number(&CONFIRM.delete_title, urls.len(), usize::MAX), - position: Position::new(CONFIRM.delete_origin, CONFIRM.delete_offset), - content: urls.iter().map(ToString::to_string).collect::>().join("\n"), - } + Self::new( + Self::replace_number(&CONFIRM.delete_title, urls.len(), usize::MAX), + (CONFIRM.delete_origin, CONFIRM.delete_offset), + None, + Some(urls.iter().map(ToString::to_string).collect()), + ) } pub fn overwrite(url: &Url) -> Self { - Self { - title: CONFIRM.overwrite_title.to_owned(), - content: CONFIRM.overwrite_content.replace("{url}", &url.to_string()), - position: Position::new(CONFIRM.overwrite_origin, CONFIRM.overwrite_offset), - } + Self::new( + CONFIRM.overwrite_title.to_owned(), + (CONFIRM.overwrite_origin, CONFIRM.overwrite_offset), + Some(Text::raw(&CONFIRM.overwrite_content)), + Some(url.to_string().into()), + ) } - pub fn quit(tasks: Vec) -> Self { - Self { - title: Self::replace_number(&CONFIRM.quit_title, tasks.len(), 10), - content: CONFIRM.quit_content.replace("{tasks}", &tasks.join("\n")), - position: Position::new(CONFIRM.quit_origin, CONFIRM.quit_offset), - } + pub fn quit(left: Vec) -> Self { + Self::new( + Self::replace_number(&CONFIRM.quit_title, left.len(), 10), + (CONFIRM.quit_origin, CONFIRM.quit_offset), + Some(Text::raw(&CONFIRM.quit_content)), + Some(left.into_iter().collect()), + ) } fn replace_number(tpl: &str, n: usize, max: usize) -> String { diff --git a/yazi-config/src/popup/origin.rs b/yazi-config/src/popup/origin.rs index 70231c88..39ffa1d6 100644 --- a/yazi-config/src/popup/origin.rs +++ b/yazi-config/src/popup/origin.rs @@ -3,7 +3,7 @@ use std::{fmt::Display, str::FromStr}; use anyhow::bail; use serde::Deserialize; -#[derive(Clone, Copy, Default, Deserialize, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq)] #[serde(try_from = "String")] pub enum Origin { #[default] diff --git a/yazi-config/src/popup/position.rs b/yazi-config/src/popup/position.rs index d8974947..b37a2e0a 100644 --- a/yazi-config/src/popup/position.rs +++ b/yazi-config/src/popup/position.rs @@ -3,7 +3,7 @@ use ratatui::layout::Rect; use super::{Offset, Origin}; -#[derive(Clone, Copy, Default)] +#[derive(Clone, Copy, Debug, Default)] pub struct Position { pub origin: Origin, pub offset: Offset, @@ -30,7 +30,7 @@ impl Position { let max_y = rows.saturating_sub(height); let new_y = match self.origin { TopLeft | TopCenter | TopRight => y.clamp(0, max_y as i16) as u16, - Center => (max_y / 2).saturating_sub(height / 2).saturating_add_signed(y).clamp(0, max_y), + Center => (rows / 2).saturating_sub(height / 2).saturating_add_signed(y).clamp(0, max_y), BottomLeft | BottomCenter | BottomRight => max_y.saturating_add_signed(y).clamp(0, max_y), Hovered => unreachable!(), }; diff --git a/yazi-core/src/confirm/commands/arrow.rs b/yazi-core/src/confirm/commands/arrow.rs index 23a913f2..fe5ae899 100644 --- a/yazi-core/src/confirm/commands/arrow.rs +++ b/yazi-core/src/confirm/commands/arrow.rs @@ -1,6 +1,6 @@ use yazi_shared::{event::{Cmd, Data}, render}; -use crate::confirm::Confirm; +use crate::{confirm::Confirm, manager::Manager}; pub struct Opt { step: isize, @@ -11,13 +11,14 @@ impl From for Opt { } impl Confirm { - fn next(&mut self, step: usize) { - if self.lines == 0 { + fn next(&mut self, step: usize, width: u16) { + let height = self.list.line_count(width); + if height == 0 { return; } let old = self.offset; - self.offset = (self.offset + step).min(self.lines - 1); + self.offset = (self.offset + step).min(height - 1); render!(old != self.offset); } @@ -29,8 +30,12 @@ impl Confirm { render!(old != self.offset); } - pub fn arrow(&mut self, opt: impl Into) { + pub fn arrow(&mut self, opt: impl Into, manager: &Manager) { let opt = opt.into() as Opt; - if opt.step > 0 { self.next(opt.step as usize) } else { self.prev(opt.step.unsigned_abs()) } + if opt.step > 0 { + self.next(opt.step as usize, manager.area(self.position).width) + } else { + self.prev(opt.step.unsigned_abs()) + } } } diff --git a/yazi-core/src/confirm/commands/show.rs b/yazi-core/src/confirm/commands/show.rs index 7f1f5faa..5ec84803 100644 --- a/yazi-core/src/confirm/commands/show.rs +++ b/yazi-core/src/confirm/commands/show.rs @@ -26,7 +26,7 @@ impl Confirm { self.close(false); self.title = opt.cfg.title; self.content = opt.cfg.content; - self.lines = self.content.lines().count(); + self.list = opt.cfg.list; self.offset = 0; self.position = opt.cfg.position; diff --git a/yazi-core/src/confirm/confirm.rs b/yazi-core/src/confirm/confirm.rs index 35f67e62..fe7649c4 100644 --- a/yazi-core/src/confirm/confirm.rs +++ b/yazi-core/src/confirm/confirm.rs @@ -1,11 +1,12 @@ +use ratatui::widgets::Paragraph; use tokio::sync::oneshot::Sender; use yazi_config::popup::Position; #[derive(Default)] pub struct Confirm { pub title: String, - pub content: String, - pub lines: usize, + pub content: Paragraph<'static>, + pub list: Paragraph<'static>, pub offset: usize, pub position: Position, diff --git a/yazi-core/src/manager/manager.rs b/yazi-core/src/manager/manager.rs index 4214e1bf..0b5545f8 100644 --- a/yazi-core/src/manager/manager.rs +++ b/yazi-core/src/manager/manager.rs @@ -1,5 +1,8 @@ use std::collections::HashMap; +use ratatui::layout::Rect; +use yazi_adapter::Dimension; +use yazi_config::popup::{Origin, Position}; use yazi_fs::Folder; use yazi_shared::fs::{File, Url}; @@ -25,6 +28,14 @@ impl Manager { } } + pub fn area(&self, pos: Position) -> Rect { + if pos.origin == Origin::Hovered { + self.active().hovered_rect_based(pos) + } else { + pos.rect(Dimension::available()) + } + } + pub fn shutdown(&mut self) { self.tabs.iter_mut().for_each(|t| t.shutdown()); } } diff --git a/yazi-core/src/tab/tab.rs b/yazi-core/src/tab/tab.rs index c6c553bf..0df8a13a 100644 --- a/yazi-core/src/tab/tab.rs +++ b/yazi-core/src/tab/tab.rs @@ -1,7 +1,10 @@ use std::{collections::HashMap, iter}; use anyhow::Result; +use ratatui::layout::Rect; use tokio::task::JoinHandle; +use yazi_adapter::Dimension; +use yazi_config::{popup::{Origin, Position}, LAYOUT}; use yazi_fs::{Folder, FolderStage}; use yazi_shared::{fs::Url, render}; @@ -35,6 +38,24 @@ impl Tab { impl Tab { // --- Current + pub fn hovered_rect(&self) -> Option { + let y = self.current.files.position(&self.current.hovered()?.url)? - self.current.offset; + + let mut rect = LAYOUT.load().current; + rect.y = rect.y.saturating_sub(1) + y as u16; + rect.height = 1; + Some(rect) + } + + pub fn hovered_rect_based(&self, pos: Position) -> Rect { + let ws = Dimension::available(); + if let Some(r) = self.hovered_rect() { + Position::sticky(ws, r, pos.offset) + } else { + Position::new(Origin::TopCenter, pos.offset).rect(ws) + } + } + pub fn selected_or_hovered(&self, reorder: bool) -> Box + '_> { if self.selected.is_empty() { Box::new(self.current.hovered().map(|h| vec![&h.url]).unwrap_or_default().into_iter()) diff --git a/yazi-fm/src/completion/completion.rs b/yazi-fm/src/completion/completion.rs index 75d2b6bb..1ee5cadd 100644 --- a/yazi-fm/src/completion/completion.rs +++ b/yazi-fm/src/completion/completion.rs @@ -40,7 +40,7 @@ impl<'a> Widget for Completion<'a> { }) .collect(); - let input_area = self.cx.area(&self.cx.input.position); + let input_area = self.cx.manager.area(self.cx.input.position); let mut area = Position::sticky(Dimension::available(), input_area, Offset { x: 1, y: 0, diff --git a/yazi-fm/src/confirm/buttons.rs b/yazi-fm/src/confirm/buttons.rs new file mode 100644 index 00000000..13997eaf --- /dev/null +++ b/yazi-fm/src/confirm/buttons.rs @@ -0,0 +1,13 @@ +use ratatui::{buffer::Buffer, layout::{Constraint, Rect}, style::Stylize, text::Span, widgets::{Paragraph, Widget}}; + +pub(crate) struct Buttons; + +impl Widget for Buttons { + fn render(self, area: Rect, buf: &mut Buffer) { + let chunks = + ratatui::layout::Layout::horizontal([Constraint::Fill(1), Constraint::Fill(1)]).split(area); + + Paragraph::new(Span::raw(" [Y]es ").reversed()).centered().render(chunks[0], buf); + Paragraph::new(Span::raw(" (N)o ")).centered().render(chunks[1], buf); + } +} diff --git a/yazi-fm/src/confirm/confirm.rs b/yazi-fm/src/confirm/confirm.rs index cfeded61..450a3f20 100644 --- a/yazi-fm/src/confirm/confirm.rs +++ b/yazi-fm/src/confirm/confirm.rs @@ -1,5 +1,4 @@ -use ratatui::{buffer::Buffer, layout::{Constraint, Layout, Margin, Rect}, text::Line, widgets::{Block, BorderType, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, Widget, Wrap}}; -use yazi_config::THEME; +use ratatui::{buffer::Buffer, layout::{Alignment, Constraint, Layout, Margin, Rect}, style::{Style, Stylize}, text::Line, widgets::{Block, BorderType, Widget}}; use crate::Ctx; @@ -10,55 +9,33 @@ pub(crate) struct Confirm<'a> { impl<'a> Confirm<'a> { pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } } + impl<'a> Widget for Confirm<'a> { fn render(self, _win: Rect, buf: &mut Buffer) { let confirm = &self.cx.confirm; - let area = self.cx.area(&confirm.position); + let area = self.cx.manager.area(confirm.position); yazi_plugin::elements::Clear::default().render(area, buf); Block::bordered() .border_type(BorderType::Rounded) - .border_style(THEME.input.border) - .title(Line::styled(&confirm.title, THEME.input.title)) + .border_style(Style::new().blue()) + .title(Line::styled(&confirm.title, Style::new().blue())) + .title_alignment(Alignment::Center) .render(area, buf); - let popup_layout = - Layout::vertical(vec![Constraint::Percentage(70), Constraint::Percentage(30)]) - .vertical_margin(1) - .horizontal_margin(2) - .split(area); + let content = confirm.content.clone(); + let content_height = content.line_count(area.width).saturating_add(1) as u16; - let button_layout = Layout::horizontal(vec![ - Constraint::Percentage(10), - Constraint::Percentage(30), - Constraint::Percentage(20), - Constraint::Percentage(30), - Constraint::Percentage(10), + let chunks = Layout::vertical([ + Constraint::Length(if content_height == 1 { 0 } else { content_height }), + Constraint::Fill(1), + Constraint::Length(1), ]) - .vertical_margin(1) - .split(popup_layout[1]); + .split(area.inner(Margin::new(0, 1))); - Paragraph::new(confirm.content.lines().map(Line::from).collect::>()) - .block(Block::bordered().border_type(BorderType::Rounded).border_style(THEME.input.border)) - .scroll((confirm.offset as u16, 0)) - .wrap(Wrap { trim: false }) - .render(popup_layout[0], buf); - - const BORDER_SIZE: usize = 2; - if confirm.lines > popup_layout[0].as_size().height as usize - BORDER_SIZE { - let mut scrollbar_state = - ScrollbarState::new(confirm.content.lines().collect::>().len()) - .position(confirm.offset); - - Scrollbar::new(ScrollbarOrientation::VerticalRight).render( - popup_layout[0].inner(Margin { vertical: 1, horizontal: 0 }), - buf, - &mut scrollbar_state, - ); - } - - Paragraph::new("[Y]es").block(Block::bordered()).centered().render(button_layout[1], buf); - Paragraph::new("(N)o").block(Block::bordered()).centered().render(button_layout[3], buf); + super::Content::new(content).render(chunks[0], buf); + super::List::new(self.cx).render(chunks[1], buf); + super::Buttons.render(chunks[2], buf); } } diff --git a/yazi-fm/src/confirm/content.rs b/yazi-fm/src/confirm/content.rs new file mode 100644 index 00000000..c1a553d4 --- /dev/null +++ b/yazi-fm/src/confirm/content.rs @@ -0,0 +1,22 @@ +use ratatui::{buffer::Buffer, layout::{Margin, Rect}, style::{Style, Stylize}, widgets::{Block, Borders, Paragraph, Widget}}; + +pub(crate) struct Content<'a> { + p: Paragraph<'a>, +} + +impl<'a> Content<'a> { + pub(crate) fn new(p: Paragraph<'a>) -> Self { Self { p } } +} + +impl<'a> Widget for Content<'a> { + fn render(self, area: Rect, buf: &mut Buffer) { + // Content area + let inner = area.inner(Margin::new(1, 0)); + + // Bottom border + let block = Block::new().borders(Borders::BOTTOM).border_style(Style::new().blue()); + block.clone().render(area.inner(Margin::new(1, 0)), buf); + + self.p.alignment(ratatui::layout::Alignment::Center).block(block).render(inner, buf); + } +} diff --git a/yazi-fm/src/confirm/list.rs b/yazi-fm/src/confirm/list.rs new file mode 100644 index 00000000..22709c05 --- /dev/null +++ b/yazi-fm/src/confirm/list.rs @@ -0,0 +1,44 @@ +use ratatui::{buffer::Buffer, layout::{Margin, Rect}, style::{Style, Stylize}, widgets::{Block, Borders, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, Widget, Wrap}}; + +use crate::Ctx; + +pub(crate) struct List<'a> { + cx: &'a Ctx, +} + +impl<'a> List<'a> { + pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } +} + +impl<'a> Widget for List<'a> { + fn render(self, mut area: Rect, buf: &mut Buffer) { + // List content area + let inner = area.inner(Margin::new(2, 0)); + + // Bottom border + let block = Block::new().borders(Borders::BOTTOM).border_style(Style::new().blue()); + block.clone().render(area.inner(Margin::new(1, 0)), buf); + + let list = self + .cx + .confirm + .list + .clone() + .scroll((self.cx.confirm.offset as u16, 0)) + .block(block) + .wrap(Wrap { trim: false }); + + // Vertical scrollbar + let lines = list.line_count(inner.width); + if lines >= inner.height as usize { + area.height = area.height.saturating_sub(1); + Scrollbar::new(ScrollbarOrientation::VerticalRight).render( + area, + buf, + &mut ScrollbarState::new(lines).position(self.cx.confirm.offset), + ); + } + + list.render(inner, buf); + } +} diff --git a/yazi-fm/src/confirm/mod.rs b/yazi-fm/src/confirm/mod.rs index f3ce5fd6..567a133e 100644 --- a/yazi-fm/src/confirm/mod.rs +++ b/yazi-fm/src/confirm/mod.rs @@ -1,3 +1,9 @@ +mod buttons; mod confirm; +mod content; +mod list; +use buttons::*; pub(super) use confirm::*; +use content::*; +use list::*; diff --git a/yazi-fm/src/context.rs b/yazi-fm/src/context.rs index 2f2cf4d7..c97336e2 100644 --- a/yazi-fm/src/context.rs +++ b/yazi-fm/src/context.rs @@ -1,6 +1,4 @@ use ratatui::layout::Rect; -use yazi_adapter::Dimension; -use yazi_config::popup::{Origin, Position}; use yazi_core::{completion::Completion, confirm::Confirm, help::Help, input::Input, manager::Manager, notify::Notify, select::Select, tasks::Tasks, which::Which}; pub struct Ctx { @@ -30,25 +28,10 @@ impl Ctx { } } - pub fn area(&self, position: &Position) -> Rect { - let ws = Dimension::available(); - if position.origin != Origin::Hovered { - return position.rect(ws); - } - - if let Some(r) = - self.manager.hovered().and_then(|h| self.manager.current().rect_current(&h.url)) - { - Position::sticky(ws, r, position.offset) - } else { - Position::new(Origin::TopCenter, position.offset).rect(ws) - } - } - #[inline] pub fn cursor(&self) -> Option<(u16, u16)> { if self.input.visible { - let Rect { x, y, .. } = self.area(&self.input.position); + let Rect { x, y, .. } = self.manager.area(self.input.position); return Some((x + 1 + self.input.cursor(), y + 1)); } if let Some((x, y)) = self.help.cursor() { diff --git a/yazi-fm/src/executor.rs b/yazi-fm/src/executor.rs index 486b5431..5f2bc339 100644 --- a/yazi-fm/src/executor.rs +++ b/yazi-fm/src/executor.rs @@ -252,14 +252,14 @@ impl<'a> Executor<'a> { fn confirm(&mut self, cmd: Cmd) { macro_rules! on { - ($name:ident) => { + ($name:ident $(,$args:expr)*) => { if cmd.name == stringify!($name) { - return self.app.cx.confirm.$name(cmd); + return self.app.cx.confirm.$name(cmd, $($args),*); } }; } - on!(arrow); + on!(arrow, &self.app.cx.manager); on!(show); on!(close); } diff --git a/yazi-fm/src/input/input.rs b/yazi-fm/src/input/input.rs index 9a9ee778..f82dea06 100644 --- a/yazi-fm/src/input/input.rs +++ b/yazi-fm/src/input/input.rs @@ -34,7 +34,7 @@ impl<'a> Input<'a> { impl<'a> Widget for Input<'a> { fn render(self, win: Rect, buf: &mut Buffer) { let input = &self.cx.input; - let area = self.cx.area(&input.position); + let area = self.cx.manager.area(input.position); yazi_plugin::elements::Clear::default().render(area, buf); Paragraph::new(self.highlighted_value().unwrap_or_else(|_| Line::from(input.value()))) diff --git a/yazi-fm/src/select/select.rs b/yazi-fm/src/select/select.rs index 9bbf2997..2fc04a45 100644 --- a/yazi-fm/src/select/select.rs +++ b/yazi-fm/src/select/select.rs @@ -14,7 +14,7 @@ impl<'a> Select<'a> { impl<'a> Widget for Select<'a> { fn render(self, _: Rect, buf: &mut Buffer) { let select = &self.cx.select; - let area = self.cx.area(&select.position); + let area = self.cx.manager.area(select.position); let items: Vec<_> = select .window() diff --git a/yazi-fs/src/folder.rs b/yazi-fs/src/folder.rs index 8b8380fe..d6be6652 100644 --- a/yazi-fs/src/folder.rs +++ b/yazi-fs/src/folder.rs @@ -1,6 +1,5 @@ use std::mem; -use ratatui::layout::Rect; use yazi_config::{LAYOUT, MANAGER}; use yazi_proxy::ManagerProxy; use yazi_shared::fs::{Cha, File, FilesOp, Url}; @@ -151,13 +150,4 @@ impl Folder { let end = ((page + 2) * limit).min(len); &self.files[start..end] } - - pub fn rect_current(&self, url: &Url) -> Option { - let y = self.files.position(url)? - self.offset; - - let mut rect = LAYOUT.load().current; - rect.y = rect.y.saturating_sub(1) + y as u16; - rect.height = 1; - Some(rect) - } } diff --git a/yazi-plugin/src/utils/layer.rs b/yazi-plugin/src/utils/layer.rs index 0b0f0f85..3af6c71d 100644 --- a/yazi-plugin/src/utils/layer.rs +++ b/yazi-plugin/src/utils/layer.rs @@ -3,8 +3,8 @@ use std::{str::FromStr, time::Duration}; use mlua::{ExternalError, ExternalResult, IntoLuaMulti, Lua, Table, Value}; use tokio::sync::mpsc; use tokio_stream::wrappers::UnboundedReceiverStream; -use yazi_config::{keymap::{Control, Key}, popup::{ConfirmCfg, InputCfg}}; -use yazi_proxy::{AppProxy, ConfirmProxy, InputProxy}; +use yazi_config::{keymap::{Control, Key}, popup::InputCfg}; +use yazi_proxy::{AppProxy, InputProxy}; use yazi_shared::{emit, event::Cmd, Debounce, Layer}; use super::Utils; @@ -86,17 +86,18 @@ impl Utils { })?, )?; - ya.raw_set( - "confirm", - lua.create_async_function(|_, t: Table| async move { - let result = ConfirmProxy::show(ConfirmCfg { - title: t.raw_get("title")?, - content: t.raw_get("content")?, - position: Position::try_from(t.raw_get::<_, Table>("position")?)?.into(), - }); - Ok(result.await) - })?, - )?; + // TODO: redesign the confirm API + // ya.raw_set( + // "confirm", + // lua.create_async_function(|_, t: Table| async move { + // let result = ConfirmProxy::show(ConfirmCfg { + // title: t.raw_get("title")?, + // content: t.raw_get("content")?, + // position: Position::try_from(t.raw_get::<_, Table>("position")?)?.into(), + // }); + // Ok(result.await) + // })?, + // )?; ya.raw_set( "notify", diff --git a/yazi-proxy/src/confirm.rs b/yazi-proxy/src/confirm.rs index 3e27da9e..60ecd93a 100644 --- a/yazi-proxy/src/confirm.rs +++ b/yazi-proxy/src/confirm.rs @@ -8,6 +8,7 @@ impl ConfirmProxy { #[inline] pub async fn show(cfg: ConfirmCfg) -> bool { Self::show_rx(cfg).await.unwrap_or(false) } + #[inline] pub fn show_rx(cfg: ConfirmCfg) -> oneshot::Receiver { let (tx, rx) = oneshot::channel(); emit!(Call(Cmd::new("show").with_any("tx", tx).with_any("cfg", cfg), Layer::Confirm));