2023-12-26 14:48:33 +03:00
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M:peek()
|
2023-12-30 18:41:41 +03:00
|
|
|
local child = Command("jq")
|
2023-12-26 14:48:33 +03:00
|
|
|
:args({
|
|
|
|
"-C",
|
|
|
|
"--tab",
|
|
|
|
".",
|
|
|
|
tostring(self.file.url),
|
|
|
|
})
|
|
|
|
:stdout(Command.PIPED)
|
|
|
|
:stderr(Command.PIPED)
|
|
|
|
:spawn()
|
|
|
|
|
2024-01-01 13:28:38 +03:00
|
|
|
if not child then
|
2024-09-20 19:23:46 +03:00
|
|
|
return require("code").peek(self)
|
2024-01-01 13:28:38 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local limit = self.area.h
|
2023-12-26 14:48:33 +03:00
|
|
|
local i, lines = 0, ""
|
|
|
|
repeat
|
2024-01-01 13:28:38 +03:00
|
|
|
local next, event = child:read_line()
|
|
|
|
if event == 1 then
|
2024-09-20 19:23:46 +03:00
|
|
|
return require("code").peek(self)
|
2024-01-01 13:28:38 +03:00
|
|
|
elseif event ~= 0 then
|
2023-12-26 14:48:33 +03:00
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
i = i + 1
|
|
|
|
if i > self.skip then
|
|
|
|
lines = lines .. next
|
|
|
|
end
|
|
|
|
until i >= self.skip + limit
|
|
|
|
|
|
|
|
child:start_kill()
|
|
|
|
if self.skip > 0 and i < self.skip + limit then
|
2024-04-22 09:18:00 +03:00
|
|
|
ya.manager_emit("peek", { math.max(0, i - limit), only_if = self.file.url, upper_bound = true })
|
2023-12-26 14:48:33 +03:00
|
|
|
else
|
|
|
|
lines = lines:gsub("\t", string.rep(" ", PREVIEW.tab_size))
|
2024-10-13 20:54:03 +03:00
|
|
|
ya.preview_widgets(self, { ui.Text.parse(lines):area(self.area) })
|
2023-12-26 14:48:33 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-03 03:21:17 +03:00
|
|
|
function M:seek(units) require("code").seek(self, units) end
|
2023-12-26 14:48:33 +03:00
|
|
|
|
|
|
|
return M
|