-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.lua
66 lines (54 loc) · 1.17 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
local M = {}
function M:peek(job)
local cache = ya.file_cache(job)
if not cache then
return
end
if not self:preload(job) then
return
end
local t = io.open(tostring(cache), "r")
if t == nil then return 0 end
local thumb = Url(t:read())
t:close()
ya.image_show(thumb, job.area)
ya.preview_widgets(job, {})
end
function M:seek() end
function M:preload(job)
local cache = ya.file_cache(job)
if not cache or fs.cha(cache) then
return 1
end
local output = Command("allmytoes")
:args({ "-sxx", tostring(job.file.url) })
:stdout(Command.PIPED)
:stderr(Command.PIPED)
:output()
-- yazi 0.2.5
local function check_output_v025()
if output.status:success() then
return true
end
return false
end
-- yazi 0.3
local function check_output_v03()
if output.status.success then
return true
end
return false
end
if pcall(check_output_v03) then
elseif pcall(check_output_v025) then
else
ya.err(
"Could not obtain thumbnail for " .. tostring(job.file.url)
.. ". allmytoes output: " .. tostring(output.stderr)
)
return 0
end
local thumb = string.gsub(tostring(output.stdout), "\n", "")
return fs.write(cache, thumb) and 1 or 2
end
return M