fix: properly drop the permit for terminal resources (#3592)

This commit is contained in:
三咲雅 misaki masa 2026-01-20 18:25:02 +08:00 committed by GitHub
parent ca4cc59413
commit e6d995710f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 115 additions and 86 deletions

View file

@ -1,5 +1,6 @@
{ {
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
"runtime.version": "Lua 5.4", "runtime.version": "Lua 5.4",
"workspace.library": ["~/.config/yazi/plugins/types.yazi/"] "workspace.library": ["~/.config/yazi/plugins/types.yazi/"],
"diagnostics.disable": ["redefined-local"]
} }

68
Cargo.lock generated
View file

@ -104,7 +104,7 @@ dependencies = [
"ratatui-core", "ratatui-core",
"simdutf8", "simdutf8",
"smallvec", "smallvec",
"thiserror 2.0.17", "thiserror 2.0.18",
] ]
[[package]] [[package]]
@ -255,7 +255,7 @@ dependencies = [
"num-traits", "num-traits",
"pastey", "pastey",
"rayon", "rayon",
"thiserror 2.0.17", "thiserror 2.0.18",
"v_frame", "v_frame",
"y4m", "y4m",
] ]
@ -919,9 +919,9 @@ dependencies = [
[[package]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.2.0-rc.9" version = "0.2.0-rc.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41b8986f836d4aeb30ccf4c9d3bd562fd716074cfd7fc4a2948359fbd21ed809" checksum = "0f4fc0003068acd7e9cb6659fd956dc4d671f102a06cc115990b9e7bb5745c25"
dependencies = [ dependencies = [
"hybrid-array", "hybrid-array",
] ]
@ -1203,13 +1203,13 @@ dependencies = [
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.11.0-rc.5" version = "0.11.0-rc.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebf9423bafb058e4142194330c52273c343f8a5beb7176d052f0e73b17dd35b9" checksum = "2778ee7344f47967d6701053913962accf9bfdb0caa4b6d921b7c4a615f658d0"
dependencies = [ dependencies = [
"block-buffer 0.11.0", "block-buffer 0.11.0",
"const-oid 0.10.2", "const-oid 0.10.2",
"crypto-common 0.2.0-rc.9", "crypto-common 0.2.0-rc.10",
] ]
[[package]] [[package]]
@ -1387,9 +1387,9 @@ checksum = "dea2df4cf52843e0452895c455a1a2cfbb842a1e7329671acf418fdc53ed4c59"
[[package]] [[package]]
name = "euclid" name = "euclid"
version = "0.22.11" version = "0.22.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad9cdb4b747e485a12abb0e6566612956c7a1bafa3bdb8d682c5b6d403589e48" checksum = "df61bf483e837f88d5c2291dcf55c67be7e676b3a51acc48db3a7b163b91ed63"
dependencies = [ dependencies = [
"num-traits", "num-traits",
] ]
@ -1913,7 +1913,7 @@ dependencies = [
"rgb", "rgb",
"tiff", "tiff",
"zune-core 0.5.1", "zune-core 0.5.1",
"zune-jpeg 0.5.9", "zune-jpeg 0.5.11",
] ]
[[package]] [[package]]
@ -2004,7 +2004,7 @@ checksum = "fe44f2bbd99fcb302e246e2d6bcf51aeda346d02a365f80296a07a8c711b6da6"
dependencies = [ dependencies = [
"argon2", "argon2",
"bcrypt-pbkdf", "bcrypt-pbkdf",
"digest 0.11.0-rc.5", "digest 0.11.0-rc.6",
"ecdsa", "ecdsa",
"ed25519-dalek", "ed25519-dalek",
"hex", "hex",
@ -2087,7 +2087,7 @@ checksum = "8fe90c1150662e858c7d5f945089b7517b0a80d8bf7ba4b1b5ffc984e7230a5b"
dependencies = [ dependencies = [
"hashbrown", "hashbrown",
"portable-atomic", "portable-atomic",
"thiserror 2.0.17", "thiserror 2.0.18",
] ]
[[package]] [[package]]
@ -3060,9 +3060,9 @@ dependencies = [
[[package]] [[package]]
name = "pkcs8" name = "pkcs8"
version = "0.11.0-rc.8" version = "0.11.0-rc.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77089aec8290d0b7bb01b671b091095cf1937670725af4fd73d47249f03b12c0" checksum = "80f8fa6196ede5a9f9ee95b44ca134bddc9b70e8913f9297bd58c909f5889a09"
dependencies = [ dependencies = [
"der 0.8.0-rc.10", "der 0.8.0-rc.10",
"spki 0.8.0-rc.4", "spki 0.8.0-rc.4",
@ -3371,7 +3371,7 @@ dependencies = [
"lru", "lru",
"serde", "serde",
"strum", "strum",
"thiserror 2.0.17", "thiserror 2.0.18",
"unicode-segmentation", "unicode-segmentation",
"unicode-truncate", "unicode-truncate",
"unicode-width", "unicode-width",
@ -3471,7 +3471,7 @@ dependencies = [
"rand 0.9.2", "rand 0.9.2",
"rand_chacha 0.9.0", "rand_chacha 0.9.0",
"simd_helpers", "simd_helpers",
"thiserror 2.0.17", "thiserror 2.0.18",
"v_frame", "v_frame",
"wasm-bindgen", "wasm-bindgen",
] ]
@ -3527,7 +3527,7 @@ checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac"
dependencies = [ dependencies = [
"getrandom 0.2.17", "getrandom 0.2.17",
"libredox", "libredox",
"thiserror 2.0.17", "thiserror 2.0.18",
] ]
[[package]] [[package]]
@ -3618,9 +3618,9 @@ dependencies = [
"const-oid 0.10.2", "const-oid 0.10.2",
"crypto-bigint 0.7.0-rc.18", "crypto-bigint 0.7.0-rc.18",
"crypto-primes", "crypto-primes",
"digest 0.11.0-rc.5", "digest 0.11.0-rc.6",
"pkcs1", "pkcs1",
"pkcs8 0.11.0-rc.8", "pkcs8 0.11.0-rc.9",
"rand_core 0.10.0-rc-3", "rand_core 0.10.0-rc-3",
"sha2 0.11.0-rc.3", "sha2 0.11.0-rc.3",
"signature 3.0.0-rc.6", "signature 3.0.0-rc.6",
@ -3928,7 +3928,7 @@ checksum = "aa1ae819b9870cadc959a052363de870944a1646932d274a4e270f64bf79e5ef"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"cpufeatures", "cpufeatures",
"digest 0.11.0-rc.5", "digest 0.11.0-rc.6",
] ]
[[package]] [[package]]
@ -3950,7 +3950,7 @@ checksum = "19d43dc0354d88b791216bb5c1bfbb60c0814460cc653ae0ebd71f286d0bd927"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"cpufeatures", "cpufeatures",
"digest 0.11.0-rc.5", "digest 0.11.0-rc.6",
] ]
[[package]] [[package]]
@ -4037,7 +4037,7 @@ version = "3.0.0-rc.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597a96996ccff7dfa16f052bd995b4cecc72af22c35138738dc029f0ead6608d" checksum = "597a96996ccff7dfa16f052bd995b4cecc72af22c35138738dc029f0ead6608d"
dependencies = [ dependencies = [
"digest 0.11.0-rc.5", "digest 0.11.0-rc.6",
"rand_core 0.10.0-rc-3", "rand_core 0.10.0-rc-3",
] ]
@ -4228,7 +4228,7 @@ dependencies = [
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"thiserror 2.0.17", "thiserror 2.0.18",
"walkdir", "walkdir",
] ]
@ -4324,11 +4324,11 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "2.0.17" version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
dependencies = [ dependencies = [
"thiserror-impl 2.0.17", "thiserror-impl 2.0.18",
] ]
[[package]] [[package]]
@ -4344,9 +4344,9 @@ dependencies = [
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "2.0.17" version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -4559,7 +4559,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "786d480bce6247ab75f005b14ae1624ad978d3029d9113f0a22fa1ac773faeaf" checksum = "786d480bce6247ab75f005b14ae1624ad978d3029d9113f0a22fa1ac773faeaf"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"thiserror 2.0.17", "thiserror 2.0.18",
"time", "time",
"tracing-subscriber", "tracing-subscriber",
] ]
@ -5842,7 +5842,7 @@ dependencies = [
"parking_lot", "parking_lot",
"percent-encoding", "percent-encoding",
"serde", "serde",
"thiserror 2.0.17", "thiserror 2.0.18",
"tokio", "tokio",
"typed-path", "typed-path",
"uzers", "uzers",
@ -5975,9 +5975,9 @@ dependencies = [
[[package]] [[package]]
name = "zmij" name = "zmij"
version = "1.0.14" version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd8f3f50b848df28f887acb68e41201b5aea6bc8a8dacc00fb40635ff9a72fea" checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65"
[[package]] [[package]]
name = "zune-core" name = "zune-core"
@ -6011,9 +6011,9 @@ dependencies = [
[[package]] [[package]]
name = "zune-jpeg" name = "zune-jpeg"
version = "0.5.9" version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87c86acb70a85b2c16f071f171847d1945e8f44812630463cd14ec83900ad01c" checksum = "2959ca473aae96a14ecedf501d20b3608d2825ba280d5adb57d651721885b0c2"
dependencies = [ dependencies = [
"zune-core 0.5.1", "zune-core 0.5.1",
] ]

View file

@ -55,7 +55,7 @@ scopeguard = "1.2.0"
serde = { version = "1.0.228", features = [ "derive" ] } serde = { version = "1.0.228", features = [ "derive" ] }
serde_json = "1.0.149" serde_json = "1.0.149"
syntect = { version = "5.3.0", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] } syntect = { version = "5.3.0", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] }
thiserror = "2.0.17" thiserror = "2.0.18"
tokio = { version = "1.49.0", features = [ "full" ] } tokio = { version = "1.49.0", features = [ "full" ] }
tokio-stream = "0.1.18" tokio-stream = "0.1.18"
tokio-util = "0.7.18" tokio-util = "0.7.18"

View file

@ -225,7 +225,7 @@ overwrite_offset = [ 0, 0, 50, 15 ]
# quit # quit
quit_title = "Quit?" quit_title = "Quit?"
quit_body = "The following tasks are still running, are you sure you want to quit?" quit_body = "There are unfinished tasks, quit anyway?\n(Open task manager with default key 'w')"
quit_origin = "center" quit_origin = "center"
quit_offset = [ 0, 0, 50, 15 ] quit_offset = [ 0, 0, 50, 15 ]

View file

@ -167,13 +167,20 @@ impl Client {
loop { loop {
if let Ok(conn) = Stream::connect().await { if let Ok(conn) = Stream::connect().await {
Pubsub::pub_inner_hi(); Pubsub::pub_inner_hi();
tracing::debug!("Connected to existing DDS server on instance {ID}");
return conn; return conn;
} }
server.take().map(|h| h.abort()); server.take().map(|h| h.abort());
*server = Server::make().await.ok(); match Server::make().await {
if server.is_some() { Ok(h) => {
super::STATE.load_or_create().await; *server = Some(h);
super::STATE.load_or_create().await;
tracing::debug!("Started new DDS server on instance {ID}");
}
Err(e) => {
tracing::error!("Could not connect to or start a new DDS server on instance {ID}: {e}");
}
} }
if mem::replace(&mut first, false) && server.is_some() { if mem::replace(&mut first, false) && server.is_some() {

View file

@ -16,8 +16,10 @@ function M:entry()
return ya.notify { title = "Fzf", content = "Not supported under virtual filesystems", timeout = 5, level = "warn" } return ya.notify { title = "Fzf", content = "Not supported under virtual filesystems", timeout = 5, level = "warn" }
end end
local _permit = ui.hide() local permit = ui.hide()
local output, err = M.run_with(cwd, selected) local output, err = M.run_with(cwd, selected)
permit:drop()
if not output then if not output then
return ya.notify { title = "Fzf", content = tostring(err), timeout = 5, level = "error" } return ya.notify { title = "Fzf", content = tostring(err), timeout = 5, level = "error" }
end end
@ -32,6 +34,9 @@ function M:entry()
end end
end end
---@param cwd Url
---@param selected Url[]
---@return string?, Error?
function M.run_with(cwd, selected) function M.run_with(cwd, selected)
local child, err = Command("fzf") local child, err = Command("fzf")
:arg("-m") :arg("-m")

View file

@ -1,3 +1,5 @@
local M = {}
local state = ya.sync(function(st) local state = ya.sync(function(st)
return { return {
cwd = tostring(cx.active.current.cwd), cwd = tostring(cx.active.current.cwd),
@ -7,9 +9,51 @@ end)
local set_state = ya.sync(function(st, empty) st.empty = empty end) local set_state = ya.sync(function(st, empty) st.empty = empty end)
local function fail(s, ...) ya.notify { title = "Zoxide", content = s:format(...), timeout = 5, level = "error" } end function M:setup(opts)
opts = opts or {}
local function options() if opts.update_db then
ps.sub(
"cd",
function()
ya.emit("shell", {
cwd = fs.cwd(),
orphan = true,
"zoxide add " .. ya.quote(tostring(cx.active.current.cwd)):gsub("%%", "%%%%"),
})
end
)
end
end
function M:entry()
local st = state()
if st.empty == nil then
st.empty = M.is_empty(st.cwd)
set_state(st.empty)
end
if st.empty then
return ya.notify {
title = "Zoxide",
content = "No directory history found, check Zoxide's doc to set it up and restart Yazi.",
timeout = 5,
level = "error",
}
end
local permit = ui.hide()
local target, err = M.run_with(st.cwd)
permit:drop()
if not target then
ya.notify { title = "Zoxide", content = tostring(err), timeout = 5, level = "error" }
elseif target ~= "" then
ya.emit("cd", { target, raw = true })
end
end
function M.options()
-- https://github.com/ajeetdsouza/zoxide/blob/main/src/cmd/query.rs#L92 -- https://github.com/ajeetdsouza/zoxide/blob/main/src/cmd/query.rs#L92
local default = { local default = {
-- Search mode -- Search mode
@ -48,7 +92,9 @@ local function options()
.. (os.getenv("YAZI_ZOXIDE_OPTS") or "") .. (os.getenv("YAZI_ZOXIDE_OPTS") or "")
end end
local function empty(cwd) ---@param cwd string
---@return boolean
function M.is_empty(cwd)
local child = Command("zoxide"):arg({ "query", "-l", "--exclude", cwd }):stdout(Command.PIPED):spawn() local child = Command("zoxide"):arg({ "query", "-l", "--exclude", cwd }):stdout(Command.PIPED):spawn()
if not child then if not child then
return true return true
@ -59,61 +105,31 @@ local function empty(cwd)
return not first return not first
end end
local function setup(_, opts) ---@param cwd string
opts = opts or {} ---@return string?, Error?
function M.run_with(cwd)
if opts.update_db then local child, err = Command("zoxide")
ps.sub( :arg({ "query", "-i", "--exclude", cwd })
"cd",
function()
ya.emit("shell", {
cwd = fs.cwd(),
orphan = true,
"zoxide add " .. ya.quote(tostring(cx.active.current.cwd)),
})
end
)
end
end
local function entry()
local st = state()
if st.empty == nil then
st.empty = empty(st.cwd)
set_state(st.empty)
end
if st.empty then
return fail("No directory history found, check Zoxide's doc to set it up and restart Yazi.")
end
local _permit = ui.hide()
local child, err1 = Command("zoxide")
:arg({ "query", "-i", "--exclude", st.cwd })
:env("SHELL", "sh") :env("SHELL", "sh")
:env("CLICOLOR", 1) :env("CLICOLOR", 1)
:env("CLICOLOR_FORCE", 1) :env("CLICOLOR_FORCE", 1)
:env("_ZO_FZF_OPTS", options()) :env("_ZO_FZF_OPTS", M.options())
:stdin(Command.INHERIT) :stdin(Command.INHERIT)
:stdout(Command.PIPED) :stdout(Command.PIPED)
:stderr(Command.PIPED) :stderr(Command.PIPED)
:spawn() :spawn()
if not child then if not child then
return fail("Failed to start `zoxide`, error: " .. err1) return nil, Err("Failed to start `zoxide`, error: %s", err)
end end
local output, err2 = child:wait_with_output() local output, err = child:wait_with_output()
if not output then if not output then
return fail("Cannot read `zoxide` output, error: " .. err2) return nil, Err("Cannot read `zoxide` output, error: %s", err)
elseif not output.status.success and output.status.code ~= 130 then elseif not output.status.success and output.status.code ~= 130 then
return fail("`zoxide` exited with code %s: %s", output.status.code, output.stderr:gsub("^zoxide:%s*", "")) return nil, Err("`zoxide` exited with code %s: %s", output.status.code, output.stderr:gsub("^zoxide:%s*", ""))
end
local target = output.stdout:gsub("\n$", "")
if target ~= "" then
ya.emit("cd", { target, raw = true })
end end
return output.stdout:gsub("\n$", ""), nil
end end
return { setup = setup, entry = entry } return M