refactor: lua; close #352

This commit is contained in:
Dvel
2023-06-15 22:21:06 +08:00
parent ab066356f8
commit 314b3621af
5 changed files with 65 additions and 62 deletions

View File

@@ -1,14 +1,18 @@
-- 根据是否在用户词典,在结尾加上一个星号 *
-- is_in_user_dict: true 输入过的内容
-- is_in_user_dict: flase 或不写 未输入过的内容
local function is_in_user_dict(input, env)
if not env.is_in_user_dict then
local config = env.engine.schema.config
env.name_space = env.name_space:gsub('^*', '')
env.is_in_user_dict = config:get_bool(env.name_space)
end
local M = {}
function M.init(env)
local config = env.engine.schema.config
env.name_space = env.name_space:gsub('^*', '')
M.is_in_user_dict = config:get_bool(env.name_space)
end
function M.func(input, env)
for cand in input:iter() do
if env.is_in_user_dict then
if M.is_in_user_dict then
if cand.type == "user_phrase" then
cand.comment = cand.comment .. '*'
end
@@ -21,4 +25,4 @@ local function is_in_user_dict(input, env)
end
end
return is_in_user_dict
return M