This commit is contained in:
sxyazi 2024-09-16 23:58:30 +08:00
parent 41bf51fa9e
commit f7d7389245
No known key found for this signature in database
3 changed files with 25 additions and 19 deletions

View file

@ -83,13 +83,13 @@ Please replace e.g. `shell` with `shell --interactive`, `shell "my-template"` wi
} }
} }
// TODO: Remove when deprecated // TODO: Remove in v0.3.6
if matches!(INPUT.create_title, popup::CreateTitle::One(_)) { if matches!(INPUT.create_title, popup::InputCreateTitle::One(_)) {
println!( println!(
r#"WARNING: `create_title` config now takes two different values to account for the `--dir` flag. 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.
Example:
[input] Please change `create_title = "Create:"` to `create_title = ["Create:", "Create (dir):"]` in your yazi.toml.
create_title = ["Create:", "Create (dir):"]"# "#
); );
} }

View file

@ -4,13 +4,6 @@ use serde::Deserialize;
use super::{Offset, Origin}; use super::{Offset, Origin};
#[derive(Deserialize)]
#[serde(untagged)]
pub enum CreateTitle {
One(String),
Two([String; 2]),
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Input { pub struct Input {
pub cursor_blink: bool, pub cursor_blink: bool,
@ -21,7 +14,7 @@ pub struct Input {
pub cd_offset: Offset, pub cd_offset: Offset,
// create // create
pub create_title: CreateTitle, pub create_title: InputCreateTitle,
pub create_origin: Origin, pub create_origin: Origin,
pub create_offset: Offset, pub create_offset: Offset,
@ -67,3 +60,20 @@ impl FromStr for Input {
Ok(toml::from_str::<Outer>(s)?.input) Ok(toml::from_str::<Outer>(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]],
}
}
}

View file

@ -41,12 +41,8 @@ impl InputCfg {
} }
pub fn create(dir: bool) -> Self { 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 { Self {
title, title: INPUT.create_title.as_array()[dir as usize].to_owned(),
position: Position::new(INPUT.create_origin, INPUT.create_offset), position: Position::new(INPUT.create_origin, INPUT.create_offset),
..Default::default() ..Default::default()
} }