feat!: remove the meaningless --confirm option to simplify the shell command (#1982)

This commit is contained in:
三咲雅 · Misaki Masa 2024-12-03 22:15:43 +08:00 committed by GitHub
parent 4bd8b0b446
commit d3f572a8c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 43 deletions

View file

@ -28,28 +28,6 @@ pub fn init() -> anyhow::Result<()> {
try_init(false)?;
}
// TODO: Remove in v0.3.2
for c in &KEYMAP.manager {
for r in &c.run {
if r.name != "shell" {
continue;
}
if !r.bool("confirm") && !r.bool("interactive") {
let s = format!("`{}` ({})", c.on(), c.desc_or_run());
eprintln!(
r#"WARNING: In Yazi v0.3, the behavior of the interactive `shell` (i.e., shell templates) must be explicitly specified with either `--interactive` or `--confirm`.
Please replace e.g. `shell` with `shell --interactive`, `shell "my-template"` with `shell "my-template" --interactive`, in your keymap.toml for the key: {s}"#
);
return Ok(());
} else if r.bool("confirm") && r.bool("interactive") {
eprintln!(
"The `shell` command cannot specify both `--confirm` and `--interactive` at the same time.",
);
}
}
}
// TODO: Remove in v0.3.6
if matches!(INPUT.create_title, popup::InputCreateTitle::One(_)) {
eprintln!(

View file

@ -11,7 +11,6 @@ pub struct Opt {
run: Cow<'static, str>,
block: bool,
orphan: bool,
confirm: bool,
interactive: bool,
cursor: Option<usize>,
}
@ -24,7 +23,6 @@ impl TryFrom<CmdCow> for Opt {
run: c.take_first_str().unwrap_or_default(),
block: c.bool("block"),
orphan: c.bool("orphan"),
confirm: c.bool("confirm"),
interactive: c.bool("interactive"),
cursor: c.get("cursor").and_then(Data::as_usize),
};
@ -48,26 +46,9 @@ impl Tab {
Err(e) => return AppProxy::notify_warn("`shell` command", e),
};
// TODO: Remove in v0.3.2
if !opt.interactive && !opt.confirm {
AppProxy::notify_error(
"`shell` command",
r#"WARNING: In Yazi v0.3, the behavior of the interactive `shell` (i.e., shell templates) must be explicitly specified with either `--interactive` or `--confirm`.
Please replace e.g. `shell` with `shell --interactive`, `shell "my-template"` with `shell "my-template" --interactive`, in your keymap.toml"#,
);
return;
} else if opt.interactive && opt.confirm {
AppProxy::notify_error(
"`shell` command",
"The `shell` command cannot specify both `--confirm` and `--interactive` at the same time.",
);
return;
}
let selected = self.hovered_and_selected(true).cloned().collect();
tokio::spawn(async move {
if !opt.confirm || opt.run.is_empty() {
if opt.interactive {
let mut result =
InputProxy::show(InputCfg::shell(opt.block).with_value(opt.run).with_cursor(opt.cursor));
match result.recv().await {
@ -75,6 +56,9 @@ Please replace e.g. `shell` with `shell --interactive`, `shell "my-template"` wi
_ => return,
}
}
if opt.run.is_empty() {
return;
}
TasksProxy::open_with(
selected,

View file

@ -13,7 +13,13 @@ impl Sendable {
Value::LightUserData(_) => Err("light userdata is not supported".into_lua_err())?,
Value::Integer(i) => Data::Integer(i),
Value::Number(n) => Data::Number(n),
Value::String(s) => Data::String(s.to_str()?.to_owned()),
Value::String(b) => {
if let Ok(s) = b.to_str() {
Data::String(s.to_owned())
} else {
Data::Bytes(b.as_bytes().to_owned())
}
}
Value::Table(t) => {
let (mut i, mut map) = (1, HashMap::with_capacity(t.raw_len()));
for result in t.pairs::<Value, Value>() {
@ -100,6 +106,7 @@ impl Sendable {
Value::Table(tbl)
}
Data::Url(u) => Value::UserData(lua.create_any_userdata(u.clone())?),
Data::Bytes(b) => Value::String(lua.create_string(b)?),
Data::Any(a) => {
if let Some(t) = a.downcast_ref::<super::body::BodyYankIter>() {
Value::UserData(lua.create_userdata(t.clone())?)

View file

@ -18,6 +18,8 @@ pub enum Data {
#[serde(skip_deserializing)]
Url(Url),
#[serde(skip)]
Bytes(Vec<u8>),
#[serde(skip)]
Any(Box<dyn Any + Send + Sync>),
}