Skip to content

Commit

Permalink
分号临时英文解决方案,参考 KyleBing#154
Browse files Browse the repository at this point in the history
  • Loading branch information
huo-feng-ding committed Oct 14, 2024
1 parent 50aef1b commit 4d87873
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 1 deletion.
90 changes: 90 additions & 0 deletions lua/my/log.lua
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
37 changes: 37 additions & 0 deletions lua/my/processor_enter_skip_prefix.lua
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
13 changes: 13 additions & 0 deletions lua/my/readme.txt
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
```
26 changes: 26 additions & 0 deletions mydefault.custom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
customization:
distribution_code_name: Weasel
distribution_version: 0.16.3
generator: "Rime::SwitcherSettings"
modified_time: "Fri Oct 11 16:16:18 2024"
rime_version: 1.11.2
patch:
ascii_composer:
good_old_caps_lock: true
switch_key: {Caps_Lock: commit_code, Control_L: noop, Control_R: noop, Shift_L: commit_code, Shift_R: commit_code}
key_binder:
bindings: [{accept: semicolon, send: 2, when: has_menu}, {accept: apostrophe, send: 3, when: has_menu}, {accept: bracketleft, send: Page_Up, when: has_menu}, {accept: bracketright, send: Page_Down, when: has_menu}, {accept: "Shift+Tab", send: Page_Up, when: has_menu}, {accept: Tab, send: Page_Down, when: has_menu}, {accept: "Control+p", send: Up, when: composing}, {accept: "Control+n", send: Down, when: composing}, {accept: "Control+b", send: Left, when: composing}, {accept: "Control+f", send: Right, when: composing}, {accept: "Control+a", send: Home, when: composing}, {accept: "Control+e", send: End, when: composing}, {accept: "Control+d", send: Delete, when: composing}, {accept: "Control+k", send: "Shift+Delete", when: composing}, {accept: "Control+h", send: BackSpace, when: composing}, {accept: "Control+g", send: Escape, when: composing}, {accept: "Control+bracketleft", send: Escape, when: composing}, {accept: "Alt+v", send: Page_Up, when: composing}, {accept: "Control+v", send: Page_Down, when: composing}]
menu:
page_size: 5
punctuator:
full_shape: {" ": {commit: " "}, "!": {commit: "!"}, "\"": {pair: ["“", "”"]}, "#": ["#", "⌘"], "$": "¥", "%": "%", "&": "&", "'": {pair: ["‘", "’"]}, "(": "(", ")": ")", "*": ["*", "・", "×"], "+": "+", ",": {commit: ","}, "-": "-", .: {commit: "。"}, "/": ["/", "÷"], ":": {commit: ":"}, ";": {commit: ";"}, "<": ["《", "〈", "«", "‹"], "=": "=", ">": ["》", "〉", "»", "›"], "?": {commit: "?"}, "@": "@", "[": ["「", "【", "〔", "["], "\\": ["、", "\"], "]": ["」", "】", "〕", "]"], "^": {commit: "……"}, _: "——", "`": "`", "{": ["『", "〖", "{"], "|": ["·", "|", "§", "¦"], "}": ["』", "〗", "}"], "~": "~"}
half_shape: {"!": {commit: "!"}, "\"": {pair: ["“", "”"]}, "#": "#", "$": "¥", "%": ["%", "%", "°", "℃"], "&": "&", "'": {pair: ["‘", "’"]}, "(": "(", ")": ")", "*": "*", "+": "+", ",": {commit: ","}, "-": {commit: "-"}, .: {commit: "。"}, "/": "/", ":": {commit: ":"}, ";": {commit: ";"}, "<": {commit: "《"}, "=": {commit: "="}, ">": {commit: "》"}, "?": {commit: "?"}, "@": "@", "[": {commit: "【"}, "\\": {commit: "、"}, "]": {commit: "】"}, "^": {commit: "……"}, _: "——", "`": "`", "{": "「", "|": "|", "}": "」", "~": "~"}
recognizer:
patterns: {email: "^[-_.0-9A-Za-z]+@.*$", url: "^(www[.]|https?:|ftp[.:]|mailto:|file:|localhost).*$|^[a-z]+[.].+$", english: "^;[a-zA-Z]*$"}
schema_list:
- {schema: wubi86_jidian}
switcher:
abbreviate_options: true
caption: "【 输入法设置 】"
hotkeys: ["Control+0", "Shift+Control+0"]
option_list_separator: ""
14 changes: 13 additions & 1 deletion wubi86_jidian.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ schema:
description: |
五笔字形 86 极点极爽版,方案由 KyleBing 修改 - 2019年11月08日 10:26
dependencies:
# - melt_eng #如果要启用英文词典,把英文方案文件(以melt_eng为例,就是melt_eng.dict.yaml和melt_eng.schema.yaml)复制到此项目之下, 然后再在下边添加 english/dictionary: melt_eng 属性
# - pinyin_simp

switches:
Expand Down Expand Up @@ -42,28 +43,39 @@ engine:
segmentors:
- ascii_segmentor
- matcher
- affix_segmentor@english
- abc_segmentor
- punct_segmentor
- fallback_segmentor
translators:
- punct_translator
- reverse_lookup_translator
- table_translator
- table_translator@english
- lua_translator@*wubi86_jidian_date_translator # 日期、时间、星期
- history_translator@repeat_last_input # 重复上一次输入,对应下面的 repeat_last_input
filters:
- simplifier@tradition
# - lua_filter@*wubi86_jidian_single_char_first_filter # 单字优先
# - lua_filter@*wubi86_jidian_single_char_only # 纯单字

english:
tag: english
#dictionary: melt_eng # 如果需要英文词典的话
prefix: ";" # 反查前缀,以它为起点
tips: 〔En〕 # 反查时的提示信息
enable_completion: true
enable_sentence: false
initial_quality: 1.1



# 自动造词功能:参阅: https://github.com/KyleBing/rime-wubi86-jidian#6-%E5%BC%80%E5%90%AF%E8%87%AA%E5%8A%A8%E9%80%A0%E8%AF%8D

speller:
max_code_length: 4 # 四码上屏
auto_select: true # 四码唯一时,自动上屏
# auto_clear: max_length # 空码时自动清空
auto_clear: max_length # 空码时自动清空

translator:
dictionary: wubi86_jidian # 翻译器将调取此字典文件
Expand Down

0 comments on commit 4d87873

Please sign in to comment.