2024-08-14 10:03:38 +03:00
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M:msg(s)
|
|
|
|
local p = ui.Paragraph(self.area, {
|
2024-08-24 21:56:38 +03:00
|
|
|
ui.Line(s):reverse(),
|
2024-08-14 10:03:38 +03:00
|
|
|
})
|
|
|
|
ya.preview_widgets(self, { p:wrap(ui.Paragraph.WRAP) })
|
|
|
|
end
|
|
|
|
|
|
|
|
function M:peek()
|
|
|
|
local path = tostring(self.file.url)
|
|
|
|
if path:sub(1, 6) ~= "/proc/" then
|
|
|
|
return self:msg("Empty file")
|
|
|
|
end
|
|
|
|
|
|
|
|
local limit = self.area.h
|
|
|
|
local i, lines = 0, {}
|
|
|
|
local ok, err = pcall(function()
|
|
|
|
for line in io.lines(path) do
|
|
|
|
i = i + 1
|
|
|
|
if i > self.skip + limit then
|
|
|
|
break
|
|
|
|
elseif i > self.skip then
|
|
|
|
lines[#lines + 1] = ui.Line(line)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
if not ok then
|
|
|
|
self:msg(err)
|
|
|
|
elseif 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 })
|
|
|
|
else
|
|
|
|
ya.preview_widgets(self, { ui.Paragraph(self.area, lines) })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-03 03:21:17 +03:00
|
|
|
function M:seek(units) require("code").seek(self, units) end
|
2024-08-14 10:03:38 +03:00
|
|
|
|
|
|
|
return M
|