Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more candidates to time.lua and add ExtH/ExtI to charset.lua #350

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions sample/lua/charset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
查询unicode 编码
1. https://unicode.org/charts/

查询 Unicode 编码区
https://www.unicode.org/Public/UCD/latest/ucd/Blocks.txt

导出函数
1. charset_filter: 滤除含 CJK 扩展汉字的候选项
2. charset_comment_filter: 为候选项加上其所属字符集的注释
Expand All @@ -24,7 +27,9 @@ local charset = {
["ExtD"] = { first = 0x2B740, last = 0x2B81F }, -- CJK Unified Ideographs Extension D - https://unicode.org/charts/PDF/U2B740.pdf
["ExtE"] = { first = 0x2B820, last = 0x2CEAF }, -- CJK Unified Ideographs Extension E - https://unicode.org/charts/PDF/U2B820.pdf
["ExtF"] = { first = 0x2CEB0, last = 0x2EBEF }, -- CJK Unified Ideographs Extension F - https://unicode.org/charts/PDF/U2CEB0.pdf
["ExtG"] = { first = 0x30000, last = 0x3134A }, -- CJK Unified Ideographs Extension G - https://unicode.org/charts/PDF/U30000.pdf
["ExtG"] = { first = 0x30000, last = 0x3134F }, -- CJK Unified Ideographs Extension G - https://unicode.org/charts/PDF/U30000.pdf
["ExtH"] = { first = 0x31350, last = 0x323AF }, -- CJK Unified Ideographs Extension H - https://unicode.org/charts/PDF/U31350.pdf
["ExtI"] = { first = 0x2EBF0, last = 0x2EE5F }, -- CJK Unified Ideographs Extension I - https://unicode.org/charts/PDF/U2EBF0.pdf
["Compat"] = { first = 0xF900, last = 0xFAFF }, -- CJK Compatibility Ideographs - https://unicode.org/charts/PDF/UF900.pdf
["CompatSupp"] = { first = 0x2F800, last = 0x2FA1F } -- CJK Compatibility Ideographs Supplement - https://unicode.org/charts/PDF/U2F800.pdf
}
Expand All @@ -46,10 +51,16 @@ local function is_charset(s)
end

local function is_cjk_ext(c)
return is_charset("ExtA")(c) or is_charset("ExtB")(c) or
is_charset("ExtC")(c) or is_charset("ExtD")(c) or
is_charset("ExtE")(c) or is_charset("ExtF")(c) or
is_charset("ExtG")(c) or is_charset("Compat")(c) or
return is_charset("ExtA")(c) or
is_charset("ExtB")(c) or
is_charset("ExtC")(c) or
is_charset("ExtD")(c) or
is_charset("ExtE")(c) or
is_charset("ExtF")(c) or
is_charset("ExtG")(c) or
is_charset("ExtH")(c) or
is_charset("ExtI")(c) or
is_charset("Compat")(c) or
is_charset("CompatSupp")(c)
end

Expand Down
5 changes: 4 additions & 1 deletion sample/lua/time.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ time_translator: 将 `time` 翻译为当前时间

local function translator(input, seg)
if (input == "time") then
yield(Candidate("time", seg.start, seg._end, os.date("%H:%M:%S"), " 时间"))
yield(Candidate("time", seg.start, seg._end, os.date("%H:%M"), "时间"))
yield(Candidate("time", seg.start, seg._end, os.date("%H:%M:%S"), "时间"))
yield(Candidate("time", seg.start, seg._end, os.date("%H时%M分"),"时间"))
yield(Candidate("time", seg.start, seg._end, os.date("%H时%M分%S秒"),"时间"))
end
end

Expand Down
34 changes: 34 additions & 0 deletions sample/lua/week.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--[[
week_translator: 将 `week` 翻译为当前星期
--]]

local function translator(input, seg)
if (input == "week") then
if (os.date("%w") == "0") then
weekstr = "日"
end
if (os.date("%w") == "1") then
weekstr = "一"
end
if (os.date("%w") == "2") then
weekstr = "二"
end
if (os.date("%w") == "3") then
weekstr = "三"
end
if (os.date("%w") == "4") then
weekstr = "四"
end
if (os.date("%w") == "5") then
weekstr = "五"
end
if (os.date("%w") == "6") then
weekstr = "六"
end
yield(Candidate("week", seg.start, seg._end, "".."星期"..weekstr.."","星期"))
yield(Candidate("week", seg.start, seg._end, os.date("%Y年%m月%d日").."".."星期"..weekstr.."","星期"))
yield(Candidate("week", seg.start, seg._end, os.date("%Y年%m月%d日").."".."星期"..weekstr..""..os.date("%H:%M:%S"),"星期"))
end
end

return translator
4 changes: 4 additions & 0 deletions sample/rime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ date_translator = require("date")
-- 详见 `lua/time.lua`
time_translator = require("time")

-- week_translator: 将 `week` 翻译为当前星期
-- 详见 `lua/week.lua`
week_translator = require("week")

-- number_translator: 将 `/` + 阿拉伯数字 翻译为大小写汉字
-- 详见 `lua/number.lua`
number_translator = require("number")
Expand Down