diff --git a/default.custom.yaml b/default.custom.yaml index f3c7a93..418d3f1 100644 --- a/default.custom.yaml +++ b/default.custom.yaml @@ -10,9 +10,8 @@ patch: - {schema: wubi98_ci} - {schema: wubi98_S} - {schema: wubi98_U} - - {schema: wb_spelling} + # - {schema: wb_spelling} - {schema: py} - - {schema: wubi98_openfly_extra} - schema: xkjd6cx - schema: xkjd6_bj - schema: xkjd6 diff --git a/wubi98_openfly_extra.dict.yaml b/dicts/openfly/openfly.extend.dict.yaml similarity index 99% rename from wubi98_openfly_extra.dict.yaml rename to dicts/openfly/openfly.extend.dict.yaml index 15da2f9..a3a02ca 100644 --- a/wubi98_openfly_extra.dict.yaml +++ b/dicts/openfly/openfly.extend.dict.yaml @@ -6,24 +6,10 @@ --- # zhwiki # moegirl -name: wubi98_openfly_extra +name: openfly.extend version: "20220503" sort: by_weight use_preset_vocabulary: false -import_tables: - - 'openfly.user.top' - - 'openfly.fast.symbols' - - 'openfly.primary' - - 'openfly.secondary.short.code' - - 'openfly.secondary' - # - 'openfly.completion' - # - 'openfly.embedded.hint' - - 'openfly.off-table' - - 'openfly.whimsicality' - - 'openfly.symbols' - - 'openfly.web' - - 'openfly.uncommon' - - 'openfly.user' ... 吖丙啶 abdk 吖丁啶 addk diff --git a/lua/Lfmt.lua b/lua/Lfmt.lua new file mode 100644 index 0000000..b2b29e7 --- /dev/null +++ b/lua/Lfmt.lua @@ -0,0 +1,10 @@ +local function Lfmt(logger, level) + return function(fmt, ...) + local info = debug.getinfo(2, "Sl") + local lineinfo = info.short_src .. ":" .. info.currentline + local msg = string.format("[%-6s] " .. fmt .. "\n", logger, ...) + log[level](msg, 1234) + end +end + +return Lfmt diff --git a/lua/flypy/calculator_translator.lua b/lua/flypy/calculator_translator.lua index 645bcdc..3cd2532 100644 --- a/lua/flypy/calculator_translator.lua +++ b/lua/flypy/calculator_translator.lua @@ -27,27 +27,28 @@ -- - 如目錄/文件不存在,請自行創建 -- 定義全局函數、常數(注意命名空間污染) -cos = math.cos -sin = math.sin -tan = math.tan -acos = math.acos -asin = math.asin -atan = math.atan -rad = math.rad -deg = math.deg - -abs = math.abs -floor = math.floor -ceil = math.ceil -mod = math.fmod -trunc = function(x, dc) +local math_env = {} +math_env.cos = math.cos +math_env.sin = math.sin +math_env.tan = math.tan +math_env.acos = math.acos +math_env.asin = math.asin +math_env.atan = math.atan +math_env.rad = math.rad +math_env.deg = math.deg + +math_env.abs = math.abs +math_env.floor = math.floor +math_env.ceil = math.ceil +math_env.mod = math.fmod +math_env.trunc = function(x, dc) if dc == nil then return math.modf(x) end return x - mod(x, dc) end -round = function(x, dc) +math_env.round = function(x, dc) dc = dc or 1 local dif = mod(x, dc) if abs(dif) > dc / 2 then @@ -56,23 +57,23 @@ round = function(x, dc) return x - dif end -random = math.random -randomseed = math.randomseed +math_env.random = math.random +math_env.randomseed = math.randomseed -inf = math.huge -MAX_INT = math.maxinteger -MIN_INT = math.mininteger -pi = math.pi -sqrt = math.sqrt -exp = math.exp -e = exp(1) -ln = math.log -log = function(x, base) +math_env.inf = math.huge +math_env.MAX_INT = math.maxinteger +math_env.MIN_INT = math.mininteger +math_env.pi = math.pi +math_env.sqrt = math.sqrt +math_env.exp = math.exp +math_env.e = math.exp(1) +math_env.ln = math.log +math_env.log = function(x, base) base = base or 10 return ln(x) / ln(base) end -min = function(arr) +math_env.min = function(arr) local m = inf for k, x in ipairs(arr) do m = x < m and x or m @@ -80,7 +81,7 @@ min = function(arr) return m end -max = function(arr) +math_env.max = function(arr) local m = -inf for k, x in ipairs(arr) do m = x > m and x or m @@ -88,7 +89,7 @@ max = function(arr) return m end -sum = function(t) +math_env.sum = function(t) local acc = 0 for k, v in ipairs(t) do acc = acc + v @@ -96,16 +97,18 @@ sum = function(t) return acc end -avg = function(t) +math_env.avg = function(t) return sum(t) / #t end -isinteger = function(x) +local isinteger = function(x) return math.fmod(x, 1) == 0 end +math_env.isinteger = isinteger + -- iterator . array -array = function(...) +math_env.array = function(...) local arr = {} for v in ... do arr[#arr + 1] = v @@ -114,7 +117,7 @@ array = function(...) end -- iterator <- [form, to) -irange = function(from, to, step) +math_env.irange = function(from, to, step) if to == nil then to = from from = 0 @@ -131,12 +134,12 @@ irange = function(from, to, step) end -- array <- [form, to) -range = function(from, to, step) +math_env.range = function(from, to, step) return array(irange(from, to, step)) end -- array . reversed iterator -irev = function(arr) +math_env.irev = function(arr) local i = #arr + 1 return function() if i > 1 then @@ -147,11 +150,11 @@ irev = function(arr) end -- array . reversed array -arev = function(arr) +math_env.arev = function(arr) return array(irev(arr)) end -test = function(f, t) +math_env.test = function(f, t) for k, v in ipairs(t) do if not f(v) then return false @@ -161,7 +164,7 @@ test = function(f, t) end -- # Functional -map = function(t, ...) +math_env.map = function(t, ...) local ta = {} for k, v in pairs(t) do local tmp = v @@ -173,7 +176,7 @@ map = function(t, ...) return ta end -filter = function(t, ...) +math_env.filter = function(t, ...) local ta = {} local i = 1 for k, v in pairs(t) do @@ -193,7 +196,7 @@ filter = function(t, ...) end -- e.g: foldr({2,3},\n,x.x^n|,2) = 81 -foldr = function(t, f, acc) +math_env.foldr = function(t, f, acc) for k, v in pairs(t) do acc = f(acc, v) end @@ -201,7 +204,7 @@ foldr = function(t, f, acc) end -- e.g: foldl({2,3},\n,x.x^n|,2) = 512 -foldl = function(t, f, acc) +math_env.foldl = function(t, f, acc) for v in irev(t) do acc = f(acc, v) end @@ -213,7 +216,7 @@ end -- = floor(map(map(map(range(-5,5),\x.x/5|),sin),\x.e^x*10|)) -- = {4, 4, 5, 6, 8, 10, 12, 14, 17, 20} -- 可以用 $ 代替 chain -chain = function(t) +math_env.chain = function(t) local ta = t local function cf(f, ...) if f ~= nil then @@ -227,7 +230,7 @@ chain = function(t) end -- # Statistics -fac = function(n) +math_env.fac = function(n) local acc = 1 for i = 2, n do acc = acc * i @@ -235,15 +238,15 @@ fac = function(n) return acc end -nPr = function(n, r) +math_env.nPr = function(n, r) return fac(n) / fac(n - r) end -nCr = function(n, r) +math_env.nCr = function(n, r) return nPr(n, r) / fac(r) end -MSE = function(t) +math_env.MSE = function(t) local ss = 0 local s = 0 local n = #t @@ -258,7 +261,7 @@ end -- # Calculus -- Linear approximation -lapproxd = function(f, delta) +math_env.lapproxd = function(f, delta) local delta = delta or 1e-8 return function(x) return (f(x + delta) - f(x)) / delta @@ -266,7 +269,7 @@ lapproxd = function(f, delta) end -- Symmetric approximation -sapproxd = function(f, delta) +math_env.sapproxd = function(f, delta) local delta = delta or 1e-8 return function(x) return (f(x + delta) - f(x - delta)) / delta / 2 @@ -274,7 +277,7 @@ sapproxd = function(f, delta) end -- 近似導數 -deriv = function(f, delta, dc) +math_env.deriv = function(f, delta, dc) dc = dc or 1e-4 local fd = sapproxd(f, delta) return function(x) @@ -283,7 +286,7 @@ deriv = function(f, delta, dc) end -- Trapezoidal rule -trapzo = function(f, a, b, n) +math_env.trapzo = function(f, a, b, n) local dif = b - a local acc = 0 for i = 1, n - 1 do @@ -295,7 +298,7 @@ trapzo = function(f, a, b, n) end -- 近似積分 -integ = function(f, delta, dc) +math_env.integ = function(f, delta, dc) delta = delta or 1e-4 dc = dc or 1e-4 return function(a, b) @@ -309,7 +312,7 @@ integ = function(f, delta, dc) end -- Runge-Kutta -rk4 = function(f, timestep) +math_env.rk4 = function(f, timestep) local timestep = timestep or 0.01 return function(start_x, start_y, time) local x = start_x @@ -329,13 +332,14 @@ rk4 = function(f, timestep) end -- # System -date = os.date -time = os.time -path = function() +math_env.date = os.date +math_env.time = os.time +math_env.path = function() return debug.getinfo(1).source:match("@?(.*/)") end -local function serialize(obj) +local floor = math.floor +local serialize = function(obj) local type = type(obj) if type == "number" then return isinteger(obj) and floor(obj) or obj @@ -396,8 +400,9 @@ local function calculator_translator(input, seg) return end -- return語句保證了只有合法的Lua表達式才可執行 - local result = load("return " .. expe)() + local result = load("return " .. expe, "calculate", "bt", math_env)() if result == nil then + log.error("calculate error") return end diff --git a/lua/wubi98/Submit_text.lua b/lua/wubi98/Submit_text.lua index 96facda..e23204d 100644 --- a/lua/wubi98/Submit_text.lua +++ b/lua/wubi98/Submit_text.lua @@ -1,115 +1,118 @@ -local local_require = require('util').get_local_require("wubi98") -local basic = local_require('lib/basic') -local map = basic.map -local index = basic.index -local utf8chars = basic.utf8chars -local matchstr = basic.matchstr - -local function commit_text_processor(key, env) - local engine = env.engine - local context = engine.context - local composition = context.composition - local segment = composition:back() - local input_text = context.input - local schema_name=env.engine.schema.schema_name or "" - local page_size = env.engine.schema.page_size - local schema_id=env.engine.schema.schema_id or "" - local candidate_count =0 - - if input_text:find("^%p*(%a+%d*)$") then - if context:has_menu() then - candidate_count = segment.menu:candidate_count() - end - env.last_1th_text=context:get_commit_text() or "" - env.last_2th_text={text="",type=""} - env.last_3th_text={text="",type=""} - if candidate_count>1 then - env.last_2th_text=segment:get_candidate_at(1) - if candidate_count>2 then - env.last_3th_text=segment:get_candidate_at(2) - end - end - end - - -- `引导精准造词记录保存 - -- 0x20空格,0x31大键盘数字1 - if input_text:find("^%`*(%l+%`%l+)") then - local commit_text=context:get_commit_text() or "" - if commit_text~="" and not commit_text:find("(%a)") and utf8.len(commit_text)>1 then - env.userphrase=commit_text - if segment.prompt:find('(%a+)') then - env.inputtext=segment.prompt:gsub('[^%a]','') - else - env.inputtext=input_text - end - end - else - if key.keycode==0x20 or key.keycode>0x30 and key.keycode<0x39 then - if env.userphrase~="" and env.userphrase~=nil and userphrasepath~="" then - -- engine:commit_text(env.userphrase..env.inputtext.."\r") - fileappendtext(userphrasepath,env.userphrase,env.inputtext,schema_name) env.userphrase="" env.inputtext="" - end - end - end - - if key.keycode==0x27 and context:is_composing() and env.last_3th_text.text~="" then - if env.last_3th_text.type=="reverse_lookup" or env.last_3th_text.type=="table" then - context:clear() - engine:commit_text(env.last_3th_text.text) - return 1 - end - end - - local m,n=input_text:find("^(%a+%d*)([%[%/%]\\])") - if n~=nil and m~=nil then - if (context:is_composing()) then - -- local focus_text = context:get_commit_text() - -- engine:commit_text(focus_text) - context:clear() - if input_text:find("^%u+%l*%d*") then -- 大写字母引导的日期反查与转换功能,[ 和 ] 分别对应二选三选 - if input_text:find("%[") then - engine:commit_text(env.last_2th_text.text) - elseif input_text:find("%]") then - engine:commit_text(env.last_3th_text.text) - end - else - engine:commit_text(env.last_1th_text..CandidateText[1]) -- 第1个候选标点符号 - end - return 1 - end - end - return 2 -end - --- 记录自造词、文件路径userphrasepath在rime.lua中定义 -local function fileappendtext(filepath,context,input,schemaname) - if not context:find('%a') then - input=splitinput(input,utf8.len(context)) - context=context.."\t"..input.."\t〔"..schemaname.."〕" - local f=io.open(filepath,"a+") - local usertext=f:read("*a") - if not usertext:find("[\r\n]*"..context) then - f:write(context.."\r") - end - f:close() - end -end - --- 格式化五笔组合编码 -local function splitinput(input,len) - input="`"..input:gsub("%`*$","") - if len==2 and input:find("(%`%l%l+%`%l%l+)") then - input=input:gsub('(%`%l%l)%l*(%`%l%l)%l*', '%1%2') - return input:gsub('%`', '') - elseif len==3 and input:find("(%`%l%l+%`%l%l+%`%l%l+)") then - input=input:gsub('(%`%l)%l+(%`%l)%l+(%`%l%l)%l*', '%1%2%3') - return input:gsub('%`', '') - elseif len>3 and input:find("(%`%l%l+%`%l%l+%`%l%l+.*%`%l%l+)$") then - input=input:gsub('(%`%l)%l+(%`%l)%l+(%`%l).*(%`%l)%l+$', '%1%2%3%4') - return input:gsub('`', '') - else - return input:gsub('^%`*', '') - end -end - -return commit_text_processor +local local_require = require("util").get_local_require("wubi98") +local basic = local_require("lib/basic") +local map = basic.map +local index = basic.index +local utf8chars = basic.utf8chars +local matchstr = basic.matchstr + +local function commit_text_processor(key, env) + local engine = env.engine + local context = engine.context + local composition = context.composition + local segment = composition:back() + local input_text = context.input + local schema_name = env.engine.schema.schema_name or "" + local page_size = env.engine.schema.page_size + local schema_id = env.engine.schema.schema_id or "" + local candidate_count = 0 + + if input_text:find("^%p*(%a+%d*)$") then + if context:has_menu() then + candidate_count = segment.menu:candidate_count() + end + env.last_1th_text = context:get_commit_text() or "" + env.last_2th_text = { text = "", type = "" } + env.last_3th_text = { text = "", type = "" } + if candidate_count > 1 then + env.last_2th_text = segment:get_candidate_at(1) + if candidate_count > 2 then + env.last_3th_text = segment:get_candidate_at(2) + end + end + end + + -- `引导精准造词记录保存 + -- 0x20空格,0x31大键盘数字1 + if input_text:find("^%`*(%l+%`%l+)") then + local commit_text = context:get_commit_text() or "" + if commit_text ~= "" and not commit_text:find("(%a)") and utf8.len(commit_text) > 1 then + env.userphrase = commit_text + if segment.prompt:find("(%a+)") then + env.inputtext = segment.prompt:gsub("[^%a]", "") + else + env.inputtext = input_text + end + end + else + if key.keycode == 0x20 or key.keycode > 0x30 and key.keycode < 0x39 then + if env.userphrase ~= "" and env.userphrase ~= nil and Wubi98Context.userphrasepath ~= "" then + -- engine:commit_text(env.userphrase..env.inputtext.."\r") + Wubi98Context.fileappendtext(Wubi98Context.userphrasepath, env.userphrase, env.inputtext, schema_name) + env.userphrase = "" + env.inputtext = "" + end + end + end + + if key.keycode == 0x27 and context:is_composing() and env.last_3th_text.text ~= "" then + if env.last_3th_text.type == "reverse_lookup" or env.last_3th_text.type == "table" then + context:clear() + engine:commit_text(env.last_3th_text.text) + return 1 + end + end + + local m, n = input_text:find("^(%a+%d*)([%[%/%]\\])") + if n ~= nil and m ~= nil then + if context:is_composing() then + -- local focus_text = context:get_commit_text() + -- engine:commit_text(focus_text) + context:clear() + if input_text:find("^%u+%l*%d*") then -- 大写字母引导的日期反查与转换功能,[ 和 ] 分别对应二选三选 + if input_text:find("%[") then + engine:commit_text(env.last_2th_text.text) + elseif input_text:find("%]") then + engine:commit_text(env.last_3th_text.text) + end + else + engine:commit_text(env.last_1th_text .. CandidateText[1]) -- 第1个候选标点符号 + end + return 1 + end + end + return 2 +end + +-- 记录自造词、文件路径Wubi98Context.userphrasepath在rime.lua中定义 +Wubi98Context.fileappendtext = function(filepath, context, input, schemaname) + lfmt("%s %s", input, filepath) + if not context:find("%a") then + input = Wubi98Context.splitinput(input, utf8.len(context)) + context = context .. "\t" .. input .. "\t〔" .. schemaname .. "〕" + local f = io.open(filepath, "a+") + local usertext = f:read("*a") + if not usertext:find("[\r\n]*" .. context) then + f:write(context .. "\r") + end + f:close() + end +end + +-- 格式化五笔组合编码 +Wubi98Context.splitinput = function(input, len) + input = "`" .. input:gsub("%`*$", "") + if len == 2 and input:find("(%`%l%l+%`%l%l+)") then + input = input:gsub("(%`%l%l)%l*(%`%l%l)%l*", "%1%2") + return input:gsub("%`", "") + elseif len == 3 and input:find("(%`%l%l+%`%l%l+%`%l%l+)") then + input = input:gsub("(%`%l)%l+(%`%l)%l+(%`%l%l)%l*", "%1%2%3") + return input:gsub("%`", "") + elseif len > 3 and input:find("(%`%l%l+%`%l%l+%`%l%l+.*%`%l%l+)$") then + input = input:gsub("(%`%l)%l+(%`%l)%l+(%`%l).*(%`%l)%l+$", "%1%2%3%4") + return input:gsub("`", "") + else + return input:gsub("^%`*", "") + end +end + +return commit_text_processor diff --git a/lua/wubi98/helper.lua b/lua/wubi98/helper.lua index 0ba4326..24b37d2 100644 --- a/lua/wubi98/helper.lua +++ b/lua/wubi98/helper.lua @@ -4,13 +4,21 @@ local function translator(input, seg, env) local composition = env.engine.context.composition local segment = composition:back() - if input == rv_var.help then + if input == Wubi98Context.rv_var.help then local table = { - { "时间输出", "→ " .. rv_var.date_var .. "|" .. rv_var.time_var .. "|" .. rv_var.week_var }, - { "历法节气", "→ " .. rv_var.nl_var .. "|" .. rv_var.jq_var }, + { + "时间输出", + "→ " + .. Wubi98Context.rv_var.date_var + .. "|" + .. Wubi98Context.rv_var.time_var + .. "|" + .. Wubi98Context.rv_var.week_var, + }, + { "历法节气", "→ " .. Wubi98Context.rv_var.nl_var .. "|" .. Wubi98Context.rv_var.jq_var }, { "农历反查", "→ 任意大写字母引导+数字日期" }, - { "功能切换", "→ " .. rv_var.switch_keyword }, - { "方案切换", "→ " .. rv_var.switch_schema }, + { "功能切换", "→ " .. Wubi98Context.rv_var.switch_keyword }, + { "方案切换", "→ " .. Wubi98Context.rv_var.switch_schema }, { "注解上屏", "→ Ctrl + Shift + Return" }, { "折分显隐", "→ Ctrl+Shift+H" }, { "注解切换", "→ Ctrl+Shift +J" }, @@ -23,7 +31,7 @@ local function translator(input, seg, env) { "精准造词", "→ `键引导精准造词" }, { "选单", "→ Ctrl+` 或 F4" }, { "lua字符串", "→ 以大写字母开头触发" }, - { "帮助", "→ " .. rv_var.help }, + { "帮助", "→ " .. Wubi98Context.rv_var.help }, { "官网", "http://www.98wubi.com" }, { "下载", "http://98wb.ys168.com" }, { "项目", "https://github.com/98wb" }, diff --git a/lua/wubi98/init.lua b/lua/wubi98/init.lua index a328707..ecfc239 100644 --- a/lua/wubi98/init.lua +++ b/lua/wubi98/init.lua @@ -1,4 +1,5 @@ local local_require = require("util").get_local_require("wubi98") +Wubi98Context = {} ------------------------------------ ------wirting by 98wubi Group------- ------http://98wb.ys168.com/-------- @@ -10,25 +11,25 @@ local local_require = require("util").get_local_require("wubi98") -- --=========================================================;关键字修改--========================================================== -- --==========================================================--========================================================== -rv_var = { +Wubi98Context.rv_var = { week_var = "week", date_var = "date", - nl_var = "nlnl", + nl_var = "nl", time_var = "time", - jq_var = "jqjq", + jq_var = "jq", switch_keyword = "next", help = "help", switch_schema = "mode", } -- 编码关键字修改 -trad_keyword = "zh_trad" -- 简繁切换switcher参数 -single_keyword = "single_char" -- 单字过滤switcher参数 -spelling_keyword = "new_spelling" -- 拆分switcher参数 -GB2312_keyword = "GB2312" -- GB2312开关switcher参数 -candidate_keywords = { - { "简繁", "簡繁", trad_keyword }, - { "拆分", "拆分", spelling_keyword }, - { "GB2312过滤", "GB2312過濾", GB2312_keyword }, - { "单字模式", "單字模式", single_keyword }, +Wubi98Context.trad_keyword = "zh_trad" -- 简繁切换switcher参数 +Wubi98Context.single_keyword = "single_char" -- 单字过滤switcher参数 +Wubi98Context.spelling_keyword = "new_spelling" -- 拆分switcher参数 +Wubi98Context.GB2312_keyword = "GB2312" -- GB2312开关switcher参数 +Wubi98Context.candidate_keywords = { + { "简繁", "簡繁", Wubi98Context.trad_keyword }, + { "拆分", "拆分", Wubi98Context.spelling_keyword }, + { "GB2312过滤", "GB2312過濾", Wubi98Context.GB2312_keyword }, + { "单字模式", "單字模式", Wubi98Context.single_keyword }, } -- 活动开关项关键字 -- --==========================================================--========================================================== -- --==========================================================--========================================================== @@ -105,7 +106,7 @@ end local rime_dirs = GetRimeAllDir() local RimeDefalutDir = "" -enable_schema_list = get_schema_list() +Wubi98Context.enable_schema_list = get_schema_list() local debug_path = debug.getinfo(1, "S").source:sub(2):sub(1, -10) if rime_dirs.shared_data_dir == debug_path then RimeDefalutDir = rime_dirs.shared_data_dir @@ -114,16 +115,18 @@ elseif rime_dirs.user_data_dir == debug_path then else RimeDefalutDir = debug_path end +lfmt("RimeDefalutDir: %s", RimeDefalutDir) -- --=========================================================精准造词文件存放路径=========================================================== -- 精准造词文件存放路径 will export -userphrasepath = "" +Wubi98Context.userphrasepath = "" if RimeDefalutDir ~= "" then if RimeDefalutDir:find("\\") then - userphrasepath = RimeDefalutDir .. "\\userphrase.txt" + Wubi98Context.userphrasepath = RimeDefalutDir .. "\\userphrase.txt" elseif RimeDefalutDir:find("/") then - userphrasepath = RimeDefalutDir .. "/userphrase.txt" + Wubi98Context.userphrasepath = RimeDefalutDir .. "/userphrase.txt" end end +lfmt("Wubi98Context.userphrasepath: %s", Wubi98Context.userphrasepath) -- --=========================================================读取lua目录下hotstring.txt文件=========================================================== -- --======================================================格式:编码+Tab+字符串+Tab+字符串说明======================================================== local function FileIsExist(name) @@ -376,7 +379,7 @@ end -- 公历日期 local function date_translator(input, seg) - local keyword = rv_var["date_var"] + local keyword = Wubi98Context.rv_var["date_var"] if input == keyword then local dates = { os.date("%Y-%m-%d"), @@ -395,7 +398,7 @@ end -- 公历时间 local function time_translator(input, seg) - local keyword = rv_var["time_var"] + local keyword = Wubi98Context.rv_var["time_var"] if input == keyword then local times = { os.date("%H:%M:%S"), @@ -410,7 +413,7 @@ end -- 农历日期 local function lunar_translator(input, seg) - local keyword = rv_var["nl_var"] + local keyword = Wubi98Context.rv_var["nl_var"] if input == keyword then local lunar = { { @@ -502,13 +505,13 @@ end --- 单字模式 function single_char(input, env) - local b = env.engine.context:get_option(single_keyword) + local b = env.engine.context:get_option(Wubi98Context.single_keyword) local input_text = env.engine.context.input for cand in input:iter() do if not b or utf8.len(cand.text) == 1 - or table.vIn(rv_var, input_text) + or table.vIn(Wubi98Context.rv_var, input_text) or input_text:find("^z") or input_text:find("^[%u%p]") then @@ -519,7 +522,7 @@ end -- 星期 local function week_translator(input, seg) - local keyword = rv_var["week_var"] + local keyword = Wubi98Context.rv_var["week_var"] -- local luapath=debug.getinfo(1,"S").source:sub(2):sub(1,-9) -- luapath.."lua\\user.txt" if input == keyword then local weeks = { @@ -535,7 +538,7 @@ end --列出当年余下的节气 local function Jq_translator(input, seg) - local keyword = rv_var["jq_var"] + local keyword = Wubi98Context.rv_var["jq_var"] if input == keyword then local jqs = lunarJq.GetNowTimeJq(os.date("%Y%m%d")) for i = 1, #jqs do @@ -596,24 +599,24 @@ local function set_switch_keywords(input, seg, env) local schema_id = env.engine.schema.schema_id or "" local composition = env.engine.context.composition local segment = composition:back() - local trad_mode = env.engine.context:get_option(trad_keyword) + local trad_mode = env.engine.context:get_option(Wubi98Context.trad_keyword) if - input == rv_var.switch_keyword and #candidate_keywords > 0 - or input == rv_var.switch_schema and #enable_schema_list > 0 and trad_mode + input == Wubi98Context.rv_var.switch_keyword and #Wubi98Context.candidate_keywords > 0 + or input == Wubi98Context.rv_var.switch_schema and #Wubi98Context.enable_schema_list > 0 and trad_mode then if schema_name then segment.prompt = " 〔 当前方案:" .. schema_name .. " 〕" end local cand = nil local seg_text = "" - for i = 1, #candidate_keywords do + for i = 1, #Wubi98Context.candidate_keywords do if trad_mode then - seg_text = candidate_keywords[i][2] + seg_text = Wubi98Context.candidate_keywords[i][2] else - seg_text = candidate_keywords[i][1] + seg_text = Wubi98Context.candidate_keywords[i][1] end - if env.engine.context:get_option(candidate_keywords[i][3]) then + if env.engine.context:get_option(Wubi98Context.candidate_keywords[i][3]) then cand = Candidate(input, seg.start, seg._end, seg_text, " ✓") else cand = Candidate(input, seg.start, seg._end, seg_text, " ✕") @@ -621,16 +624,16 @@ local function set_switch_keywords(input, seg, env) cand.quality = 100000000 yield(cand) end - elseif input == rv_var.switch_schema and #enable_schema_list > 0 and not trad_mode then + elseif input == Wubi98Context.rv_var.switch_schema and #Wubi98Context.enable_schema_list > 0 and not trad_mode then local select_index = 1 - for i = 1, #enable_schema_list do - if enable_schema_list[i][2] then + for i = 1, #Wubi98Context.enable_schema_list do + if Wubi98Context.enable_schema_list[i][2] then local comment = "" - if enable_schema_list[i][1] == schema_id then + if Wubi98Context.enable_schema_list[i][1] == schema_id then comment = " ☚" select_index = i - 1 end - local cand = Candidate(input, seg.start, seg._end, enable_schema_list[i][2], comment) + local cand = Candidate(input, seg.start, seg._end, Wubi98Context.enable_schema_list[i][2], comment) segment.selected_index = select_index cand.quality = 100000000 yield(cand) diff --git a/lua/wubi98/new_spelling.lua b/lua/wubi98/new_spelling.lua index 58628cc..57bb684 100644 --- a/lua/wubi98/new_spelling.lua +++ b/lua/wubi98/new_spelling.lua @@ -263,10 +263,10 @@ local function filter(input, env) local hide_pinyin = env.engine.context:get_option("new_hide_pinyin") local schema_name = env.engine.schema.schema_name or "" local schema_id = env.engine.schema.schema_id or "" - local spelling_states = env.engine.context:get_option(spelling_keyword) + local spelling_states = env.engine.context:get_option(Wubi98Context.spelling_keyword) local composition = env.engine.context.composition local segment = composition:back() - -- if codetext==rv_var.switch_keyword and schema_name then segment.prompt =" 〔 当前方案:"..schema_name.." 〕" end + -- if codetext==Wubi98Context.rv_var.switch_keyword and schema_name then segment.prompt =" 〔 当前方案:"..schema_name.." 〕" end -- 获取输入法常用参数 -- env.engine.context:get_commit_text() -- filter中为获取提交词 -- env.engine.context:get_script_text()-- 获取编码带引导符 @@ -292,7 +292,7 @@ local function filter(input, env) if cand.comment == "" then local comment = get_tricomment(cand, env) -- local rvlk_comment= - yield(Candidate(spelling_keyword, cand.start, cand._end, cand.text, comment)) + yield(Candidate(Wubi98Context.spelling_keyword, cand.start, cand._end, cand.text, comment)) end else if @@ -304,7 +304,7 @@ local function filter(input, env) local code_comment = env.code_rvdb:lookup(cand.text) if add_comment ~= nil or add_comment ~= "" then if cand.comment == "" then - yield(Candidate(spelling_keyword, cand.start, cand._end, cand.text, add_comment)) + yield(Candidate(Wubi98Context.spelling_keyword, cand.start, cand._end, cand.text, add_comment)) else if cand.comment:find("(☯)") then segment.prompt = "〔编码:" .. get_en_code(cand.text, env.spll_rvdb) .. "〕" @@ -313,7 +313,7 @@ local function filter(input, env) if utf8.len(cand.text) == 1 and code_comment and not hide_pinyin then yield( Candidate( - spelling_keyword, + Wubi98Context.spelling_keyword, cand.start, cand._end, cand.text, @@ -323,7 +323,7 @@ local function filter(input, env) else yield( Candidate( - spelling_keyword, + Wubi98Context.spelling_keyword, cand.start, cand._end, cand.text, @@ -346,7 +346,7 @@ local function filter(input, env) else yield(cand) end - -- elseif script_text==rv_var.switch_keyword then + -- elseif script_text==Wubi98Context.rv_var.switch_keyword then -- if cand.text:find("方案") then cand.comment="〔 "..schema_name.." 〕" end -- yield(cand) else @@ -434,7 +434,7 @@ local function filter(input, env) or not env.engine.context:get_option("GB2312") then table.insert(CandidateText, cand.text) - -- if script_text==rv_var.switch_keyword then + -- if script_text==Wubi98Context.rv_var.switch_keyword then -- if cand.text:find("方案") then cand.comment="〔 "..schema_name.." 〕" end -- end if cand.comment:find("(☯)") and script_text:find("^%`*(%l+%`%l+)") then diff --git a/lua/wubi98/switcher.lua b/lua/wubi98/switcher.lua index 27da401..90ca574 100644 --- a/lua/wubi98/switcher.lua +++ b/lua/wubi98/switcher.lua @@ -1,5 +1,5 @@ --[[ -switch_keyword关键字更换在rime.lua文件rv_var中 +switch_keyword关键字更换在rime.lua文件Wubi98Context.rv_var中 须将 lua_processor@switch_processor 放在 engine/processors 里,并位于默认 selector 之前 --]] @@ -110,7 +110,7 @@ local function selector(key, env) local candidate_count = segment.menu:candidate_count() local selected_candidate = segment:get_selected_candidate() or "" local page_pos = math.modf(segment.selected_index / page_size) + 1 - local trad_mode = env.engine.context:get_option(trad_keyword) + local trad_mode = env.engine.context:get_option(Wubi98Context.trad_keyword) -- if segment.selected_index>page_size then -- local candidate_pos= math.fmod( segment.selected_index, page_size ) -- end @@ -122,8 +122,8 @@ local function selector(key, env) if key.keycode > 0x2f and key.keycode < 0x6a and idx > -1 then last_candidate = segment:get_candidate_at(idx).text or "" end - if context.input == rv_var.switch_schema and last_candidate and not trad_mode then -- 控制关键字切换方案 - local sc_id = IsExistChar(enable_schema_list, last_candidate) + if context.input == Wubi98Context.rv_var.switch_schema and last_candidate and not trad_mode then -- 控制关键字切换方案 + local sc_id = IsExistChar(Wubi98Context.enable_schema_list, last_candidate) -- env.engine:commit_text(last_candidate.."-"..sc_id) -- context:clear() if sc_id:find("%a") then @@ -131,10 +131,10 @@ local function selector(key, env) return kAccepted end elseif - context.input == rv_var.switch_keyword and last_candidate - or trad_mode and context.input == rv_var.switch_schema and last_candidate + context.input == Wubi98Context.rv_var.switch_keyword and last_candidate + or trad_mode and context.input == Wubi98Context.rv_var.switch_schema and last_candidate then -- 关键字切换方案选项开关,如简繁切换、拆分开关等等 - local keyword = get_switch_keywords(candidate_keywords, last_candidate) + local keyword = get_switch_keywords(Wubi98Context.candidate_keywords, last_candidate) -- env.engine:commit_text(last_candidate .. "-" .. keyword) if keyword ~= "" then local flag = env.engine.context:get_option(keyword) diff --git a/openfly.dict.yaml b/openfly.dict.yaml index ee95eca..f3f0792 100644 --- a/openfly.dict.yaml +++ b/openfly.dict.yaml @@ -13,12 +13,12 @@ import_tables: - 'dicts/openfly/openfly.secondary.short.code' - 'dicts/openfly/openfly.secondary' # - 'dicts/openfly/openfly.completion' - - 'dicts/openfly/openfly.embedded.hint' + # - 'dicts/openfly/openfly.embedded.hint' - 'dicts/openfly/openfly.off-table' - 'dicts/openfly/openfly.whimsicality' - 'dicts/openfly/openfly.symbols' - 'dicts/openfly/openfly.web' - 'dicts/openfly/openfly.uncommon' - 'dicts/openfly/openfly.user' + - 'dicts/openfly/openfly.extend' ... - diff --git a/rime.lua b/rime.lua index 47326c7..29e1820 100644 --- a/rime.lua +++ b/rime.lua @@ -1,4 +1,7 @@ -require('flypy') -require('openfly') -require('wubi98') -require('xkjd6') +Lfmt = require("Lfmt") +lfmt = Lfmt("oh-my-rime", "warning") + +require("flypy") +require("openfly") +require("wubi98") +require("xkjd6") diff --git a/wubi98_S.custom.yaml b/wubi98_S.custom.yaml index f76e3af..dc84fc2 100644 --- a/wubi98_S.custom.yaml +++ b/wubi98_S.custom.yaml @@ -5,5 +5,4 @@ patch: "translator/enable_completion": true "key_binder/import_preset": default "reverse_lookup/enable_completion": true - "reverse_lookup/dictionary": wubi98_openfly_extra - "schema/dependencies/@next": wubi98_openfly_extra + "reverse_lookup/dictionary": openfly diff --git a/wubi98_U.custom.yaml b/wubi98_U.custom.yaml index 8aa6ba4..96aadae 100644 --- a/wubi98_U.custom.yaml +++ b/wubi98_U.custom.yaml @@ -5,5 +5,4 @@ patch: "translator/enable_completion": true "key_binder/import_preset": default "reverse_lookup/enable_completion": true - "reverse_lookup/dictionary": wubi98_openfly_extra - "schema/dependencies/@next": wubi98_openfly_extra + "reverse_lookup/dictionary": openfly diff --git a/wubi98_ci.custom.yaml b/wubi98_ci.custom.yaml index 4ca1edd..58db6a4 100644 --- a/wubi98_ci.custom.yaml +++ b/wubi98_ci.custom.yaml @@ -25,7 +25,7 @@ patch: rvlk_openfly: prefix: "z," tips: "〔小鹤反查〕" - dictionary: wubi98_openfly_extra + dictionary: openfly auto_completion: true tag: rvlk_openfly extra_tags: diff --git a/wubi98_dz.custom.yaml b/wubi98_dz.custom.yaml index e63e358..6d3779b 100644 --- a/wubi98_dz.custom.yaml +++ b/wubi98_dz.custom.yaml @@ -5,6 +5,6 @@ patch: "translator/enable_completion": true "key_binder/import_preset": default "reverse_lookup/enable_completion": true - "reverse_lookup/dictionary": wubi98_openfly_extra - "schema/dependencies/@next": wubi98_openfly_extra + "reverse_lookup/dictionary": openfly + # "schema/dependencies/@next": openfly diff --git a/wubi98_openfly_extra.schema.yaml b/wubi98_openfly_extra.schema.yaml deleted file mode 100644 index 97b2a16..0000000 --- a/wubi98_openfly_extra.schema.yaml +++ /dev/null @@ -1,104 +0,0 @@ -# Rime schema settings -# encoding: utf-8 - -schema: - schema_id: wubi98_openfly_extra - name: 反查 - version: "v9.9m" - author: - - 方案设计:何海峰 - - 修改:amorphobia - - 修改:Yiklek - description: - 词库开源的小鹤音形 Rime 配方 + zhwiki + moegirl - dependencies: - - openfly_reverse - -punctuator: - import_preset: default - -switches: - - name: ascii_mode - reset: 0 - - name: full_shape - - name: simplification - reset: 0 - - name: ascii_punct - reset: 0 - -engine: - processors: - - lua_processor@openfly_shortcut_processor - - ascii_composer - - recognizer - - key_binder - - speller - - punctuator - - selector - - navigator - - express_editor - segmentors: - - ascii_segmentor - - matcher - - abc_segmentor - - punct_segmentor - - fallback_segmentor - translators: - - punct_translator - - table_translator - - lua_translator@openfly_date_translator - - lua_translator@openfly_time_translator - - lua_translator@openfly_shortcut_translator - - reverse_lookup_translator - - history_translator@history - filters: - - lua_filter@openfly_hint_filter - - lua_filter@openfly_deletion_filter - - simplifier - - simplifier@simplification - - uniquifier - -speller: - alphabet: '/;zyxwvutsrqponmlkjihgfedcba' - initials: 'abcdefghijklmnopqrstuvwxyz;' - -translator: - dictionary: wubi98_openfly_extra - enable_encoder: true - enable_charset_filter: false - enable_sentence: true - enable_completion: true - enable_user_dict: false - disable_user_dict_for_patterns: - - "^z.*$" - -history: - input: ;f - size: 1 - initial_quality: 1 - -simplification: - opencc_config: s2tw.json - option_name: simplification - tips: all - -reverse_lookup: - dictionary: openfly_reverse - comment_format: - - xform/ / / - -key_binder: - import_preset: default - -recognizer: - import_preset: default - patterns: - uppercase: "" - reverse_lookup: "[a-z`]*`+[a-z`]*" - punct: "" - -menu: - page_size: 9 - -style: - horizontal: false