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 16, 2024
1 parent 50aef1b commit 4947a89
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 30 deletions.
34 changes: 15 additions & 19 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 @@ -68,21 +68,16 @@ patch:
# 回车清码
# - { when: composing, accept: Return, 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+6, send: End }
- { when: composing, accept: Control+d, send: Escape }
- { when: always, accept: Control+space, toggle: ascii_punct }

punctuator:
full_shape: # 全角符号
" ": {commit: " "}
Expand Down Expand Up @@ -156,3 +151,4 @@ patch:
email: "^[-_.0-9A-Za-z]+@.*$"
uppercase: "[A-Z][-_+.'0-9A-Za-z]*$"
url: "^(www[.]|https?:|ftp[.:]|mailto:|file:|localhost).*$|^[a-z]+[.].+$"
english: "^;[-_+'a-zA-Z]*$"
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
```
23 changes: 20 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,24 @@ customization:
config_version: "0.22"

patch:
show_notifications_time: 200 # 部署通知、中英切换标识 显示时长 ms
show_notifications: true
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
style:
inline_preedit: true
color_scheme: MacRoseo # 匹配正文的颜色方案,对应正文的颜色方案名
Expand Down Expand Up @@ -99,4 +116,4 @@ patch:
candidate_text_color: 0x000000
comment_text_color: 0xBBCC27

style/layout/border_width: 1
style/layout/border_width: 1
28 changes: 20 additions & 8 deletions wubi86_jidian.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ 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:
- name: ascii_mode
reset: 0
states: [ 中, En ]
- name: zh_trad
reset: 0 # 初始状态为 0: 简 -> 简 1: 简 -> 繁
states: [ 简体, 繁体 ]
- name: full_shape
states: [ 半角, 全角 ]
- name: extended_charset
states: [ 常用, 扩展 ]
# - name: zh_trad
# reset: 0 # 初始状态为 0: 简 -> 简 1: 简 -> 繁
# states: [ 简体, 繁体 ]
# - name: full_shape
# states: [ 半角, 全角 ]
# - name: extended_charset
# states: [ 常用, 扩展 ]
- name: ascii_punct
states: [ 。,, ., ]

Expand All @@ -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 4947a89

Please sign in to comment.