feat: support Yazi 0.4 for lsar and mactag, https://github.com/sxyazi/yazi/pull/1966
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M:peek()
|
function M:peek(job)
|
||||||
local child, code = Command("lsar"):arg(tostring(self.file.url)):stdout(Command.PIPED):spawn()
|
-- 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
|
if not child then
|
||||||
return ya.err("spawn `lsar` command returns " .. tostring(code))
|
return ya.err("spawn `lsar` command returns " .. tostring(code))
|
||||||
end
|
end
|
||||||
@@ -14,7 +17,7 @@ function M:peek()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local limit = self.area.h
|
local limit = job.area.h
|
||||||
local i, lines = 0, {}
|
local i, lines = 0, {}
|
||||||
repeat
|
repeat
|
||||||
local next, event = child:read_line()
|
local next, event = child:read_line()
|
||||||
@@ -23,26 +26,30 @@ function M:peek()
|
|||||||
end
|
end
|
||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
if i > self.skip then
|
if i > job.skip then
|
||||||
lines[#lines + 1] = next
|
lines[#lines + 1] = next
|
||||||
end
|
end
|
||||||
until i >= self.skip + limit
|
until i >= job.skip + limit
|
||||||
|
|
||||||
child:start_kill()
|
child:start_kill()
|
||||||
if self.skip > 0 and i < self.skip + limit then
|
if job.skip > 0 and i < job.skip + limit then
|
||||||
ya.manager_emit("peek", { math.max(0, i - limit), only_if = self.file.url, upper_bound = true })
|
ya.manager_emit("peek", { math.max(0, i - limit), only_if = job.file.url, upper_bound = true })
|
||||||
else
|
else
|
||||||
ya.preview_widgets(self, { ui.Text(lines):area(self.area) })
|
ya.preview_widgets(job, { ui.Text(lines):area(job.area) })
|
||||||
end
|
end
|
||||||
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
|
local h = cx.active.current.hovered
|
||||||
if h and h.url == self.file.url then
|
if h and h.url == job.file.url then
|
||||||
local step = math.floor(units * self.area.h / 10)
|
local step = math.floor(units * job.area.h / 10)
|
||||||
ya.manager_emit("peek", {
|
ya.manager_emit("peek", {
|
||||||
math.max(0, cx.active.preview.skip + step),
|
math.max(0, cx.active.preview.skip + step),
|
||||||
only_if = self.file.url,
|
only_if = job.file.url,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -75,7 +75,10 @@ local cands = ya.sync(function(st)
|
|||||||
return t
|
return t
|
||||||
end)
|
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")
|
assert(args[1] == "add" or args[1] == "remove", "Invalid action")
|
||||||
ya.manager_emit("escape", { visual = true })
|
ya.manager_emit("escape", { visual = true })
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user