-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
58 lines (48 loc) · 1.2 KB
/
Copy pathmain.lua
File metadata and controls
58 lines (48 loc) · 1.2 KB
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
local TEXT = "ABCDEFGHIJKLM\nNOPQRSTUVWXYZ\nabcdefghijklm\nnopqrstuvwxyz\n1234567890\n!$&*()[]{}"
local TEXT = "永和九年,岁在癸丑,暮春之初,会于会稽山阴之兰亭。\n" .. TEXT
local M = {}
function M:peek(job)
local start, cache = os.clock(), ya.file_cache(job)
if not cache then
return
end
local ok, err = self:preload(job)
if not ok or err then
return ya.preview_widget(job, err)
end
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))
local _, err = ya.image_show(cache, job.area)
ya.preview_widget(job, err)
end
function M:seek() end
function M:preload(job)
local cache = ya.file_cache(job)
if not cache or fs.cha(cache) then
return true
end
local status, err = Command("magick"):arg({
"-size",
"800x560",
"-gravity",
"center",
"-font",
tostring(job.file.path):gsub("\\", "\\\\"),
"-pointsize",
64,
"xc:white",
"-fill",
"black",
"-annotate",
"+0+0",
TEXT,
"JPG:" .. tostring(cache),
}):status()
if not status then
return true, Err("Failed to start `magick`, error: %s", err)
elseif not status.success then
return false, Err("`magick` exited with error code: %s", status.code)
else
return true
end
end
return M