refactor!: v0.3 API changes (#1108)

This commit is contained in:
三咲雅 · Misaki Masa 2024-05-31 01:09:30 +08:00 committed by GitHub
parent 46cd42f923
commit 95e960a64a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 63 additions and 22 deletions

View File

@ -62,7 +62,7 @@ keymap = [
{ on = [ "o" ], run = "open", desc = "Open the selected files" },
{ on = [ "O" ], run = "open --interactive", desc = "Open the selected files interactively" },
{ on = [ "<Enter>" ], run = "open", desc = "Open the selected files" },
{ on = [ "<C-Enter>" ], run = "open --interactive", desc = "Open the selected files interactively" },
{ on = [ "<S-Enter>" ], run = "open --interactive", desc = "Open the selected files interactively" },
{ on = [ "y" ], run = "yank", desc = "Copy the selected files" },
{ on = [ "Y" ], run = "unyank", desc = "Cancel the yank status of files" },
{ on = [ "x" ], run = "yank --cut", desc = "Cut the selected files" },

View File

@ -67,7 +67,7 @@ rules = [
{ mime = "application/json", use = [ "edit", "reveal" ] },
{ mime = "*/javascript", use = [ "edit", "reveal" ] },
{ mime = "*", use = [ "open", "reveal" ] },
{ name = "*", use = [ "open", "reveal" ] },
]
[tasks]

View File

@ -78,6 +78,13 @@ impl<'de> Deserialize<'de> for Open {
}
let mut outer = Outer::deserialize(deserializer)?;
if outer.open.append_rules.iter().any(|r| r.any_file()) {
outer.open.rules.retain(|r| !r.any_file());
}
if outer.open.append_rules.iter().any(|r| r.any_dir()) {
outer.open.rules.retain(|r| !r.any_dir());
}
Preset::mix(&mut outer.open.rules, outer.open.prepend_rules, outer.open.append_rules);
let openers = outer

View File

@ -13,6 +13,14 @@ pub(super) struct OpenRule {
pub(super) use_: Vec<String>,
}
impl OpenRule {
#[inline]
pub fn any_file(&self) -> bool { self.name.as_ref().is_some_and(|p| p.any_file()) }
#[inline]
pub fn any_dir(&self) -> bool { self.name.as_ref().is_some_and(|p| p.any_dir()) }
}
impl OpenRule {
fn deserialize<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>
where

View File

@ -43,10 +43,15 @@ impl Icons {
#[inline]
fn match_name(&self, file: &File) -> Option<&Icon> {
let name = file.name()?.to_str()?;
if let Some(i) = if file.is_dir() { self.dirs.get(name) } else { self.files.get(name) } {
return Some(i);
if file.is_dir() {
self.dirs.get(name).or_else(|| self.dirs.get(&name.to_ascii_lowercase()))
} else {
self
.files
.get(name)
.or_else(|| self.files.get(&name.to_ascii_lowercase()))
.or_else(|| self.exts.get(file.url.extension()?.to_str()?))
}
self.exts.get(file.url.extension()?.to_str()?)
}
}

View File

@ -46,7 +46,7 @@ function M:preload()
end
local status = child:wait()
return status and status:success() and 1 or 2
return status and status.success and 1 or 2
end
return M

View File

@ -16,8 +16,8 @@ local function entry()
local output, err = child:wait_with_output()
if not output then
return fail("Cannot read `fzf` output, error code %s", err)
elseif not output.status:success() and output.status:code() ~= 130 then
return fail("`fzf` exited with error code %s", output.status:code())
elseif not output.status.success and output.status.code ~= 130 then
return fail("`fzf` exited with error code %s", output.status.code)
end
local target = output.stdout:gsub("\n$", "")

View File

@ -37,7 +37,7 @@ function M:preload()
end
local status = child:wait()
return status and status:success() and 1 or 2
return status and status.success and 1 or 2
end
return M

View File

@ -59,4 +59,28 @@ function M:fetch()
return j == #urls and 3 or 2
end
-- TODO: remove this after v0.3 release
local notified = ya.sync(function (state)
if state.notified then
return true
else
state.notified = true
return false
end
end)
function M:preload()
if notified() then
return 1
end
ya.notify {
title = "Error",
content = [[In Yazi v0.3, the `mime` plugin has been re-classified as a fetcher. Please remove it from the `preloaders` of your yazi.toml
See https://github.com/sxyazi/yazi/issues/1046 for details.]],
timeout = 20,
level = "error",
}
return 1
end
return M

View File

@ -34,7 +34,7 @@ function M:preload()
if not output then
return 0
elseif not output.status:success() then
elseif not output.status.success then
local pages = tonumber(output.stderr:match("the last page %((%d+)%)")) or 0
if self.skip > 0 and pages > 0 then
ya.manager_emit("peek", { math.max(0, pages - 1), only_if = self.file.url, upper_bound = true })

View File

@ -55,7 +55,7 @@ function M:preload()
end
local status = child:wait()
return status and status:success() and 1 or 2
return status and status.success and 1 or 2
end
return M

View File

@ -75,8 +75,8 @@ local function entry()
local output, err = child:wait_with_output()
if not output then
return fail("Cannot read `zoxide` output, error code %s", err)
elseif not output.status:success() and output.status:code() ~= 130 then
return fail("`zoxide` exited with error code %s", output.status:code())
elseif not output.status.success and output.status.code ~= 130 then
return fail("`zoxide` exited with error code %s", output.status.code)
end
local target = output.stdout:gsub("\n$", "")

View File

@ -13,13 +13,10 @@ impl Cha {
reg.add_field_method_get("is_hidden", |_, me| Ok(me.is_hidden()));
reg.add_field_method_get("is_link", |_, me| Ok(me.is_link()));
reg.add_field_method_get("is_orphan", |_, me| Ok(me.is_orphan()));
// TODO: rename to `is_block`
reg.add_field_method_get("is_block_device", |_, me| Ok(me.is_block()));
// TODO: rename to `is_char`
reg.add_field_method_get("is_char_device", |_, me| Ok(me.is_char()));
reg.add_field_method_get("is_block", |_, me| Ok(me.is_block()));
reg.add_field_method_get("is_char", |_, me| Ok(me.is_char()));
reg.add_field_method_get("is_fifo", |_, me| Ok(me.is_fifo()));
// TODO: rename to `is_sock`
reg.add_field_method_get("is_socket", |_, me| Ok(me.is_sock()));
reg.add_field_method_get("is_sock", |_, me| Ok(me.is_sock()));
reg.add_field_method_get("is_exec", |_, me| Ok(me.is_exec()));
reg.add_field_method_get("is_sticky", |_, me| Ok(me.is_sticky()));

View File

@ -9,8 +9,8 @@ impl Status {
}
impl UserData for Status {
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_method("success", |_, me, ()| Ok(me.inner.success()));
methods.add_method("code", |_, me, ()| Ok(me.inner.code()));
fn add_fields<'lua, F: mlua::UserDataFields<'lua, Self>>(fields: &mut F) {
fields.add_field_method_get("success", |_, me| Ok(me.inner.success()));
fields.add_field_method_get("code", |_, me| Ok(me.inner.code()));
}
}