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 29, 2024
1 parent 50aef1b commit 899e858
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 51 deletions.
45 changes: 21 additions & 24 deletions default.custom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ patch:
schema_list:
- schema: wubi86_jidian # 五笔
- schema: numbers # 大写数字
- schema: wubi86_jidian_pinyin # 五笔拼音混输
- schema: wubi86_jidian_trad # 五笔 - 简入繁出
- schema: wubi86_jidian_trad_pinyin # 五笔拼音混输 - 简入繁出
- schema: pinyin_simp # 普通拼音
# - schema: wubi86_jidian_pinyin # 五笔拼音混输
# - schema: wubi86_jidian_trad # 五笔 - 简入繁出
# - schema: wubi86_jidian_trad_pinyin # 五笔拼音混输 - 简入繁出
# - schema: pinyin_simp # 普通拼音

# Menu
menu:
Expand Down Expand Up @@ -62,27 +62,23 @@ patch:
# - { when: has_menu, accept: equal, send: Page_Down }

# 上下翻页 tab
- { when: has_menu, accept: Shift+Tab, send: Page_Up }
- { when: has_menu, accept: Tab, send: Page_Down }
# - { when: has_menu, accept: Shift+Tab, send: Page_Up }
# - { when: has_menu, accept: Tab, send: Page_Down }

# 回车清码
# - { when: composing, accept: Return, send: Escape }
# Tab清码, 在vim模式插入状态下,中文输入法按Esc清屏时会将输入法切换成英文Bug,先暂时使用Tab或Ctrl+d清码
- { when: composing, accept: Tab, send: Escape }

# emacs key bindings, copy from https://github.com/rime/rime-prelude/blob/master/key_bindings.yaml
- { when: composing, 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 }

# vim key bindings
- { when: composing, accept: Control+k, send: Up }
- { when: composing, accept: Control+j, send: Down }
- { when: composing, accept: Control+h, send: Left }
- { when: composing, accept: Control+l, send: Right }
- { when: composing, accept: Control+5, send: Home }
- { when: composing, accept: Control+4, send: End }
- { when: composing, accept: Control+d, send: Escape }

punctuator:
full_shape: # 全角符号
" ": {commit: " "}
Expand Down Expand Up @@ -135,7 +131,7 @@ patch:
.: {commit: "。"}
"/": "/"
":": {commit: ":"}
";": {commit: ";"}
";": {commit: ";"} # 分号临时英文需要
"<": {commit: "《"}
"=": {commit: "="}
">": {commit: "》"}
Expand All @@ -145,7 +141,7 @@ patch:
"\\": {commit: "、"}
"]": {commit: "】"}
"^": {commit: "……"}
_: "——"
_: "_"
"`": "`"
"{": ""
"|": "|"
Expand All @@ -154,5 +150,6 @@ patch:
recognizer:
patterns: # 一些常见的英文组合,当正则匹配到这些时,都不会生成候选词,而只输入英文
email: "^[-_.0-9A-Za-z]+@.*$"
uppercase: "[A-Z][-_+.'0-9A-Za-z]*$"
# uppercase: "[A-Z][-_+.'0-9A-Za-z]*$"
url: "^(www[.]|https?:|ftp[.:]|mailto:|file:|localhost).*$|^[a-z]+[.].+$"
english: "^[;A-Z][-;_+'a-zA-Z]*$" # 分号临时英文需要
3 changes: 3 additions & 0 deletions key_bindings.custom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# encoding: utf-8

patch:
60 changes: 60 additions & 0 deletions lua/append_original_filter.lua
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




90 changes: 90 additions & 0 deletions lua/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
43 changes: 43 additions & 0 deletions lua/processor_enter_skip_prefix.lua
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
13 changes: 13 additions & 0 deletions lua/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
```
3 changes: 3 additions & 0 deletions numbers.custom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# encoding: utf-8

patch:
3 changes: 3 additions & 0 deletions punctuation.custom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# encoding: utf-8

patch:
27 changes: 24 additions & 3 deletions weasel.custom.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: utf-8
# encoding: utf-8

customization:
distribution_code_name: Weasel
Expand All @@ -9,7 +9,28 @@ customization:
config_version: "0.22"

patch:
show_notifications_time: 200 # 部署通知、中英切换标识 显示时长 ms
show_notifications: false
show_notifications_time: 1000 # 部署通知、中英切换标识 显示时长 ms
app_options:
code.exe:
ascii_mode: true
vim_mode: true
idea64.exe:
ascii_mode: true
vim_mode: true
gvim.exe:
ascii_mode: true
vim_mode: true
WindowsTerminal.exe:
ascii_mode: true
XYplorer.exe:
ascii_mode: true
utools.exe:
ascii_mode: true
SecureCRT.exe:
ascii_mode: true
Taskmgr.exe :
ascii_mode: true
style:
inline_preedit: true
color_scheme: MacRoseo # 匹配正文的颜色方案,对应正文的颜色方案名
Expand Down Expand Up @@ -99,4 +120,4 @@ patch:
candidate_text_color: 0x000000
comment_text_color: 0xBBCC27

style/layout/border_width: 1
style/layout/border_width: 1
3 changes: 3 additions & 0 deletions wubi86_jidian.custom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# encoding: utf-8

patch:
Loading

0 comments on commit 899e858

Please sign in to comment.