mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: add maximum preview limit under /proc virtual file system (#2355)
This commit is contained in:
parent
3ec832b9d8
commit
1ddbbfea71
1 changed files with 20 additions and 7 deletions
|
|
@ -12,10 +12,25 @@ function M:peek(job)
|
||||||
return self.msg(job, "Empty file")
|
return self.msg(job, "Empty file")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local i, j, lines = 0, 0, {}
|
||||||
|
local file = io.open(path, "r")
|
||||||
|
if not file then
|
||||||
|
return self.msg(job, "Failed to open file")
|
||||||
|
end
|
||||||
|
|
||||||
local limit = job.area.h
|
local limit = job.area.h
|
||||||
local i, lines = 0, {}
|
while true do
|
||||||
local ok, err = pcall(function()
|
local chunk = file:read(4096)
|
||||||
for line in io.lines(path) do
|
if not chunk then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
j = j + #chunk
|
||||||
|
if j > 5242880 then
|
||||||
|
return self.msg(job, "File too large")
|
||||||
|
end
|
||||||
|
|
||||||
|
for line in chunk:gmatch("[^\n]*\n?") do
|
||||||
i = i + 1
|
i = i + 1
|
||||||
if i > job.skip + limit then
|
if i > job.skip + limit then
|
||||||
break
|
break
|
||||||
|
|
@ -23,11 +38,9 @@ function M:peek(job)
|
||||||
lines[#lines + 1] = line
|
lines[#lines + 1] = line
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
if not ok then
|
if job.skip > 0 and i < job.skip + limit then
|
||||||
self.msg(job, err)
|
|
||||||
elseif 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 })
|
ya.manager_emit("peek", { math.max(0, i - limit), only_if = job.file.url, upper_bound = true })
|
||||||
else
|
else
|
||||||
ya.preview_widgets(job, { ui.Text(lines):area(job.area) })
|
ya.preview_widgets(job, { ui.Text(lines):area(job.area) })
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue