Update 2025-01-11

This commit is contained in:
2025-01-11 18:19:28 +02:00
parent 9ae599446b
commit f441d61eca
40 changed files with 845 additions and 587 deletions

View File

@@ -1,53 +1,46 @@
local M = {}
function M:peek()
-- launch process
local process, code = Command("transmission-show")
function M:peek(job)
local child = Command("transmission-show")
:args({
tostring(self.file.url),
tostring(job.file.url),
})
:stdout(Command.PIPED)
:stderr(Command.PIPED)
:spawn()
local limit = self.area.h
-- read and count lines from process
if not child then
return require("code"):peek(job)
end
local limit = job.area.h
local i, lines = 0, ""
repeat
local next, event = process:read_line()
if event ~= 0 then
local next, event = child:read_line()
if event == 1 then
return require("code"):peek(job)
elseif event ~= 0 then
break
end
i = i + 1
-- only concatenate lines that are past 'skip' number of STDOUT
if i > self.skip then
if i > job.skip then
lines = lines .. next
end
until i >= self.skip + limit -- until reader reaches max number of lines on screen plus skip
until i >= job.skip + limit
process:start_kill()
-- if paged below all output, run peek again with smaller skip
if self.skip > 0 and i < self.skip + limit then
ya.manager_emit(
"peek",
{ tostring(math.max(0, i - limit)), only_if = tostring(self.file.url), upper_bound = "" }
)
-- preview torrent
child:start_kill()
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.Paragraph.parse(self.area, lines):wrap(ui.Paragraph.WRAP) })
lines = lines:gsub("\t", string.rep(" ", PREVIEW.tab_size))
ya.preview_widgets(job, { ui.Text.parse(lines):area(job.area) })
end
end
function M:seek(units)
local h = cx.active.current.hovered
if h and h.url == self.file.url then
local step = math.floor(units * self.area.h / 10)
ya.manager_emit("peek", {
math.max(0, cx.active.preview.skip + step),
only_if = self.file.url,
})
end
function M:seek(job)
require("code"):seek(job)
end
return M