mirror of
https://github.com/sxyazi/yazi.git
synced 2026-05-13 08:16:40 +00:00
fix: properly drop the permit for terminal resources (#3592)
This commit is contained in:
parent
ca4cc59413
commit
e6d995710f
7 changed files with 115 additions and 86 deletions
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
|
||||
"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
68
Cargo.lock
generated
|
|
@ -104,7 +104,7 @@ dependencies = [
|
|||
"ratatui-core",
|
||||
"simdutf8",
|
||||
"smallvec",
|
||||
"thiserror 2.0.17",
|
||||
"thiserror 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -255,7 +255,7 @@ dependencies = [
|
|||
"num-traits",
|
||||
"pastey",
|
||||
"rayon",
|
||||
"thiserror 2.0.17",
|
||||
"thiserror 2.0.18",
|
||||
"v_frame",
|
||||
"y4m",
|
||||
]
|
||||
|
|
@ -919,9 +919,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
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"
|
||||
checksum = "41b8986f836d4aeb30ccf4c9d3bd562fd716074cfd7fc4a2948359fbd21ed809"
|
||||
checksum = "0f4fc0003068acd7e9cb6659fd956dc4d671f102a06cc115990b9e7bb5745c25"
|
||||
dependencies = [
|
||||
"hybrid-array",
|
||||
]
|
||||
|
|
@ -1203,13 +1203,13 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.11.0-rc.5"
|
||||
version = "0.11.0-rc.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebf9423bafb058e4142194330c52273c343f8a5beb7176d052f0e73b17dd35b9"
|
||||
checksum = "2778ee7344f47967d6701053913962accf9bfdb0caa4b6d921b7c4a615f658d0"
|
||||
dependencies = [
|
||||
"block-buffer 0.11.0",
|
||||
"const-oid 0.10.2",
|
||||
"crypto-common 0.2.0-rc.9",
|
||||
"crypto-common 0.2.0-rc.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1387,9 +1387,9 @@ checksum = "dea2df4cf52843e0452895c455a1a2cfbb842a1e7329671acf418fdc53ed4c59"
|
|||
|
||||
[[package]]
|
||||
name = "euclid"
|
||||
version = "0.22.11"
|
||||
version = "0.22.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad9cdb4b747e485a12abb0e6566612956c7a1bafa3bdb8d682c5b6d403589e48"
|
||||
checksum = "df61bf483e837f88d5c2291dcf55c67be7e676b3a51acc48db3a7b163b91ed63"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
|
@ -1913,7 +1913,7 @@ dependencies = [
|
|||
"rgb",
|
||||
"tiff",
|
||||
"zune-core 0.5.1",
|
||||
"zune-jpeg 0.5.9",
|
||||
"zune-jpeg 0.5.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2004,7 +2004,7 @@ checksum = "fe44f2bbd99fcb302e246e2d6bcf51aeda346d02a365f80296a07a8c711b6da6"
|
|||
dependencies = [
|
||||
"argon2",
|
||||
"bcrypt-pbkdf",
|
||||
"digest 0.11.0-rc.5",
|
||||
"digest 0.11.0-rc.6",
|
||||
"ecdsa",
|
||||
"ed25519-dalek",
|
||||
"hex",
|
||||
|
|
@ -2087,7 +2087,7 @@ checksum = "8fe90c1150662e858c7d5f945089b7517b0a80d8bf7ba4b1b5ffc984e7230a5b"
|
|||
dependencies = [
|
||||
"hashbrown",
|
||||
"portable-atomic",
|
||||
"thiserror 2.0.17",
|
||||
"thiserror 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3060,9 +3060,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pkcs8"
|
||||
version = "0.11.0-rc.8"
|
||||
version = "0.11.0-rc.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77089aec8290d0b7bb01b671b091095cf1937670725af4fd73d47249f03b12c0"
|
||||
checksum = "80f8fa6196ede5a9f9ee95b44ca134bddc9b70e8913f9297bd58c909f5889a09"
|
||||
dependencies = [
|
||||
"der 0.8.0-rc.10",
|
||||
"spki 0.8.0-rc.4",
|
||||
|
|
@ -3371,7 +3371,7 @@ dependencies = [
|
|||
"lru",
|
||||
"serde",
|
||||
"strum",
|
||||
"thiserror 2.0.17",
|
||||
"thiserror 2.0.18",
|
||||
"unicode-segmentation",
|
||||
"unicode-truncate",
|
||||
"unicode-width",
|
||||
|
|
@ -3471,7 +3471,7 @@ dependencies = [
|
|||
"rand 0.9.2",
|
||||
"rand_chacha 0.9.0",
|
||||
"simd_helpers",
|
||||
"thiserror 2.0.17",
|
||||
"thiserror 2.0.18",
|
||||
"v_frame",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
|
@ -3527,7 +3527,7 @@ checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac"
|
|||
dependencies = [
|
||||
"getrandom 0.2.17",
|
||||
"libredox",
|
||||
"thiserror 2.0.17",
|
||||
"thiserror 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3618,9 +3618,9 @@ dependencies = [
|
|||
"const-oid 0.10.2",
|
||||
"crypto-bigint 0.7.0-rc.18",
|
||||
"crypto-primes",
|
||||
"digest 0.11.0-rc.5",
|
||||
"digest 0.11.0-rc.6",
|
||||
"pkcs1",
|
||||
"pkcs8 0.11.0-rc.8",
|
||||
"pkcs8 0.11.0-rc.9",
|
||||
"rand_core 0.10.0-rc-3",
|
||||
"sha2 0.11.0-rc.3",
|
||||
"signature 3.0.0-rc.6",
|
||||
|
|
@ -3928,7 +3928,7 @@ checksum = "aa1ae819b9870cadc959a052363de870944a1646932d274a4e270f64bf79e5ef"
|
|||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest 0.11.0-rc.5",
|
||||
"digest 0.11.0-rc.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3950,7 +3950,7 @@ checksum = "19d43dc0354d88b791216bb5c1bfbb60c0814460cc653ae0ebd71f286d0bd927"
|
|||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest 0.11.0-rc.5",
|
||||
"digest 0.11.0-rc.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -4037,7 +4037,7 @@ version = "3.0.0-rc.6"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "597a96996ccff7dfa16f052bd995b4cecc72af22c35138738dc029f0ead6608d"
|
||||
dependencies = [
|
||||
"digest 0.11.0-rc.5",
|
||||
"digest 0.11.0-rc.6",
|
||||
"rand_core 0.10.0-rc-3",
|
||||
]
|
||||
|
||||
|
|
@ -4228,7 +4228,7 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"thiserror 2.0.17",
|
||||
"thiserror 2.0.18",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
|
|
@ -4324,11 +4324,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.17"
|
||||
version = "2.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8"
|
||||
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
|
||||
dependencies = [
|
||||
"thiserror-impl 2.0.17",
|
||||
"thiserror-impl 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -4344,9 +4344,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.17"
|
||||
version = "2.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
|
||||
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -4559,7 +4559,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "786d480bce6247ab75f005b14ae1624ad978d3029d9113f0a22fa1ac773faeaf"
|
||||
dependencies = [
|
||||
"crossbeam-channel",
|
||||
"thiserror 2.0.17",
|
||||
"thiserror 2.0.18",
|
||||
"time",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
|
@ -5842,7 +5842,7 @@ dependencies = [
|
|||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde",
|
||||
"thiserror 2.0.17",
|
||||
"thiserror 2.0.18",
|
||||
"tokio",
|
||||
"typed-path",
|
||||
"uzers",
|
||||
|
|
@ -5975,9 +5975,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.14"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd8f3f50b848df28f887acb68e41201b5aea6bc8a8dacc00fb40635ff9a72fea"
|
||||
checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65"
|
||||
|
||||
[[package]]
|
||||
name = "zune-core"
|
||||
|
|
@ -6011,9 +6011,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zune-jpeg"
|
||||
version = "0.5.9"
|
||||
version = "0.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87c86acb70a85b2c16f071f171847d1945e8f44812630463cd14ec83900ad01c"
|
||||
checksum = "2959ca473aae96a14ecedf501d20b3608d2825ba280d5adb57d651721885b0c2"
|
||||
dependencies = [
|
||||
"zune-core 0.5.1",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ scopeguard = "1.2.0"
|
|||
serde = { version = "1.0.228", features = [ "derive" ] }
|
||||
serde_json = "1.0.149"
|
||||
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-stream = "0.1.18"
|
||||
tokio-util = "0.7.18"
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ overwrite_offset = [ 0, 0, 50, 15 ]
|
|||
|
||||
# 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_offset = [ 0, 0, 50, 15 ]
|
||||
|
||||
|
|
|
|||
|
|
@ -167,13 +167,20 @@ impl Client {
|
|||
loop {
|
||||
if let Ok(conn) = Stream::connect().await {
|
||||
Pubsub::pub_inner_hi();
|
||||
tracing::debug!("Connected to existing DDS server on instance {ID}");
|
||||
return conn;
|
||||
}
|
||||
|
||||
server.take().map(|h| h.abort());
|
||||
*server = Server::make().await.ok();
|
||||
if server.is_some() {
|
||||
super::STATE.load_or_create().await;
|
||||
match Server::make().await {
|
||||
Ok(h) => {
|
||||
*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() {
|
||||
|
|
|
|||
|
|
@ -16,8 +16,10 @@ function M:entry()
|
|||
return ya.notify { title = "Fzf", content = "Not supported under virtual filesystems", timeout = 5, level = "warn" }
|
||||
end
|
||||
|
||||
local _permit = ui.hide()
|
||||
local permit = ui.hide()
|
||||
local output, err = M.run_with(cwd, selected)
|
||||
|
||||
permit:drop()
|
||||
if not output then
|
||||
return ya.notify { title = "Fzf", content = tostring(err), timeout = 5, level = "error" }
|
||||
end
|
||||
|
|
@ -32,6 +34,9 @@ function M:entry()
|
|||
end
|
||||
end
|
||||
|
||||
---@param cwd Url
|
||||
---@param selected Url[]
|
||||
---@return string?, Error?
|
||||
function M.run_with(cwd, selected)
|
||||
local child, err = Command("fzf")
|
||||
:arg("-m")
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
local M = {}
|
||||
|
||||
local state = ya.sync(function(st)
|
||||
return {
|
||||
cwd = tostring(cx.active.current.cwd),
|
||||
|
|
@ -7,9 +9,51 @@ 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
|
||||
local default = {
|
||||
-- Search mode
|
||||
|
|
@ -48,7 +92,9 @@ local function options()
|
|||
.. (os.getenv("YAZI_ZOXIDE_OPTS") or "")
|
||||
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()
|
||||
if not child then
|
||||
return true
|
||||
|
|
@ -59,61 +105,31 @@ local function empty(cwd)
|
|||
return not first
|
||||
end
|
||||
|
||||
local function setup(_, opts)
|
||||
opts = opts or {}
|
||||
|
||||
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)),
|
||||
})
|
||||
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 })
|
||||
---@param cwd string
|
||||
---@return string?, Error?
|
||||
function M.run_with(cwd)
|
||||
local child, err = Command("zoxide")
|
||||
:arg({ "query", "-i", "--exclude", cwd })
|
||||
:env("SHELL", "sh")
|
||||
:env("CLICOLOR", 1)
|
||||
:env("CLICOLOR_FORCE", 1)
|
||||
:env("_ZO_FZF_OPTS", options())
|
||||
:env("_ZO_FZF_OPTS", M.options())
|
||||
:stdin(Command.INHERIT)
|
||||
:stdout(Command.PIPED)
|
||||
:stderr(Command.PIPED)
|
||||
:spawn()
|
||||
|
||||
if not child then
|
||||
return fail("Failed to start `zoxide`, error: " .. err1)
|
||||
return nil, Err("Failed to start `zoxide`, error: %s", err)
|
||||
end
|
||||
|
||||
local output, err2 = child:wait_with_output()
|
||||
local output, err = child:wait_with_output()
|
||||
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
|
||||
return fail("`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 })
|
||||
return nil, Err("`zoxide` exited with code %s: %s", output.status.code, output.stderr:gsub("^zoxide:%s*", ""))
|
||||
end
|
||||
return output.stdout:gsub("\n$", ""), nil
|
||||
end
|
||||
|
||||
return { setup = setup, entry = entry }
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue