-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrime.lua
63 lines (57 loc) · 2.33 KB
/
rime.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
--- 过滤器:单字在先
function single_char_first_filter(input)
local l = {}
for cand in input:iter() do
if (utf8.len(cand.text) == 1) then
yield(cand)
else
table.insert(l, cand)
end
end
for cand in ipairs(l) do
yield(cand)
end
end
--- 计算器
--- @KyleBing 2022-01-17
function calculator(input, seg)
if string.find(input, 'coco') ~= nil then -- 匹配 coco 开头的字符串
local _, _, a, operation, b = string.find(input, "coco(%d+%.?%d*)([%+%-%*/])(%d+%.?%d*)")
local result = 0
if operation == '+' then
result = a + b
elseif operation == '-' then
result = a - b
elseif operation == '*' then
result = a * b
elseif operation == '/' then
result = a / b
end
yield(Candidate("coco", seg.start, seg._end, result, "计算器"))
end
end
function date_translator(input, seg)
if (input == "date") then
--- Candidate(type, start, end, text, comment)
yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%Y.%m.%d"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%Y/%m/%d"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%m-%d-%Y"), ""))
end
if (input == "time") then
--- Candidate(type, start, end, text, comment)
yield(Candidate("time", seg.start, seg._end, os.date("%H:%M"), ""))
yield(Candidate("time", seg.start, seg._end, os.date("%H点%M分"), " "))
yield(Candidate("time", seg.start, seg._end, os.date("%Y%m%d%H%M%S"), ""))
yield(Candidate("time", seg.start, seg._end, os.date("%H:%M:%S"), ""))
yield(Candidate("time", seg.start, seg._end, os.date("%H点%M分%S秒"), " "))
end
-- @JiandanDream
-- https://github.com/KyleBing/rime-wubi86-jidian/issues/54
if (input == "week") then
local weakTab = {'日', '一', '二', '三', '四', '五', '六'}
yield(Candidate("week", seg.start, seg._end, "周"..weakTab[tonumber(os.date("%w")+1)], ""))
yield(Candidate("week", seg.start, seg._end, "星期"..weakTab[tonumber(os.date("%w")+1)], ""))
end
end