feat: support Yazi 0.4 for lsar and mactag, https://github.com/sxyazi/yazi/pull/1966

This commit is contained in:
sxyazi
2024-11-29 22:08:27 +08:00
parent d85bfd6f31
commit a53d544048
2 changed files with 23 additions and 13 deletions

View File

@@ -1,7 +1,10 @@
local M = {}
function M:peek()
local child, code = Command("lsar"):arg(tostring(self.file.url)):stdout(Command.PIPED):spawn()
function M:peek(job)
-- TODO: remove this once Yazi 0.4 is released
job = job or self
local child, code = Command("lsar"):arg(tostring(job.file.url)):stdout(Command.PIPED):spawn()
if not child then
return ya.err("spawn `lsar` command returns " .. tostring(code))
end
@@ -14,7 +17,7 @@ function M:peek()
end
end
local limit = self.area.h
local limit = job.area.h
local i, lines = 0, {}
repeat
local next, event = child:read_line()
@@ -23,26 +26,30 @@ function M:peek()
end
i = i + 1
if i > self.skip then
if i > job.skip then
lines[#lines + 1] = next
end
until i >= self.skip + limit
until i >= job.skip + limit
child:start_kill()
if self.skip > 0 and i < self.skip + limit then
ya.manager_emit("peek", { math.max(0, i - limit), only_if = self.file.url, upper_bound = true })
if job.skip > 0 and i < job.skip + limit then
ya.manager_emit("peek", { math.max(0, i - limit), only_if = job.file.url, upper_bound = true })
else
ya.preview_widgets(self, { ui.Text(lines):area(self.area) })
ya.preview_widgets(job, { ui.Text(lines):area(job.area) })
end
end
function M:seek(units)
function M:seek(job)
-- TODO: remove this once Yazi 0.4 is released
local units = type(job) == "table" and job.units or job
job = type(job) == "table" and job or self
local h = cx.active.current.hovered
if h and h.url == self.file.url then
local step = math.floor(units * self.area.h / 10)
if h and h.url == job.file.url then
local step = math.floor(units * job.area.h / 10)
ya.manager_emit("peek", {
math.max(0, cx.active.preview.skip + step),
only_if = self.file.url,
only_if = job.file.url,
})
end
end

View File

@@ -75,7 +75,10 @@ local cands = ya.sync(function(st)
return t
end)
local function entry(self, args)
local function entry(self, job)
-- TODO: remove this once Yazi 0.4 is released
local args = job.args or job
assert(args[1] == "add" or args[1] == "remove", "Invalid action")
ya.manager_emit("escape", { visual = true })