From c95b613ed579bfae8dbfa36a3615f77b5998b7ba Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 15 Nov 2023 12:27:23 +0800 Subject: [PATCH] .. --- yazi-config/preset/yazi.toml | 15 +++++ yazi-config/src/popup/input.rs | 33 ++++++++-- yazi-config/src/popup/mod.rs | 2 + yazi-config/src/popup/options.rs | 63 ++++++++++++++++++ yazi-config/src/popup/position.rs | 9 ++- yazi-config/src/popup/select.rs | 1 + yazi-core/src/context.rs | 3 +- yazi-core/src/event.rs | 4 +- yazi-core/src/input/input.rs | 5 +- yazi-core/src/input/mod.rs | 2 - yazi-core/src/input/option.rs | 83 ------------------------ yazi-core/src/lib.rs | 2 - yazi-core/src/manager/commands/create.rs | 14 ++-- yazi-core/src/manager/commands/open.rs | 12 ++-- yazi-core/src/manager/commands/quit.rs | 2 +- yazi-core/src/manager/commands/rename.rs | 16 ++--- yazi-core/src/position.rs | 50 -------------- yazi-core/src/select/mod.rs | 2 - yazi-core/src/select/option.rs | 59 ----------------- yazi-core/src/select/select.rs | 4 +- yazi-core/src/tab/commands/cd.rs | 10 +-- yazi-core/src/tab/commands/find.rs | 8 +-- yazi-core/src/tab/commands/search.rs | 8 +-- yazi-core/src/tab/commands/shell.rs | 11 +--- yazi-core/src/tasks/tasks.rs | 14 ++-- 25 files changed, 154 insertions(+), 278 deletions(-) create mode 100644 yazi-config/src/popup/options.rs delete mode 100644 yazi-core/src/input/option.rs delete mode 100644 yazi-core/src/position.rs delete mode 100644 yazi-core/src/select/option.rs diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index 0ed62f4e..794a9130 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -90,6 +90,16 @@ rename_title = "Rename:" rename_position = "hovered" rename_offset = [ 0, 1, 50, 3 ] +# trash +trash_title = "Move {n} selected file{s} to trash? (y/N)" +trash_position = "top-center" +trash_offset = [ 0, 2, 50, 3 ] + +# delete +delete_title = "Delete {n} selected file{s} permanently? (y/N)" +delete_position = "top-center" +delete_offset = [ 0, 2, 50, 3 ] + # find find_title = [ "Find previous:", "Find next:" ] find_position = "top-center" @@ -107,6 +117,11 @@ shell_position = "top-center" shell_offset = [ 0, 2, 50, 3 ] shell_highlight = true +# overwrite +overwrite_title = "Overwrite an existing file? (y/N)" +overwrite_position = "top-center" +overwrite_offset = [ 0, 2, 50, 3 ] + [select] open_title = "Open with:" open_position = "hovered" diff --git a/yazi-config/src/popup/input.rs b/yazi-config/src/popup/input.rs index c0d98717..90aeb312 100644 --- a/yazi-config/src/popup/input.rs +++ b/yazi-config/src/popup/input.rs @@ -6,23 +6,44 @@ use crate::MERGED_YAZI; #[derive(Debug, Deserialize)] pub struct Input { // cd - pub cd_position: Position, - pub cd_offset: Offset, + pub cd_title: String, + pub cd_position: Position, + pub cd_offset: Offset, + // create + pub create_title: String, pub create_position: Position, pub create_offset: Offset, + // rename + pub rename_title: String, pub rename_position: Position, pub rename_offset: Offset, + + // trash + pub trash_title: String, + pub trash_position: Position, + pub trash_offset: Offset, + + // delete + pub delete_title: String, + pub delete_position: Position, + pub delete_offset: Offset, + // find - pub find_position: Position, - pub find_offset: Offset, + pub find_title: [String; 2], + pub find_position: Position, + pub find_offset: Offset, + // search + pub search_title: String, pub search_position: Position, pub search_offset: Offset, + // shell - pub shell_position: Position, - pub shell_offset: Offset, + pub shell_title: [String; 2], + pub shell_position: Position, + pub shell_offset: Offset, } impl Default for Input { diff --git a/yazi-config/src/popup/mod.rs b/yazi-config/src/popup/mod.rs index dc47ddd4..4d08ce5e 100644 --- a/yazi-config/src/popup/mod.rs +++ b/yazi-config/src/popup/mod.rs @@ -1,7 +1,9 @@ mod input; +mod options; mod position; mod select; pub use input::*; +pub use options::*; pub use position::*; pub use select::*; diff --git a/yazi-config/src/popup/options.rs b/yazi-config/src/popup/options.rs new file mode 100644 index 00000000..6427f66e --- /dev/null +++ b/yazi-config/src/popup/options.rs @@ -0,0 +1,63 @@ +use super::Position; + +pub struct InputOpt { + pub title: String, + pub value: String, + pub position: Position, + pub realtime: bool, + pub completion: bool, + pub highlight: bool, +} + +pub struct SelectOpt { + pub title: String, + pub items: Vec, + pub position: Position, +} + +impl InputOpt { + #[inline] + pub fn cd() -> Self { todo!() } + + #[inline] + pub fn create() -> Self { todo!() } + + #[inline] + pub fn rename() -> Self { todo!() } + + #[inline] + pub fn trash(n: usize) -> Self { todo!() } + + #[inline] + pub fn delete(n: usize) -> Self { todo!() } + + #[inline] + pub fn find(prev: bool) -> Self { todo!() } + + #[inline] + pub fn search() -> Self { todo!() } + + #[inline] + + pub fn shell(block: bool) -> Self { todo!() } + + #[inline] + pub fn overwrite() -> Self { todo!() } + + #[inline] + pub fn with_value(mut self, value: impl Into) -> Self { + self.value = value.into(); + self + } +} + +impl SelectOpt { + #[inline] + pub fn open() -> Self { todo!() } + + #[inline] + pub fn with_items(mut self, items: Vec) -> Self { + self.items = items; + self + } +} diff --git a/yazi-config/src/popup/position.rs b/yazi-config/src/popup/position.rs index 9de51f57..a901f120 100644 --- a/yazi-config/src/popup/position.rs +++ b/yazi-config/src/popup/position.rs @@ -1,7 +1,7 @@ use anyhow::bail; use serde::{Deserialize, Serialize}; -#[derive(Debug, Deserialize)] +#[derive(Debug, Default, Deserialize)] pub enum Position { #[serde(rename = "top-left")] TopLeft, @@ -9,14 +9,17 @@ pub enum Position { TopCenter, #[serde(rename = "top-right")] TopRight, - #[serde(rename = "center")] - Center, + #[serde(rename = "bottom-left")] BottomLeft, #[serde(rename = "bottom-center")] BottomCenter, #[serde(rename = "bottom-right")] BottomRight, + + #[serde(rename = "center")] + #[default] + Center, #[serde(rename = "hovered")] Hovered, } diff --git a/yazi-config/src/popup/select.rs b/yazi-config/src/popup/select.rs index 8f0da248..ad5dd86a 100644 --- a/yazi-config/src/popup/select.rs +++ b/yazi-config/src/popup/select.rs @@ -6,6 +6,7 @@ use crate::MERGED_YAZI; #[derive(Debug, Deserialize)] pub struct Select { // open + pub open_title: String, pub open_position: Position, pub open_offset: Offset, } diff --git a/yazi-core/src/context.rs b/yazi-core/src/context.rs index 78c8ab66..cd41965e 100644 --- a/yazi-core/src/context.rs +++ b/yazi-core/src/context.rs @@ -1,8 +1,9 @@ use crossterm::terminal::WindowSize; use ratatui::prelude::Rect; +use yazi_config::popup::Position; use yazi_shared::Term; -use crate::{completion::Completion, help::Help, input::Input, manager::Manager, select::Select, tasks::Tasks, which::Which, Offset, Position}; +use crate::{completion::Completion, help::Help, input::Input, manager::Manager, select::Select, tasks::Tasks, which::Which}; pub struct Ctx { pub manager: Manager, diff --git a/yazi-core/src/event.rs b/yazi-core/src/event.rs index 82baeb99..5ab91cff 100644 --- a/yazi-core/src/event.rs +++ b/yazi-core/src/event.rs @@ -3,10 +3,10 @@ use std::{collections::BTreeMap, ffi::OsString}; use anyhow::Result; use crossterm::event::KeyEvent; use tokio::sync::{mpsc::{self, UnboundedSender}, oneshot}; -use yazi_config::{keymap::{Exec, KeymapLayer}, open::Opener}; +use yazi_config::{keymap::{Exec, KeymapLayer}, open::Opener, popup::{InputOpt, SelectOpt}}; use yazi_shared::{InputError, RoCell, Url}; -use super::{files::FilesOp, input::InputOpt, select::SelectOpt}; +use super::files::FilesOp; use crate::{preview::PreviewLock, tasks::TasksProgress}; static TX: RoCell> = RoCell::new(); diff --git a/yazi-core/src/input/input.rs b/yazi-core/src/input/input.rs index 2a019c79..52b437b7 100644 --- a/yazi-core/src/input/input.rs +++ b/yazi-core/src/input/input.rs @@ -2,10 +2,11 @@ use std::ops::Range; use tokio::sync::mpsc::UnboundedSender; use unicode_width::UnicodeWidthStr; +use yazi_config::popup::{InputOpt, Position}; use yazi_shared::InputError; -use super::{mode::InputMode, op::InputOp, InputOpt, InputSnap, InputSnaps}; -use crate::{external, Position}; +use super::{mode::InputMode, op::InputOp, InputSnap, InputSnaps}; +use crate::external; #[derive(Default)] pub struct Input { diff --git a/yazi-core/src/input/mod.rs b/yazi-core/src/input/mod.rs index 328d8295..bd00b9e5 100644 --- a/yazi-core/src/input/mod.rs +++ b/yazi-core/src/input/mod.rs @@ -2,7 +2,6 @@ mod commands; mod input; mod mode; mod op; -mod option; mod shell; mod snap; mod snaps; @@ -10,6 +9,5 @@ mod snaps; pub use input::*; pub use mode::*; use op::*; -pub use option::*; use snap::*; use snaps::*; diff --git a/yazi-core/src/input/option.rs b/yazi-core/src/input/option.rs deleted file mode 100644 index 0195f93f..00000000 --- a/yazi-core/src/input/option.rs +++ /dev/null @@ -1,83 +0,0 @@ -use yazi_config::popup::{Offset as CfgOffset, Position as CfgPosition}; - -use crate::{Position, Offset}; - -#[derive(Default)] -pub struct InputOpt { - pub title: String, - pub value: String, - pub position: Position, - pub realtime: bool, - pub completion: bool, - pub highlight: bool, -} - -macro_rules! gen_method { - ($func_name:ident, $position:ident) => { - pub fn $func_name(title: impl AsRef, rect: Offset) -> InputOpt { - InputOpt { - title: title.as_ref().to_owned(), - position: Position::$position(rect), - ..Default::default() - } - } - }; -} - -impl InputOpt { - gen_method!(top_left, TopLeft); - - gen_method!(top_right, TopRight); - - gen_method!(top_center, TopCenter); - - gen_method!(center, Center); - - gen_method!(bottom_center, BottomCenter); - - gen_method!(bottom_left, BottomLeft); - - gen_method!(bottom_right, BottomRight); - - gen_method!(hovered, Hovered); - - pub fn from_cfg(title: impl AsRef, pos: &CfgPosition, rect: &CfgOffset) -> Self { - let rect = - Offset { x_offset: rect.x, y_offset: rect.y, width: rect.width, height: rect.height }; - - match pos { - CfgPosition::TopLeft => Self::top_left(title, rect), - CfgPosition::TopRight => Self::top_right(title, rect), - CfgPosition::TopCenter => Self::top_center(title, rect), - CfgPosition::Center => Self::center(title, rect), - CfgPosition::BottomCenter => Self::bottom_center(title, rect), - CfgPosition::BottomLeft => Self::bottom_left(title, rect), - CfgPosition::BottomRight => Self::bottom_right(title, rect), - CfgPosition::Hovered => Self::hovered(title, rect), - } - } - - #[inline] - pub fn with_value(mut self, value: impl AsRef) -> Self { - self.value = value.as_ref().to_owned(); - self - } - - #[inline] - pub fn with_realtime(mut self) -> Self { - self.realtime = true; - self - } - - #[inline] - pub fn with_completion(mut self) -> Self { - self.completion = true; - self - } - - #[inline] - pub fn with_highlight(mut self) -> Self { - self.highlight = true; - self - } -} diff --git a/yazi-core/src/lib.rs b/yazi-core/src/lib.rs index 044a3d2c..04664cdf 100644 --- a/yazi-core/src/lib.rs +++ b/yazi-core/src/lib.rs @@ -16,7 +16,6 @@ pub mod help; mod highlighter; pub mod input; pub mod manager; -mod position; pub mod preview; pub mod select; mod step; @@ -28,7 +27,6 @@ pub use blocker::*; pub use context::*; pub use event::*; pub use highlighter::*; -pub use position::*; pub use step::*; pub fn init() { init_blocker(); } diff --git a/yazi-core/src/manager/commands/create.rs b/yazi-core/src/manager/commands/create.rs index 4ab5ea85..2a912acc 100644 --- a/yazi-core/src/manager/commands/create.rs +++ b/yazi-core/src/manager/commands/create.rs @@ -1,10 +1,10 @@ use std::path::{PathBuf, MAIN_SEPARATOR}; use tokio::fs; -use yazi_config::keymap::Exec; +use yazi_config::{keymap::Exec, popup::InputOpt}; use yazi_shared::Url; -use crate::{emit, files::{File, FilesOp}, input::InputOpt, manager::Manager}; +use crate::{emit, files::{File, FilesOp}, manager::Manager}; pub struct Opt { force: bool, @@ -19,20 +19,14 @@ impl Manager { let opt = opt.into() as Opt; let cwd = self.cwd().to_owned(); tokio::spawn(async move { - let mut result = emit!(Input(InputOpt::top_center("Create:", Default::default()))); + let mut result = emit!(Input(InputOpt::create())); let Some(Ok(name)) = result.recv().await else { return Ok(()); }; let path = cwd.join(&name); if !opt.force && fs::symlink_metadata(&path).await.is_ok() { - match emit!(Input(InputOpt::top_center( - "Overwrite an existing file? (y/N)", - Default::default() - ))) - .recv() - .await - { + match emit!(Input(InputOpt::overwrite())).recv().await { Some(Ok(c)) if c == "y" || c == "Y" => (), _ => return Ok(()), } diff --git a/yazi-core/src/manager/commands/open.rs b/yazi-core/src/manager/commands/open.rs index e1e5c903..6c3329f4 100644 --- a/yazi-core/src/manager/commands/open.rs +++ b/yazi-core/src/manager/commands/open.rs @@ -1,9 +1,9 @@ use std::ffi::OsString; -use yazi_config::{keymap::Exec, OPEN, SELECT}; +use yazi_config::{keymap::Exec, popup::SelectOpt, OPEN, SELECT}; use yazi_shared::MIME_DIR; -use crate::{emit, external, manager::Manager, select::SelectOpt}; +use crate::{emit, external, manager::Manager}; pub struct Opt { interactive: bool, @@ -20,12 +20,8 @@ impl Manager { return; } - let result = emit!(Select(SelectOpt::from_cfg( - "Open with:", - openers.iter().map(|o| o.desc.clone()).collect(), - &SELECT.open_position, - &SELECT.open_offset - ))); + let result = + emit!(Select(SelectOpt::open().with_items(openers.iter().map(|o| o.desc.clone()).collect()))); if let Ok(choice) = result.await { emit!(Open(files, Some(openers[choice].clone()))); diff --git a/yazi-core/src/manager/commands/quit.rs b/yazi-core/src/manager/commands/quit.rs index 3c7032e8..5d6c4466 100644 --- a/yazi-core/src/manager/commands/quit.rs +++ b/yazi-core/src/manager/commands/quit.rs @@ -1,6 +1,6 @@ use yazi_config::keymap::Exec; -use crate::{emit, input::InputOpt, manager::Manager, tasks::Tasks}; +use crate::{emit, manager::Manager, tasks::Tasks}; #[derive(Default)] pub struct Opt { diff --git a/yazi-core/src/manager/commands/rename.rs b/yazi-core/src/manager/commands/rename.rs index 21e886cb..cb07f2f2 100644 --- a/yazi-core/src/manager/commands/rename.rs +++ b/yazi-core/src/manager/commands/rename.rs @@ -2,10 +2,10 @@ use std::{collections::BTreeSet, ffi::OsStr, io::{stdout, BufWriter, Write}, pat use anyhow::{anyhow, bail, Result}; use tokio::{fs::{self, OpenOptions}, io::{stdin, AsyncReadExt, AsyncWriteExt}}; -use yazi_config::{keymap::Exec, INPUT, OPEN, PREVIEW}; +use yazi_config::{keymap::Exec, popup::InputOpt, INPUT, OPEN, PREVIEW}; use yazi_shared::{max_common_root, Defer, Term, Url}; -use crate::{emit, external::{self, ShellOpt}, files::{File, FilesOp}, input::InputOpt, manager::Manager, Event, BLOCKER}; +use crate::{emit, external::{self, ShellOpt}, files::{File, FilesOp}, manager::Manager, Event, BLOCKER}; pub struct Opt { force: bool, @@ -42,10 +42,8 @@ impl Manager { let opt = opt.into() as Opt; tokio::spawn(async move { - let mut result = emit!(Input( - InputOpt::from_cfg("Rename:", &INPUT.rename_position, &INPUT.rename_offset) - .with_value(hovered.file_name().unwrap().to_string_lossy()) - )); + let mut result = + emit!(Input(InputOpt::rename().with_value(hovered.file_name().unwrap().to_string_lossy()))); let Some(Ok(name)) = result.recv().await else { return; @@ -57,11 +55,7 @@ impl Manager { return; } - let mut result = emit!(Input(InputOpt::from_cfg( - "Overwrite an existing file? (y/N)", - &INPUT.rename_position, - &INPUT.rename_offset - ))); + let mut result = emit!(Input(InputOpt::overwrite())); if let Some(Ok(choice)) = result.recv().await { if choice == "y" || choice == "Y" { Self::rename_and_hover(hovered, Url::from(new)).await.ok(); diff --git a/yazi-core/src/position.rs b/yazi-core/src/position.rs deleted file mode 100644 index d04790b6..00000000 --- a/yazi-core/src/position.rs +++ /dev/null @@ -1,50 +0,0 @@ -use ratatui::prelude::Rect; - -#[derive(Debug, Clone, Copy)] -pub struct Offset { - pub x_offset: i16, - pub y_offset: i16, - pub width: u16, - pub height: u16, -} - -impl Default for Offset { - fn default() -> Self { Self { x_offset: 0, y_offset: 2, width: 50, height: 3 } } -} - -#[derive(Debug, Clone)] -pub enum Position { - TopLeft(Offset), - TopRight(Offset), - TopCenter(Offset), - Center(Offset), - BottomCenter(Offset), - BottomLeft(Offset), - BottomRight(Offset), - Hovered(Offset), - Sticky(Offset, Rect), -} - -impl Default for Position { - fn default() -> Self { Self::TopCenter(Offset::default()) } -} - -impl Position { - #[inline] - pub fn offset(&self) -> &Offset { - match self { - Position::TopLeft(offset) => offset, - Position::TopRight(offset) => offset, - Position::TopCenter(offset) => offset, - Position::Center(offset) => offset, - Position::BottomCenter(offset) => offset, - Position::BottomLeft(offset) => offset, - Position::BottomRight(offset) => offset, - Position::Hovered(offset) => offset, - Position::Sticky(offset, _) => offset, - } - } - - #[inline] - pub fn dimension(&self) -> (u16, u16) { (self.offset().width, self.offset().height) } -} diff --git a/yazi-core/src/select/mod.rs b/yazi-core/src/select/mod.rs index 3b4cf878..ef266cba 100644 --- a/yazi-core/src/select/mod.rs +++ b/yazi-core/src/select/mod.rs @@ -1,8 +1,6 @@ mod commands; -mod option; mod select; -pub use option::*; pub use select::*; pub const SELECT_PADDING: u16 = 2; diff --git a/yazi-core/src/select/option.rs b/yazi-core/src/select/option.rs deleted file mode 100644 index b5051540..00000000 --- a/yazi-core/src/select/option.rs +++ /dev/null @@ -1,59 +0,0 @@ -use yazi_config::popup::{Offset as CfgOffset, Position as CfgPosition}; - -use crate::{Position, Offset}; - -pub struct SelectOpt { - pub title: String, - pub items: Vec, - pub position: Position, -} - -macro_rules! gen_method { - ($func_name:ident, $position:ident) => { - pub fn $func_name(title: &str, items: Vec, rect: Offset) -> SelectOpt { - let height = 2 - + items.len().min( - 5, // TODO: hardcode - ) as u16; - Self { - title: title.to_owned(), - items, - position: Position::$position(Offset { height, ..rect }), - } - } - }; -} - -impl SelectOpt { - gen_method!(top_left, TopLeft); - - gen_method!(top_right, TopRight); - - gen_method!(top_center, TopCenter); - - gen_method!(center, Center); - - gen_method!(bottom_center, BottomCenter); - - gen_method!(bottom_left, BottomLeft); - - gen_method!(bottom_right, BottomRight); - - gen_method!(hovered, Hovered); - - pub fn from_cfg(title: &str, items: Vec, pos: &CfgPosition, rect: &CfgOffset) -> Self { - let rect = - Offset { x_offset: rect.x, y_offset: rect.y, width: rect.width, height: rect.height }; - - match pos { - CfgPosition::TopLeft => Self::top_left(title, items, rect), - CfgPosition::TopRight => Self::top_right(title, items, rect), - CfgPosition::TopCenter => Self::top_center(title, items, rect), - CfgPosition::Center => Self::center(title, items, rect), - CfgPosition::BottomCenter => Self::bottom_center(title, items, rect), - CfgPosition::BottomLeft => Self::bottom_left(title, items, rect), - CfgPosition::BottomRight => Self::bottom_right(title, items, rect), - CfgPosition::Hovered => Self::hovered(title, items, rect), - } - } -} diff --git a/yazi-core/src/select/select.rs b/yazi-core/src/select/select.rs index 38fb14a6..a76afe21 100644 --- a/yazi-core/src/select/select.rs +++ b/yazi-core/src/select/select.rs @@ -1,8 +1,6 @@ use anyhow::Result; use tokio::sync::oneshot::Sender; - -use super::SelectOpt; -use crate::Position; +use yazi_config::popup::{Position, SelectOpt}; #[derive(Default)] pub struct Select { diff --git a/yazi-core/src/tab/commands/cd.rs b/yazi-core/src/tab/commands/cd.rs index 8793b187..457ea7f0 100644 --- a/yazi-core/src/tab/commands/cd.rs +++ b/yazi-core/src/tab/commands/cd.rs @@ -2,10 +2,10 @@ use std::{mem, time::Duration}; use tokio::{fs, pin}; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; -use yazi_config::{keymap::{Exec, KeymapLayer}, INPUT}; +use yazi_config::{keymap::{Exec, KeymapLayer}, popup::InputOpt}; use yazi_shared::{expand_path, Debounce, InputError, Url}; -use crate::{emit, input::InputOpt, tab::Tab}; +use crate::{emit, tab::Tab}; pub struct Opt { target: Url, @@ -65,11 +65,7 @@ impl Tab { let opt = opt.into() as Opt; tokio::spawn(async move { - let rx = emit!(Input( - InputOpt::from_cfg("Change directory:", &INPUT.cd_position, &INPUT.cd_offset) - .with_value(opt.target.to_string_lossy()) - .with_completion() - )); + let rx = emit!(Input(InputOpt::cd().with_value(opt.target.to_string_lossy()))); let rx = Debounce::new(UnboundedReceiverStream::new(rx), Duration::from_millis(50)); pin!(rx); diff --git a/yazi-core/src/tab/commands/find.rs b/yazi-core/src/tab/commands/find.rs index d70dc462..a20f0d59 100644 --- a/yazi-core/src/tab/commands/find.rs +++ b/yazi-core/src/tab/commands/find.rs @@ -2,10 +2,10 @@ use std::time::Duration; use tokio::pin; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; -use yazi_config::{keymap::{Exec, KeymapLayer}, INPUT}; +use yazi_config::{keymap::{Exec, KeymapLayer}, popup::InputOpt, INPUT}; use yazi_shared::{Debounce, InputError}; -use crate::{emit, input::InputOpt, tab::{Finder, FinderCase, Tab}}; +use crate::{emit, tab::{Finder, FinderCase, Tab}}; pub struct Opt<'a> { query: Option<&'a str>, @@ -40,9 +40,7 @@ impl Tab { let opt = opt.into() as Opt; tokio::spawn(async move { let title = if opt.prev { "Find previous:" } else { "Find next:" }; - let rx = emit!(Input( - InputOpt::from_cfg(title, &INPUT.find_position, &INPUT.find_offset).with_realtime() - )); + let rx = emit!(Input(InputOpt::find(opt.prev))); let rx = Debounce::new(UnboundedReceiverStream::new(rx), Duration::from_millis(50)); pin!(rx); diff --git a/yazi-core/src/tab/commands/search.rs b/yazi-core/src/tab/commands/search.rs index f2436410..f2efa9d1 100644 --- a/yazi-core/src/tab/commands/search.rs +++ b/yazi-core/src/tab/commands/search.rs @@ -3,9 +3,9 @@ use std::{mem, time::Duration}; use anyhow::bail; use tokio::pin; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; -use yazi_config::{keymap::{Exec, KeymapLayer}, INPUT}; +use yazi_config::{keymap::{Exec, KeymapLayer}, popup::InputOpt, INPUT}; -use crate::{emit, external, files::FilesOp, input::InputOpt, tab::Tab}; +use crate::{emit, external, files::FilesOp, tab::Tab}; pub struct Opt { pub type_: OptType, @@ -45,9 +45,7 @@ impl Tab { let hidden = self.conf.show_hidden; self.search = Some(tokio::spawn(async move { - let Some(Ok(subject)) = emit!(Input(InputOpt::from_cfg("Search:", &INPUT.cd_position, &INPUT.cd_offset))).recv().await else { - bail!("") - }; + let Some(Ok(subject)) = emit!(Input(InputOpt::search())).recv().await else { bail!("") }; cwd = cwd.into_search(subject.clone()); let rx = if opt.type_ == OptType::Rg { diff --git a/yazi-core/src/tab/commands/shell.rs b/yazi-core/src/tab/commands/shell.rs index 123678db..19ada902 100644 --- a/yazi-core/src/tab/commands/shell.rs +++ b/yazi-core/src/tab/commands/shell.rs @@ -1,6 +1,6 @@ -use yazi_config::{keymap::Exec, open::Opener, INPUT}; +use yazi_config::{keymap::Exec, open::Opener, popup::InputOpt, INPUT}; -use crate::{emit, input::InputOpt, tab::Tab}; +use crate::{emit, tab::Tab}; pub struct Opt { cmd: String, @@ -29,12 +29,7 @@ impl Tab { let mut opt = opt.into() as Opt; tokio::spawn(async move { if !opt.confirm || opt.cmd.is_empty() { - let title = if opt.block { "Shell (block):" } else { "Shell:" }; - let mut result = emit!(Input( - InputOpt::from_cfg(title, &INPUT.shell_position, &INPUT.shell_offset) - .with_value(opt.cmd) - .with_highlight() - )); + let mut result = emit!(Input(InputOpt::shell(opt.block).with_value(opt.cmd))); match result.recv().await { Some(Ok(e)) => opt.cmd = e, _ => return, diff --git a/yazi-core/src/tasks/tasks.rs b/yazi-core/src/tasks/tasks.rs index dbf21407..765f69c0 100644 --- a/yazi-core/src/tasks/tasks.rs +++ b/yazi-core/src/tasks/tasks.rs @@ -2,11 +2,11 @@ use std::{collections::{BTreeMap, HashMap, HashSet}, ffi::OsStr, path::Path, syn use serde::Serialize; use tracing::debug; -use yazi_config::{manager::SortBy, open::Opener, OPEN}; +use yazi_config::{manager::SortBy, open::Opener, popup::InputOpt, OPEN}; use yazi_shared::{MimeKind, Term, Url}; use super::{running::Running, task::TaskSummary, Scheduler, TASKS_PADDING, TASKS_PERCENT}; -use crate::{emit, files::{File, Files}, input::InputOpt}; +use crate::{emit, files::{File, Files}}; pub struct Tasks { pub(super) scheduler: Arc, @@ -110,13 +110,11 @@ impl Tasks { let scheduler = self.scheduler.clone(); tokio::spawn(async move { - let s = if targets.len() > 1 { "s" } else { "" }; - let prompt = if permanently { - format!("Delete {} selected file{s} permanently? (y/N)", targets.len()) + let mut result = emit!(Input(if permanently { + InputOpt::delete(targets.len()) } else { - format!("Move {} selected file{s} to trash? (y/N)", targets.len()) - }; - let mut result = emit!(Input(InputOpt::hovered(prompt, Default::default()))); + InputOpt::trash(targets.len()) + })); if let Some(Ok(choice)) = result.recv().await { if choice != "y" && choice != "Y" {