mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: support setting different input titles for create --dir (#1650)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
28083d805e
commit
dfe2884110
5 changed files with 32 additions and 5 deletions
|
|
@ -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 ]
|
||||
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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::<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]],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(());
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue