diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index 90d7d942..df67a363 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -75,10 +75,9 @@ preload = [] [input] # cd -cd_title = "Change directory:" -cd_origin = "top-center" -cd_offset = [ 0, 2, 50, 3 ] -cd_completion = 1 +cd_title = "Change directory:" +cd_origin = "top-center" +cd_offset = [ 0, 2, 50, 3 ] # create create_title = "Create:" @@ -101,10 +100,9 @@ delete_origin = "top-center" delete_offset = [ 0, 2, 50, 3 ] # find -find_title = [ "Find previous:", "Find next:" ] -find_origin = "top-center" -find_offset = [ 0, 2, 50, 3 ] -find_realtime = true +find_title = [ "Find next:", "Find previous:" ] +find_origin = "top-center" +find_offset = [ 0, 2, 50, 3 ] # search search_title = "Search:" @@ -112,10 +110,9 @@ search_origin = "top-center" search_offset = [ 0, 2, 50, 3 ] # shell -shell_title = [ "Shell:", "Shell (block):" ] -shell_origin = "top-center" -shell_offset = [ 0, 2, 50, 3 ] -shell_highlight = true +shell_title = [ "Shell:", "Shell (block):" ] +shell_origin = "top-center" +shell_offset = [ 0, 2, 50, 3 ] # overwrite overwrite_title = "Overwrite an existing file? (y/N)" diff --git a/yazi-config/src/popup/input.rs b/yazi-config/src/popup/input.rs index 4cbee28f..9c704044 100644 --- a/yazi-config/src/popup/input.rs +++ b/yazi-config/src/popup/input.rs @@ -44,6 +44,11 @@ pub struct Input { pub shell_title: [String; 2], pub shell_origin: Origin, pub shell_offset: Offset, + + // overwrite + pub overwrite_title: String, + pub overwrite_origin: Origin, + pub overwrite_offset: Offset, } impl Default for Input { diff --git a/yazi-config/src/popup/options.rs b/yazi-config/src/popup/options.rs index 6427f66e..03039953 100644 --- a/yazi-config/src/popup/options.rs +++ b/yazi-config/src/popup/options.rs @@ -1,5 +1,7 @@ use super::Position; +use crate::INPUT; +#[derive(Default)] pub struct InputOpt { pub title: String, pub value: String, @@ -9,6 +11,7 @@ pub struct InputOpt { pub highlight: bool, } +#[derive(Default)] pub struct SelectOpt { pub title: String, pub items: Vec, @@ -17,32 +20,90 @@ pub struct SelectOpt { impl InputOpt { #[inline] - pub fn cd() -> Self { todo!() } + pub fn cd() -> Self { + Self { + title: INPUT.cd_title.to_owned(), + position: Position::new(INPUT.cd_origin, INPUT.cd_offset), + completion: true, + ..Default::default() + } + } #[inline] - pub fn create() -> Self { todo!() } + pub fn create() -> Self { + Self { + title: INPUT.create_title.to_owned(), + position: Position::new(INPUT.create_origin, INPUT.create_offset), + ..Default::default() + } + } #[inline] - pub fn rename() -> Self { todo!() } + pub fn rename() -> Self { + Self { + title: INPUT.rename_title.to_owned(), + position: Position::new(INPUT.rename_origin, INPUT.rename_offset), + ..Default::default() + } + } #[inline] - pub fn trash(n: usize) -> Self { todo!() } + pub fn trash(n: usize) -> Self { + let title = INPUT.trash_title.replace("{n}", &n.to_string()); + Self { + title: title.replace("{s}", if n > 1 { "s" } else { "" }), + position: Position::new(INPUT.trash_origin, INPUT.trash_offset), + ..Default::default() + } + } #[inline] - pub fn delete(n: usize) -> Self { todo!() } + pub fn delete(n: usize) -> Self { + let title = INPUT.delete_title.replace("{n}", &n.to_string()); + Self { + title: title.replace("{s}", if n > 1 { "s" } else { "" }), + position: Position::new(INPUT.delete_origin, INPUT.delete_offset), + ..Default::default() + } + } #[inline] - pub fn find(prev: bool) -> Self { todo!() } + pub fn find(prev: bool) -> Self { + Self { + title: INPUT.find_title[prev as usize].to_owned(), + position: Position::new(INPUT.find_origin, INPUT.find_offset), + realtime: true, + ..Default::default() + } + } #[inline] - pub fn search() -> Self { todo!() } + pub fn search() -> Self { + Self { + title: INPUT.search_title.to_owned(), + position: Position::new(INPUT.search_origin, INPUT.search_offset), + ..Default::default() + } + } #[inline] - - pub fn shell(block: bool) -> Self { todo!() } + pub fn shell(block: bool) -> Self { + Self { + title: INPUT.shell_title[block as usize].to_owned(), + position: Position::new(INPUT.shell_origin, INPUT.shell_offset), + highlight: true, + ..Default::default() + } + } #[inline] - pub fn overwrite() -> Self { todo!() } + pub fn overwrite() -> Self { + Self { + title: INPUT.overwrite_title.to_owned(), + position: Position::new(INPUT.overwrite_origin, INPUT.overwrite_offset), + ..Default::default() + } + } #[inline] pub fn with_value(mut self, value: impl Into) -> Self { diff --git a/yazi-config/src/popup/position.rs b/yazi-config/src/popup/position.rs index d8a3e3a9..97fbdee5 100644 --- a/yazi-config/src/popup/position.rs +++ b/yazi-config/src/popup/position.rs @@ -11,6 +11,9 @@ pub struct Position { } impl Position { + #[inline] + pub fn new(origin: Origin, offset: Offset) -> Self { Self { origin, offset } } + pub fn rect(&self) -> Rect { let Offset { x, y, width, height } = self.offset; let WindowSize { columns, rows, .. } = Term::size();