From f7d73892458535b10392279fe8723db106a5a4e9 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 16 Sep 2024 23:58:30 +0800 Subject: [PATCH] Refactor --- yazi-config/src/lib.rs | 12 ++++++------ yazi-config/src/popup/input.rs | 26 ++++++++++++++++++-------- yazi-config/src/popup/options.rs | 6 +----- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/yazi-config/src/lib.rs b/yazi-config/src/lib.rs index 7c78fe49..061b869f 100644 --- a/yazi-config/src/lib.rs +++ b/yazi-config/src/lib.rs @@ -83,13 +83,13 @@ Please replace e.g. `shell` with `shell --interactive`, `shell "my-template"` wi } } - // TODO: Remove when deprecated - if matches!(INPUT.create_title, popup::CreateTitle::One(_)) { + // TODO: Remove in v0.3.6 + if matches!(INPUT.create_title, popup::InputCreateTitle::One(_)) { println!( - r#"WARNING: `create_title` config now takes two different values to account for the `--dir` flag. -Example: -[input] -create_title = ["Create:", "Create (dir):"]"# + 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. +"# ); } diff --git a/yazi-config/src/popup/input.rs b/yazi-config/src/popup/input.rs index 5bc12606..f0f35166 100644 --- a/yazi-config/src/popup/input.rs +++ b/yazi-config/src/popup/input.rs @@ -4,13 +4,6 @@ use serde::Deserialize; use super::{Offset, Origin}; -#[derive(Deserialize)] -#[serde(untagged)] -pub enum CreateTitle { - One(String), - Two([String; 2]), -} - #[derive(Deserialize)] pub struct Input { pub cursor_blink: bool, @@ -21,7 +14,7 @@ pub struct Input { pub cd_offset: Offset, // create - pub create_title: CreateTitle, + pub create_title: InputCreateTitle, pub create_origin: Origin, pub create_offset: Offset, @@ -67,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 6cc7d3be..6cf419d9 100644 --- a/yazi-config/src/popup/options.rs +++ b/yazi-config/src/popup/options.rs @@ -41,12 +41,8 @@ impl InputCfg { } pub fn create(dir: bool) -> Self { - let title = match &INPUT.create_title { - super::CreateTitle::One(single_title) => single_title.to_owned(), - super::CreateTitle::Two(titles) => titles[dir as usize].to_owned(), - }; Self { - title, + title: INPUT.create_title.as_array()[dir as usize].to_owned(), position: Position::new(INPUT.create_origin, INPUT.create_offset), ..Default::default() }