forked from KyleBing/rime-wubi86-jidian
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50aef1b
commit 899e858
Showing
13 changed files
with
316 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# encoding: utf-8 | ||
|
||
patch: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
-- 原始字符串输出,用来实现分号临时英文,再输入分号顶屏上字 | ||
|
||
-- local log = require 'log' | ||
-- log.outfile = "D:\\aux_code.log" | ||
|
||
local function append_original_filter(input, env) | ||
local envengine = env.engine | ||
local envcontext = envengine.context | ||
local composition = envcontext.composition | ||
local segmentation = composition:toSegmentation() | ||
local schema = envengine.schema | ||
|
||
if(not composition:empty()) then | ||
local seg = composition:back() | ||
local segInput = segmentation.input | ||
local segInputLen = string.len(segInput) | ||
if schema.schema_id == "easy_en" then | ||
yield(Candidate("string", seg.start, seg._end, segInput, "")) | ||
elseif segInput:sub(1, 1) == ";" then | ||
-- 分号是引导的,输入字符大于一个才有效 | ||
if segInputLen > 1 then | ||
-- 这里和正则字符集和 default.custom.yaml recognizer/patterns/english 配置有关联 | ||
local word = string.match(segInput, ".*[-_+'a-zA-Z]$") | ||
-- log.info('s', segInput, word==nil, segInputLen, string.sub(segInput,segInputLen, segInputLen), string.sub(segInput,segInputLen, segInputLen)==";") | ||
-- 如果是英语单词,则在候选栏里显示 | ||
if word ~= nil then | ||
-- log.info('t', segInput) | ||
yield(Candidate("word", seg.start, seg._end, string.sub(segInput, 2), "")) | ||
elseif string.sub(segInput,segInputLen, segInputLen) == ";" then | ||
-- 如果是以分号结尾的则上屏 | ||
-- log.info('u', segInput) | ||
envengine:commit_text(string.sub(segInput, 2)) | ||
envcontext:clear() | ||
return | ||
end | ||
end | ||
else | ||
local word = string.match(segInput, "^[A-Z][-_+'a-zA-Z]*$") | ||
-- 如果是以大写字母开关的,则在候选栏里显示 | ||
if word ~= nil then | ||
yield(Candidate("word", seg.start, seg._end, segInput, "")) | ||
elseif string.sub(segInput,segInputLen, segInputLen) == ";" then | ||
-- | ||
envengine:commit_text(segInput, 2) | ||
envcontext:clear() | ||
return | ||
end | ||
end | ||
end | ||
for cand in input:iter() do | ||
yield(cand) | ||
end | ||
end | ||
|
||
|
||
return append_original_filter | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
-- | ||
-- log.lua | ||
-- | ||
-- Copyright (c) 2016 rxi | ||
-- | ||
-- This library is free software; you can redistribute it and/or modify it | ||
-- under the terms of the MIT license. See LICENSE for details. | ||
-- | ||
|
||
local log = { _version = "0.1.0" } | ||
|
||
log.usecolor = true | ||
log.outfile = nil | ||
log.level = "trace" | ||
|
||
|
||
local modes = { | ||
{ name = "trace", color = "\27[34m", }, | ||
{ name = "debug", color = "\27[36m", }, | ||
{ name = "info", color = "\27[32m", }, | ||
{ name = "warn", color = "\27[33m", }, | ||
{ name = "error", color = "\27[31m", }, | ||
{ name = "fatal", color = "\27[35m", }, | ||
} | ||
|
||
|
||
local levels = {} | ||
for i, v in ipairs(modes) do | ||
levels[v.name] = i | ||
end | ||
|
||
|
||
local round = function(x, increment) | ||
increment = increment or 1 | ||
x = x / increment | ||
return (x > 0 and math.floor(x + .5) or math.ceil(x - .5)) * increment | ||
end | ||
|
||
|
||
local _tostring = tostring | ||
|
||
local tostring = function(...) | ||
local t = {} | ||
for i = 1, select('#', ...) do | ||
local x = select(i, ...) | ||
if type(x) == "number" then | ||
x = round(x, .01) | ||
end | ||
t[#t + 1] = _tostring(x) | ||
end | ||
return table.concat(t, " ") | ||
end | ||
|
||
|
||
for i, x in ipairs(modes) do | ||
local nameupper = x.name:upper() | ||
log[x.name] = function(...) | ||
|
||
-- Return early if we're below the log level | ||
if i < levels[log.level] then | ||
return | ||
end | ||
|
||
local msg = tostring(...) | ||
local info = debug.getinfo(2, "Sl") | ||
local lineinfo = info.short_src .. ":" .. info.currentline | ||
|
||
-- Output to console | ||
print(string.format("%s[%-6s%s]%s %s: %s", | ||
log.usecolor and x.color or "", | ||
nameupper, | ||
os.date("%H:%M:%S"), | ||
log.usecolor and "\27[0m" or "", | ||
lineinfo, | ||
msg)) | ||
|
||
-- Output to log file | ||
if log.outfile then | ||
local fp = io.open(log.outfile, "a") | ||
local str = string.format("[%-6s%s] %s: %s\n", | ||
nameupper, os.date(), lineinfo, msg) | ||
fp:write(str) | ||
fp:close() | ||
end | ||
|
||
end | ||
end | ||
|
||
|
||
return log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
-- local log = require 'log' | ||
-- log.outfile = "D:\\aux_code.log" | ||
|
||
_G.kRejected, _G.kAccepted, _G.kNoop = 0, 1, 2 | ||
|
||
local tags = { 'english', 'pinyin' } | ||
|
||
local function check_tag(context) | ||
local composition = context.composition | ||
if (not composition:empty()) then | ||
local segment = composition:back() | ||
for _, x in ipairs(tags) do | ||
if segment:has_tag(x) then | ||
return true | ||
end | ||
end | ||
end | ||
return false | ||
end | ||
|
||
local function processor(key, env) | ||
local engine = env.engine | ||
local context = engine.context | ||
local repr = key:repr() | ||
local input = context.input | ||
-- log.info(repr, input, env.trigger_key) | ||
|
||
if check_tag(context) and repr == "Return" then | ||
-- 如果是以分号开头的,则剔除开头的分号上屏 | ||
if string.sub(input, 1, 1) == ";" then | ||
engine:commit_text(string.sub(input, 2)) | ||
else | ||
-- 否则是按大写字母开头的,全部上屏 | ||
engine:commit_text(input) | ||
end | ||
context.input = '' | ||
return kAccepted | ||
end | ||
|
||
return kNoop | ||
end | ||
|
||
return processor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
* 在实现分号临时英文功能的时候, https://github.com/KyleBing/rime-wubi86-jidian/issues/154 这个功能此功能。 | ||
* 但是临时英文输出的时候按回车键上屏时,前边带了分号,参考 https://github.com/KyleBing/rime-wubi86-jidian/issues/138 加了两个lua文件 log.lua (此文件是为了调试输出内容,需要在processor_enter_skip_prefix.lua文件中引用,此文件是从https://github.com/HowcanoeWang/rime-lua-aux-code/blob/main/lua/log.lua复制而来的,aux_code.lua相关代码也值得参考), processor_enter_skip_prefix.lua | ||
* 然后在 wubi86_jidian.schema.yaml 加上这个属性配置 | ||
``` | ||
engine: | ||
- ascii_composer | ||
- recognizer | ||
- key_binder | ||
+ - lua_processor@*processor_enter_skip_prefix | ||
- speller | ||
- punctuator | ||
- selector | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# encoding: utf-8 | ||
|
||
patch: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# encoding: utf-8 | ||
|
||
patch: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# encoding: utf-8 | ||
|
||
patch: |
Oops, something went wrong.