Skip to content

Commit

Permalink
feat!: remove the meaningless --confirm option to simplify the `she…
Browse files Browse the repository at this point in the history
…ll` command (#1982)
  • Loading branch information
sxyazi authored Dec 3, 2024
1 parent 4bd8b0b commit d3f572a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 43 deletions.
22 changes: 0 additions & 22 deletions yazi-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
24 changes: 4 additions & 20 deletions yazi-core/src/tab/commands/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub struct Opt {
run: Cow<'static, str>,
block: bool,
orphan: bool,
confirm: bool,
interactive: bool,
cursor: Option<usize>,
}
Expand All @@ -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),
};
Expand All @@ -48,33 +46,19 @@ 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 {
Some(Ok(e)) => opt.run = Cow::Owned(e),
_ => return,
}
}
if opt.run.is_empty() {
return;
}

TasksProxy::open_with(
selected,
Expand Down
9 changes: 8 additions & 1 deletion yazi-dds/src/sendable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>() {
Expand Down Expand Up @@ -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())?)
Expand Down
2 changes: 2 additions & 0 deletions yazi-shared/src/event/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>),
}

Expand Down

0 comments on commit d3f572a

Please sign in to comment.