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 4947a89
Showing
6 changed files
with
195 additions
and
30 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,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,37 @@ | ||
-- 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 | ||
engine:commit_text(string.sub(input, 2)) | ||
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
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