Skip to content

Commit

Permalink
feat: use jiandao
Browse files Browse the repository at this point in the history
cherry-pick

- 3fad699
  • Loading branch information
amorphobia committed Jul 11, 2023
1 parent c497875 commit 8c190fd
Show file tree
Hide file tree
Showing 11 changed files with 630 additions and 318 deletions.
84 changes: 46 additions & 38 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,47 +64,46 @@ jobs:
name: artifact.tar
path: artifact.tar

test:
needs: build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
browser: [chromium, firefox] # webkit
include:
- os: macos-latest
browser: webkit
# test:
# needs: build
# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: false
# matrix:
# os: [ubuntu-latest]
# browser: [chromium, firefox] # webkit
# include:
# - os: macos-latest
# browser: webkit

steps:
- uses: actions/checkout@v3
- name: Use Node.js latest
uses: actions/setup-node@v2
with:
node-version: 18.x
- name: Install node dependencies
run: |
npm i -g pnpm
pnpm i
npx playwright install
npx playwright install-deps ${{ matrix.browser }}
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: artifact.tar
- name: Untar files
run: tar -xvf artifact.tar
- name: Test
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
npx playwright test --browser ${{ matrix.browser }} test/
- name: Test device
if: ${{ matrix.os == 'macos-latest' }}
run: |
npx playwright test --browser ${{ matrix.browser }} test-device/
# steps:
# - uses: actions/checkout@v3
# - name: Use Node.js latest
# uses: actions/setup-node@v2
# with:
# node-version: 18.x
# - name: Install node dependencies
# run: |
# npm i -g pnpm
# pnpm i
# npx playwright install-deps ${{ matrix.browser }}
# - name: Download artifact
# uses: actions/download-artifact@v3
# with:
# name: artifact.tar
# - name: Untar files
# run: tar -xvf artifact.tar
# - name: Test
# if: ${{ matrix.os == 'ubuntu-latest' }}
# run: |
# npx playwright test --browser ${{ matrix.browser }} test/
# - name: Test device
# if: ${{ matrix.os == 'macos-latest' }}
# run: |
# npx playwright test --browser ${{ matrix.browser }} test-device/

release:
needs: test
needs: build
if: ${{ github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
permissions:
Expand All @@ -124,3 +123,12 @@ jobs:
mv dist my-rime-dist
zip -r my-rime-dist.zip my-rime-dist
gh release upload latest my-rime-dist.zip --clobber
- name: Copy CNAME
run: |
cp CNAME my-rime-dist
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: my-rime-dist
1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jd-web.xuesong.io
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 🌟️星空键道输入法在线版

> [LibreService/my_rime](https://github.com/LibreService/my_rime) 强力驱动
[仓库](https://github.com/amorphobia/rime-jiandao)

以下是 LibreService/my_rime 原 README

---

# My RIME 梧桐输入法
![](https://img.shields.io/github/license/LibreService/my_rime)

Expand Down
7 changes: 0 additions & 7 deletions rime-config/lua/date_translator.lua

This file was deleted.

185 changes: 185 additions & 0 deletions rime-config/lua/jiandao/calculator.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
--[[
Calculator
Copyright (C) 2020 thXnder <https://github.com/tswwe>
xnumber.lua: realize a yong-style number typing experience in RIME
usage:
0. this script is intended for xkjd6 but also work for other schemas (may need some custimizations)
1. place this script in `rime\lua`
2. modify `rime\rime.lua` by adding a line like `number_translator = require("numberx")`
3. modify your schema (like `xkjd6.schema.yaml`) by adding an item like `- lua_translator@number_translator` under the `engine/translators` section
4. re-deploy RIME and enjoy (the default trigger key is `=`)
change log:
v0.0.1(20201010) - initial version written by thXnder(别打脸)
--]]

local function speakLiterally(str, valMap)
valMap = valMap or {
[0]=""; ""; ""; ""; ""; ""; ""; ""; ""; ""; "";
["+"]=""; ["-"]=""; ["."]=""; [""]=""
}

local tbOut = {}
for k = 1, #str do
local v = string.sub(str, k, k)
v = tonumber(v) or v
tbOut[k] = valMap[v]
end
return table.concat(tbOut)
end

local function speakMillitary(str)
return speakLiterally(str, {[0]=""; ""; ""; ""; ""; ""; ""; ""; ""; ""; "";["+"]=""; ["-"]=""; ["."]=""; [""]=""})
end

local function splitNumStr(str)
--[[
split a number (or a string describing a number) into 4 parts:
.sym: "+", "-" or ""
.int: "0", "000", "123456", "", etc
.dig: "." or ""
.dec: "0", "10000", "00001", "", etc
--]]
local part = {}
part.sym, part.int, part.dig, part.dec = string.match(str, "^([%+%-]?)(%d*)(%.?)(%d*)")
return part
end

local function speakBar(str, posMap, valMap)
posMap = posMap or {[1]=""; [2]=""; [3]=""; [4]=""}
valMap = valMap or {[0]=""; ""; ""; "" ;""; ""; ""; ""; ""; ""} -- the length of valMap[0] should not excess 1

local out = ""
local bar = string.sub("****" .. str, -4, -1) -- the integer part of a number string can be divided into bars; each bar has 4 bits
for pos = 1, 4 do
local val = tonumber(string.sub(bar, pos, pos))
-- case1: place holder
if val == nil then
goto continue
end
-- case2: number 1~9
if val > 0 then
out = out .. valMap[val] .. posMap[pos]
goto continue
end
-- case3: number 0
local valNext = tonumber(string.sub(bar, pos+1, pos+1))
if ( valNext==nil or valNext==0 )then
goto continue
else
out = out .. valMap[0]
goto continue
end
::continue::
end
if out == "" then out = valMap[0] end
return out
end

local function speakIntOfficially(str, posMap, valMap)
posMap = posMap or {[1]=""; [2]=""; [3]=""; [4]=""}
valMap = valMap or {[0]=""; ""; ""; "" ;""; ""; ""; ""; ""; ""} -- the length of valMap[0] should not excess 1

-- split the number string into bars, for example, in:str=123456789 → out:tbBar={1|2345|6789}
local int = string.match(str, "^0*(%d+)$")
if int=="" then int = "0" end
local remain = #int % 4
if remain==0 then remain = 4 end
local tbBar = {[1] = string.sub(int, 1, remain)}
for pos = remain+1, #int, 4 do
local bar = string.sub(int, pos, pos+3)
table.insert(tbBar, bar)
end
-- generate the suffixes of each bar, for example, tbSpeakBarSuffix={亿|万|""}
local tbSpeakBarSuffix = {[1]=""}
for iBar = 2, #tbBar do
local suffix = (iBar % 2 == 0) and (""..tbSpeakBarSuffix[1]) or ("亿"..tbSpeakBarSuffix[2])
table.insert(tbSpeakBarSuffix, 1, suffix)
end
-- speak each bar
local tbSpeakBar = {}
for k = 1, #tbBar do
tbSpeakBar[k] = speakBar(tbBar[k], posMap, valMap)
end
-- combine the results
local out = ""
for k = 1, #tbBar do
local speakBar = tbSpeakBar[k]
if speakBar ~= valMap[0] then
out = out .. speakBar .. tbSpeakBarSuffix[k]
end
end
if out == "" then out = valMap[0] end
return out
end

local function speakDecMoney(str, posMap, valMap)
posMap = posMap or {[1]=""; [2]=""; [3]=""; [4]=""}
valMap = valMap or {[0]=""; ""; ""; "" ;""; ""; ""; ""; ""; ""} -- the length of valMap[0] should not excess 1

local dec = string.sub(str, 1, 4)
dec = string.gsub(dec, "0*$", "")
if dec == "" then
return ""
end

local out = ""
for pos = 1, #dec do
local val = tonumber(string.sub(dec, pos, pos))
out = out .. valMap[val] .. posMap[pos]
end
return out
end

local function speakOfficially(str)
local part = splitNumStr(str)
local speakSym = speakLiterally(part.sym)
local speakInt = speakIntOfficially(part.int)
local speakDig = speakLiterally(part.dig)
local speakDec = speakLiterally(part.dec)
local out = speakSym .. speakInt .. speakDig .. speakDec
return out
end

local function speakMoney(str)
local part = splitNumStr(str)
local speakSym = speakLiterally(part.sym)
local speakInt = speakIntOfficially(part.int, {[1]=""; [2]=""; [3]=""; [4]=""}, {[0]=""; ""; ""; "" ;""; ""; ""; ""; ""; ""}) .. ""
local speakDec = speakDecMoney(part.dec)
local out = speakSym .. speakInt .. speakDec
return out
end

local function baseConverse(str, from, to)
local str10 = str
if from == 16 then
str10 = string.format("%d", str)
end
local strout = str10
if to == 16 then
strout = string.format("%#x", str10)
end
return strout
end

local function translator(input, seg, env)
-- env can be used for getting the state of a switch, e.g., `env.engine.context:get_option("jffh")` returns true/false (or nil if the switch does not exist)
if string.sub(input, 1, 1) == "=" then
local input2 = string.sub(input, 2)
if string.match(input2, "^[%+%-]?%d*%.?%d*$") then -- sadly, lua does not support regex like {0,4}
-- comment or reorder following lines to adjust the effects
yield(Candidate("number", seg.start, seg._end, speakMoney(input2), " 金额"))
yield(Candidate("number", seg.start, seg._end, speakOfficially(input2), " 文读"))
yield(Candidate("number", seg.start, seg._end, speakLiterally(input2), " 冷读"))
yield(Candidate("number", seg.start, seg._end, speakMillitary(input2), " 军语"))
else
local ok, ret = pcall(load, "return "..input2) -- from Lua 5.3, the `loadstring` function is replaced by `load`
if ok then yield(Candidate("number", seg.start, seg._end, tostring(ret()), " 计算")) end
end
if string.match(input2, "^[%+%-]?%d*$") then -- plz, i dont want to deal with base conversion with decimals
yield(Candidate("number", seg.start, seg._end, baseConverse(input2, 10, 16), " 进制"))
end
end
end

return translator
84 changes: 84 additions & 0 deletions rime-config/lua/jiandao/date_time_translator.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
--[[
Date & Time Translator
Copyright (C) 2019 Rea <hi@rea.ink>
Copyright (C) 2022 Xuesong Peng <pengxuesong.cn@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
--]]

local conf = {
weekday = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"},
number = {"", "", "", "", "", "", "", "", "", ""},
}

local function toUp(text)
for i, v in ipairs(conf.number) do
text = text:gsub(i-1, v)
end
return text
end

local function getUpDate()
local m = tonumber(os.date("%m"))
local d = tonumber(os.date("%d"))

local year = toUp(os.date("%Y"))
local month = toUp(tostring(m))
if m == 10 then
month = ""
elseif m > 10 then
month = month:gsub("^一", "")
end
local date = toUp(tostring(d))
if d == 10 then
date = ""
elseif d % 10 == 0 then
date = date:gsub("", "")
elseif d > 10 and d < 20 then
-- common hanzi's lenth is 3 in UTF-8
date = "" .. date:sub(4)
elseif d > 20 then
date = date:sub(1, 3) .. "" .. date:sub(4)
end
return year .. "" .. month .. "" .. date .. ""
end

local function getWeekDay()
local week = os.date("%w")
return conf.weekday[week + 1]
end

local function translator(input, seg)
if input == "o" then
yield(Candidate("date", seg.start, seg._end, os.date("%H:%M:%S"), "~ej"))
yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), "~rq"))
yield(Candidate("date", seg.start, seg._end, getWeekDay(), "~xq"))
elseif input == "oe" then
yield(Candidate("date", seg.start, seg._end, os.date("%H:%M:%S"), "~j"))
elseif input == "or" then
yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), "~q"))
elseif input == "ox" then
yield(Candidate("date", seg.start, seg._end, getWeekDay(), "~q"))
elseif input == "oej" then
yield(Candidate("date", seg.start, seg._end, os.date("%H:%M:%S"), ""))
elseif input == "orq" then
yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), ""))
yield(Candidate("date", seg.start, seg._end, getUpDate(), ""))
elseif input == "oxq" then
yield(Candidate("date", seg.start, seg._end, getWeekDay(), ""))
end
end

return translator

0 comments on commit 8c190fd

Please sign in to comment.