Skip to content

Commit

Permalink
feat: support setting different input titles for create --dir (#1650)
Browse files Browse the repository at this point in the history
Co-authored-by: sxyazi <sxyazi@gmail.com>
  • Loading branch information
Tyarel8 and sxyazi authored Sep 16, 2024
1 parent 28083d8 commit dfe2884
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion yazi-config/preset/yazi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]

Expand Down
10 changes: 10 additions & 0 deletions yazi-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
19 changes: 18 additions & 1 deletion yazi-config/src/popup/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -60,3 +60,20 @@ impl FromStr for 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]],
}
}
}
4 changes: 2 additions & 2 deletions yazi-config/src/popup/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion yazi-core/src/manager/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
};
Expand Down

0 comments on commit dfe2884

Please sign in to comment.