From dfe2884110d24515b591192be94b17c44689015d Mon Sep 17 00:00:00 2001 From: Tyarel <98483313+Tyarel8@users.noreply.github.com> Date: Mon, 16 Sep 2024 18:03:17 +0200 Subject: [PATCH] feat: support setting different input titles for `create --dir` (#1650) Co-authored-by: sxyazi --- yazi-config/preset/yazi.toml | 2 +- yazi-config/src/lib.rs | 10 ++++++++++ yazi-config/src/popup/input.rs | 19 ++++++++++++++++++- yazi-config/src/popup/options.rs | 4 ++-- yazi-core/src/manager/commands/create.rs | 2 +- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index bb91c0ce..05a60fa2 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -139,7 +139,7 @@ cd_origin = "top-center" cd_offset = [ 0, 2, 50, 3 ] # create -create_title = "Create:" +create_title = [ "Create:", "Create (dir):" ] create_origin = "top-center" create_offset = [ 0, 2, 50, 3 ] diff --git a/yazi-config/src/lib.rs b/yazi-config/src/lib.rs index bff78d0c..061b869f 100644 --- a/yazi-config/src/lib.rs +++ b/yazi-config/src/lib.rs @@ -83,5 +83,15 @@ Please replace e.g. `shell` with `shell --interactive`, `shell "my-template"` wi } } + // TODO: Remove in v0.3.6 + if matches!(INPUT.create_title, popup::InputCreateTitle::One(_)) { + println!( + r#"WARNING: The `create_title` under `[input]` now accepts an array instead of a string to support different titles for `create` and `create --dir` command. + +Please change `create_title = "Create:"` to `create_title = ["Create:", "Create (dir):"]` in your yazi.toml. +"# + ); + } + Ok(()) } diff --git a/yazi-config/src/popup/input.rs b/yazi-config/src/popup/input.rs index 633066b1..f0f35166 100644 --- a/yazi-config/src/popup/input.rs +++ b/yazi-config/src/popup/input.rs @@ -14,7 +14,7 @@ pub struct Input { pub cd_offset: Offset, // create - pub create_title: String, + pub create_title: InputCreateTitle, pub create_origin: Origin, pub create_offset: Offset, @@ -60,3 +60,20 @@ impl FromStr for Input { Ok(toml::from_str::(s)?.input) } } + +// TODO: Remove in v0.3.6 +#[derive(Deserialize)] +#[serde(untagged)] +pub enum InputCreateTitle { + One(String), + Two([String; 2]), +} + +impl InputCreateTitle { + pub fn as_array(&self) -> [&str; 2] { + match self { + Self::One(s) => [s, "Create (dir):"], + Self::Two(a) => [&a[0], &a[1]], + } + } +} diff --git a/yazi-config/src/popup/options.rs b/yazi-config/src/popup/options.rs index dc669b5b..6cf419d9 100644 --- a/yazi-config/src/popup/options.rs +++ b/yazi-config/src/popup/options.rs @@ -40,9 +40,9 @@ impl InputCfg { } } - pub fn create() -> Self { + pub fn create(dir: bool) -> Self { Self { - title: INPUT.create_title.to_owned(), + title: INPUT.create_title.as_array()[dir as usize].to_owned(), position: Position::new(INPUT.create_origin, INPUT.create_offset), ..Default::default() } diff --git a/yazi-core/src/manager/commands/create.rs b/yazi-core/src/manager/commands/create.rs index 8cca95e9..6e4ade2a 100644 --- a/yazi-core/src/manager/commands/create.rs +++ b/yazi-core/src/manager/commands/create.rs @@ -22,7 +22,7 @@ impl Manager { let opt = opt.into() as Opt; let cwd = self.cwd().to_owned(); tokio::spawn(async move { - let mut result = InputProxy::show(InputCfg::create()); + let mut result = InputProxy::show(InputCfg::create(opt.dir)); let Some(Ok(name)) = result.recv().await else { return Ok(()); };