diff --git a/lsar.yazi/init.lua b/lsar.yazi/init.lua index 135a738..b7e46dd 100644 --- a/lsar.yazi/init.lua +++ b/lsar.yazi/init.lua @@ -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 diff --git a/mactag.yazi/init.lua b/mactag.yazi/init.lua index 3fc08fe..7557fcf 100644 --- a/mactag.yazi/init.lua +++ b/mactag.yazi/init.lua @@ -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 })