谷歌拼音自带lua
function fast_string_banji(argument)
return {"快捷1", "快捷2", "快捷3", "快捷4"}
end
function fast_string_LDZY_DXXY(argument)
return {"快捷1", "快捷2", "快捷3", "快捷4"}
end
function fast_string_myMessage(argument)
return {"快捷188", "快捷@qq.com"}
end
ime.register_command("bj", "fast_string_banji", "班级名称", "alpha", "按对应字母选择")
ime.register_command("xy", "fast_string_LDZY_DXXY", "学校学院", "alpha", "按对应字母选择")
ime.register_command("xx", "fast_string_myMessage", "个人信息", "alpha", "按对应字母选择")
-- encoding: UTF-8
_CHINESE_DIGITS = {
[0] = "〇",
[1] = "一",
[2] = "二",
[3] = "三",
[4] = "四",
[5] = "五",
[6] = "六",
[7] = "七",
[8] = "八",
[9] = "九",
[10] = "十",
}
_DATE_PATTERN = "^(%d+)-(%d+)-(%d+)$"
_TIME_PATTERN = "^(%d+):(%d+)$"
function GetChineseMathNum(num)
local ret
if num < 10 then
ret = _CHINESE_DIGITS[num]
elseif num < 20 then
ret = _CHINESE_DIGITS[10]
if num > 10 then
ret = ret .. _CHINESE_DIGITS[num % 10]
end
elseif num < 100 then
local mod = num % 10
ret = _CHINESE_DIGITS[(num - mod) / 10] .. _CHINESE_DIGITS[10]
if mod > 0 then
ret = ret .. _CHINESE_DIGITS[mod]
end
else
error("Invalid number")
end
return ret
end
function GetChineseNonMathNum(num)
local ret = ""
for ch in tostring(num):gmatch(".") do
if ch >= "0" and ch <= "9" then
ch = _CHINESE_DIGITS[tonumber(ch)]
end
ret = ret .. ch
end
return ret
end
function _VerifyTime(hour, minute)
if hour < 0 or hour > 23 or minute < 0 or minute > 59 then
error("Invalid time")
end
end
function _VerifyDate(month, day)
if month < 1 or month > 12 or day < 1 or day > _MONTH_TABLE_LEAF[month] then
error("Invalid date")
end
end
function _VerifyDateWithYear(year, month, day)
_VerifyDate(month, day)
if year < 1 or year > 9999 then
error("Invalid year")
end
if month == 2 and day == 29 then
if year % 400 ~= 0 and year % 100 == 0 then
error("Invalid lunar day")
end
if year % 4 ~= 0 then
error("Invalid lunar day")
end
end
end
function GetChineseDate(y, m, d, full)
if full then
return GetChineseNonMathNum(y) .. "年" ..
GetChineseMathNum(m) .. "月" ..
GetChineseMathNum(d) .. "日"
else
return y .. "年" .. m .. "月" .. d .. "日"
end
end
function GetChineseTime(h, m, full)
if full then
local ret = GetChineseMathNum(h) .. "时"
if m > 0 then
ret = ret .. GetChineseMathNum(m) .. "分"
end
return ret
else
return h .. "时" .. m .. "分"
end
end
function NormalizeDate(y, m, d)
return string.format("%d-%02d-%02d", y, m, d)
end
function NormalizeTime(h, m)
return string.format("%02d:%02d", h, m)
end
function GetTime(input)
local now = input
if #input == 0 then
now = os.date("%H:%M")
end
local hour, minute
now:gsub(_TIME_PATTERN, function(h, m)
hour = tonumber(h)
minute = tonumber(m)
end)
_VerifyTime(hour, minute)
return {
NormalizeTime(hour, minute),
GetChineseTime(hour, minute, false),
GetChineseTime(hour, minute, true),
}
end
function GetDate(input)
local now = input
if #input == 0 then
now = os.date("%Y-%m-%d")
end
local year, month, day
now:gsub(_DATE_PATTERN, function(y, m, d)
year = tonumber(y)
month = tonumber(m)
day = tonumber(d)
end)
_VerifyDateWithYear(year, month, day)
return {
NormalizeDate(year, month, day),
GetChineseDate(year, month, day, false),
GetChineseDate(year, month, day, true),
}
end
----------------------------------
_MATH_KEYWORDS = {
"abs", "acos", "asin", "atan", "atan2", "ceil", "cos", "cosh", "deg", "exp",
"floor", "fmod", "frexp", "ldexp", "log", "log10", "max", "min", "modf", "pi",
"pow", "rad", "random", "randomseed", "sin", "sinh", "sqrt", "tan", "tanh",
}
function _AddMathKeyword(input)
local ret = input
for _, keyword in pairs(_MATH_KEYWORDS) do
ret = ret:gsub(string.format("([^%%a\.])(%s\(.-\))", keyword), "%1math\.%2")
ret = ret:gsub(string.format("^(%s\(.-\))", keyword), "math\.%1")
end
return ret
end
function Compute(input)
local expr = "return " .. _AddMathKeyword(input)
local func = loadstring(expr)
if func == nil then
return "-- 未完整表达式 --"
end
local ret = func()
if ret == math.huge then -- div/0
return "-- 计算错误 --"
end
if ret ~= ret then
-- We rely on the property that NaN is the only value not equal to itself.
return "-- 计算错误 --"
end
return ret
end
----------------------------------
_TO_BE_REPLACED_FLAG = "#TO_BE_REPLACED#"
_ASCII_IMAGE_TABLE = {
["birthday"] = { [[
o o o o o
I I I I I
|~~~~~~~~~~~|
__|___*___*___|__
|/\~~~~~~~~~~~~~/\|
|\/ * * * \/|
|~~~~~~~~~~~~~~~~~|
~~~~~~~~~~~~~~~~~
]],
"生日蛋糕"},
["search"] = { [[
--\--+--/--
{ o_o }
┏━━━━━━━━━━oOo━(__)━oOo━┓
#TO_BE_REPLACED#
┗━━━━━━━━━━━━━━━━━━┛
┏━━━━┓ ┏━━━━┓
┃ 搜索 ┃ ┃手气不错┃
┗━━━━┛ ┗━━━━┛
]],
"搜索"},
}
function PrintAscii(input)
if #input <= 0 then
local metatables = {}
for k, v in pairs(_ASCII_IMAGE_TABLE) do
table.insert(metatables, {["suggest"] = k, ["help"] = v[2]})
end
return metatables
elseif _ASCII_IMAGE_TABLE[input] then
local result = _ASCII_IMAGE_TABLE[input][1]
local last_commit = ime.get_last_commit()
if #last_commit <= 0 or #last_commit > 20 then
last_commit = ""
end
return result:gsub(_TO_BE_REPLACED_FLAG, last_commit)
else
error("Invalid argument")
end
end
----------------------------------
-- Bitmaps table used for ascii_large_letters(), in 5x7 bitmaps.
_LARGE_LETTER_BITMAPS = {
[","] = [[
,,
,
,
]],
["-"] = [[
-----
]],
["."] = [[
..
..
]],
["0"] = [[
000
0 0
0 0
0 0
0 0
0 0
000
]],
["1"] = [[
1
111
1
1
1
1
11111
]],
["2"] = [[
222
2 2
2
2
2
2
22222
]],
["3"] = [[
333
3 3
3
33
3
3 3
333
]],
["4"] = [[
4
44
4 4
4 4
44444
4
444
]],
["5"] = [[
55555
5
5555
5
5
5 5
555
]],
["6"] = [[
66
6
6
6666
6 6
6 6
666
]],
["7"] = [[
77777
7 7
7
7
7
7
7
]],
["8"] = [[
888
8 8
8 8
888
8 8
8 8
888
]],
["9"] = [[
999
9 9
9 9
9999
9
9
99
]],
["A"] = [[
A
A
A A
A A
AAAAA
A A
A A
]],
["B"] = [[
BBBB
B B
B B
BBBB
B B
B B
BBBB
]],
["C"] = [[
CCC
C C
C
C
C
C C
CCC
]],
["D"] = [[
DDD
D D
D D
D D
D D
D D
DDD
]],
["E"] = [[
EEEEE
E
E
EEEE
E
E
EEEEE
]],
["F"] = [[
FFFFF
F
F
FFFF
F
F
F
]],
["G"] = [[
GGG
G G
G
G GG
G G
G G
GGG
]],
["H"] = [[
H H
H H
H H
HHHHH
H H
H H
H H
]],
["I"] = [[
IIIII
I
I
I
I
I
IIIII
]],
["J"] = [[
JJJJJ
J
J
J
J
J
JJ
]],
["K"] = [[
K K
K K
K K
KK
K K
K K
K K
]],
["L"] = [[
L
L
L
L
L
L
LLLLL
]],
["M"] = [[
M M
MMM
MMM
MMM
M M M
M M M
M M
]],
["N"] = [[
N N
N N
NN N
N N N
N NN
N N
N N
]],
["O"] = [[
OOO
O O
O O
O O
O O
O O
OOO
]],
["P"] = [[
PPPP
P P
P P
PPPP
P
P
P
]],
["Q"] = [[
QQQ
Q Q
Q Q
Q Q
Q Q Q
Q Q Q
QQQQ
]],
["R"] = [[
RRRR
R R
R R
RRRR
R R
R R
R R
]],
["S"] = [[
SSS
S S
S
SSS
S
S S
SSS
]],
["T"] = [[
TTTTT
T
T
T
T
T
T
]],
["U"] = [[
U U
U U
U U
U U
U U
U U
UUU
]],
["V"] = [[
V V
V V
V V
V V
V V
V V
V
]],
["W"] = [[
W W
W W W
W W W
WWW
WWW
WWW
W W
]],
["X"] = [[
X X
X X
X X
X
X X
X X
X X
]],
["Y"] = [[
Y Y
Y Y
Y Y
Y
Y
Y
Y
]],
["Z"] = [[
ZZZZZ
Z
Z
Z
Z
Z
ZZZZZ
]],
}
-- Converts input string to ascii image of large letters.
function PrintLetter(input_string)
if #input_string == 0 then
return {}
end
local letter_width = 5
local letter_height = 7
local max_string_length = 16
local result_lines = {}
for i = 1, letter_height do result_lines[i] = "" end
input_string = input_string:upper()
-- Limits the input string size.
input_string = input_string:sub(1, max_string_length)
-- Only interate on valid characters.
for c in input_string:gmatch("[0-9A-Z ,.-]") do
local letter = _LARGE_LETTER_BITMAPS[c]
-- Splits the letter bitmap into lines and appends each line to the
-- corresponding line of the result.
local lines = ime.split_string(letter, "\n")
for i, line in ipairs(lines) do
if i > letter_height then break end
for i = 1, letter_width - #line do line = line .. ' ' end
result_lines[i] = result_lines[i] .. line .. ' '
end
end
-- Merges result lines.
for i, line in ipairs(result_lines) do
result_lines[i] = ime.trim_string_right(result_lines[i])
end
local result = "\n" .. ime.join_string(result_lines, "\n") .. "\n"
return result
end
-- Dice images.
_DICE_BITMAPS = {
[[
/---------\
| |
| |
| (O) |
| |
| |
\---------/
]],
[[
/---------\
| |
| @ |
| |
| @ |
| |
\---------/
]],
[[
/---------\
| |
| @ |
| @ |
| @ |
| |
\---------/
]],
[[
/---------\
| |
| @ @ |
| |
| @ @ |
| |
\---------/
]],
[[
/---------\
| |
| @ @ |
| @ |
| @ @ |
| |
\---------/
]],
[[
/---------\
| |
| @ @ |
| @ @ |
| @ @ |
| |
\---------/
]],
}
math.randomseed(os.time())
-- Plays and shows n dices.
function PlayDice(n)
n = math.min(n, 6)
n = math.max(n, 1)
local dice_height = 7
local result_lines = {}
for i = 1, dice_height do result_lines[i] = "" end
for i = 1, n do
local index = math.random(1, 6)
local dice = _DICE_BITMAPS[index]
-- Splits the dice bitmap into lines and appends each line to the
-- corresponding line of the result.
local lines = ime.split_string(dice, "\n")
for i, line in ipairs(lines) do
if i > dice_height then break end
result_lines[i] = result_lines[i] .. line .. ' '
end
end
-- Merges result lines.
for i, line in ipairs(result_lines) do
result_lines[i] = ime.trim_string_right(result_lines[i])
end
local result = "\n" .. ime.join_string(result_lines, "\n") .. "\n"
return result
end
--------------------------
_ZODIAC_TABLE = {
[{3, 21, 4, 19}] = "白羊座(Aries) ",
[{4, 20, 5, 20}] = "金牛座(Taurus) ",
[{5, 21, 6, 21}] = "双子座(Gemini) ",
[{6, 22, 7, 22}] = "巨蟹座(Cancer) ",
[{7, 23, 8, 22}] = "狮子座(Leo) ",
[{8, 23, 9, 23}] = "处女座(Virgo) ",
[{9, 24, 10, 23}] = "天秤座(Libra) ",
[{10, 24, 11, 21}] = "天蝎座(Scorpio) ",
[{11, 22, 12, 21}] = "射手座(Sagittarius) ",
[{12, 22, 12, 31}] = "摩羯座(Capricorn) ",
[{1, 1, 1, 19}] = "摩羯座(Capricorn) ",
[{1, 20, 2, 18}] = "水瓶座(Aquarius) ",
[{2, 19, 3, 20}] = "双鱼座(Pisces) ",
}
_MONTH_TABLE_NORMAL = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
_MONTH_TABLE_LEAF = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
function _CompareMonthAndDay(month1, day1, month2, day2)
if month1 < month2 then
return -1
elseif month1 > month2 then
return 1
elseif day1 < day2 then
return -1
elseif day1 > day2 then
return 1
else
return 0
end
end
-- birthday is a string in MM-DD format.
function QueryZodiac(birthday)
local month = 0
local day = 0
birthday:gsub("([0-9]+)-([0-9]+)$",
function(m, d)
month = tonumber(m)
day = tonumber(d)
end
)
_VerifyDate(month, day)
for range, name in pairs(_ZODIAC_TABLE) do
local from_month = range[1]
local from_day = range[2]
local to_month = range[3]
local to_day = range[4]
if _CompareMonthAndDay(month, day, from_month, from_day) >=0 and
_CompareMonthAndDay(month, day, to_month, to_day) <=0 then
return name
end
end
error("Should never reach here")
end
-----
-- Print Chinese manuscript grids. width_and_height in "WxH" format.
-- ┏━━━━━━━━━┓
-- ┣━┳━┳━┳━┳━┫
-- ┃ ┃ ┃ ┃ ┃ ┃
-- ┣━┻━┻━┻━┻━┫
-- ┣━┳━┳━┳━┳━┫
-- ┃ ┃ ┃ ┃ ┃ ┃
-- ┣━┻━┻━┻━┻━┫
-- ┣━┳━┳━┳━┳━┫
-- ┃ ┃ ┃ ┃ ┃ ┃
-- ┣━┻━┻━┻━┻━┫
-- ┗━━━━━━━━━┛
function PrintGaozhi(width_and_height)
local width
local height
width_and_height:gsub("([0-9]+)[x%*]([0-9]+)$",
function(w, h)
width = w
height = h
end
)
width = math.min(width, 20)
width = math.max(width, 1)
height = math.min(height, 20)
height = math.max(height, 1)
local result = "\n"
local print_line = function(leading, middle, middle_repeat, ending)
result = result .. leading
for i = 1, middle_repeat do
result = result .. middle
end
result = result .. ending
result = result .. "\n"
end
print_line("┏", "━", width * 2 - 1, "┓")
for i = 1, height do
print_line("┣", "━┳", width - 1, "━┫")
print_line("┃", " ┃", width, "")
print_line("┣", "━┻", width - 1, "━┫")
end
print_line("┗", "━", width * 2 - 1, "┛")
return result .. "\n"
end
function GetCurrentTime()
return GetTime("")
end
function GetToday()
return GetDate("")
end
----------------------------------
function AddDecoration(text)
local ret = ""
local i = 1
while i <= #text do
if text:byte(i, i) < 128 then
ret = ret .. text:sub(i, i)
i = i + 1
else
ret = ret .. text:sub(i, i + 2) .. "\210\137"
i = i + 3
end
end
return ret
end
function AddUnicode(text)
local ret = ""
local utf16_text = ime.utf8_to_utf16(text)
local utf16_len = #utf16_text
local i = 1
local j = 1
while i <= #text and j <= #utf16_text do
if text:byte(i, i) < 128 then
utf16_code = ime.int_to_hex_string(utf16_text:byte(j, j), 2)
ret = ret .. text:sub(i, i) .. "(" .. utf16_code .. ")"
i = i + 1
j = j + 2
else
utf16_code_lo = ime.int_to_hex_string(utf16_text:byte(j, j), 2)
utf16_code_hi = ime.int_to_hex_string(utf16_text:byte(j + 1, j + 1), 2)
ret = ret .. text:sub(i, i + 2)
ret = ret .. "(" .. utf16_code_hi .. utf16_code_lo .. ")"
i = i + 3
j = j + 2
end
end
return ret
end
------------
ime.register_command("sj", "GetTime", "输入时间", "alpha", "输入可选时间,例如12:34")
ime.register_command("rq", "GetDate", "输入日期", "alpha", "输入可选日期,例如2008-08-08")
ime.register_command("js", "Compute", "计算模式", "none", "输入表达式,例如3*log(4+2)")
ime.register_command("gz", "PrintGaozhi", "打印稿纸", "none", "输入稿纸大小,例如2x3")
ime.register_command("xz", "QueryZodiac", "查询星座", "none", "输入您的生日,例如12-14")
ime.register_command("sz", "PlayDice", "掷骰子", "none", "输入骰子个数,例如3")
ime.register_command("zf", "PrintLetter", "打印字符", "none", "请输入字母或数字序列,例如hello")
ime.register_command("hh", "PrintAscii", "画画")
ime.register_trigger("GetCurrentTime", "显示时间", {}, {'时间'})
ime.register_trigger("GetToday", "显示日期", {}, {'日期'})
ime.register_converter("AddDecoration", "添加装饰效果")
ime.register_converter("AddUnicode", "查询Unicode编码")
谷歌拼音自带lua的更多相关文章
- 用Lua扩展谷歌拼音输入法
谷歌拼音输入法最后一次更新是2013年,最近2年毫无动静,这个产品应该已经停了,不过这并不影响对它的使用,我一直喜欢它的简洁和稳定. 说不上来什么原因,忽然想起了摆弄摆弄谷歌拼音输入法的扩展特性(我经 ...
- [系统软件]Ubuntu 18.04 LTS 安装 搜狗输入法,谷歌拼音
1. 讲什么 本文主要讲述在Ubuntu18.04 LTS版本中安装搜狗输入法.谷歌拼音输入法的过程. 2. 为什么讲 1. Ubuntu电脑自带Ibus输入法+拼音/五笔,但是用了一段时间之后发现经 ...
- Ubuntu 18.04 LTS版本 谷歌拼音输入法安装
为何安装? 自带IBUS框架对中文支持不稳定 采用对中文支持稳定的fcitx框架 如何安装? 步骤如下: 卸载自带IBUS框架 命令:sudo remove ibus 安装fcitx框架 ...
- 谷歌拼音输入法扩展API开发指南
为了帮助开发者在谷歌拼音输入法的基本输入功能基础上,开发和定义更丰富的扩展输入功能,谷歌拼音输入法提供了以Lua脚本编程语言为基础的输入法扩展API.利用输入法扩展API,开发者可以编写自定义的输入功 ...
- ubuntu 16.04 LTS - 谷歌拼音输入法
https://blog.csdn.net/chengyq116/article/details/78638249 1. installation1.1 汉语语言包 sudo apt-get inst ...
- ubuntu安装谷歌拼音输入法
在这篇教程中,我将告诉你如何在ubuntu系统上安装谷歌拼音输入法.谷歌拼音输入法有基于ibus框架的,也有基于fcitx框架的.我只演示fcitx框架下谷歌拼音输入法的安装,因为ibus框架的谷歌拼 ...
- linux下安装谷歌拼音输入法
linux下安装谷歌拼音输入法 输入以下命令,等待安装完成. sudo apt-get install fcitx 接着输入,完成安装谷歌中文输入法 sudo apt-get install fcit ...
- 编译安装带lua 的 vim 编辑器
注:支持7.4以后的vim版本 安装lua dev库yum -bcurrent install lua-devel 编译vim带lua支持,安装到/home/sy120714/software/vim ...
- HTML5 汉字转化为拼音,带读声,穷举多音字
1,没别的,像这种没有规则的转化,我们首先需要一个字典文件,字典文件的完整度,决定了转化的成功率与精确度 2,笔者收集了较为完整的字典文件,已上传到博客园,欢迎补充 => https://b ...
随机推荐
- 【NOI P模拟赛】(要素过多的标题)(容斥原理)
题面 0 题目背景 [ 数 据 删 除 ] _{^{[数\,据\,删\,除]}} [数据删除] 1 题目描述 在执行任务时,收集到了 n n n 份能源,其中第 i i i 份的能量值是 ...
- P7727 风暴之眼 Eye of the Storm (树形 DP)
谨 以 此 文 表 达 笔 者 个 人 观 点 , 如 有 冒 犯 官 解 , 可 在 评 论 区 诉 说 _{^{_{谨以此文表达笔者个人观点,如有冒犯官解,可在评论区诉说}}} 谨以此文表达笔者个 ...
- 【Swift】从零开始的Swift语言学习笔记-1:前言&Hello World
该系列分为两个大的部分. Swift基本语法 使用Xcode编写iOS应用程式 两个部分会双线并行更新. 本人的学习资料大多为Apple Develop官方上的生肉,难免会有疏漏,望斧正. 另外该系列 ...
- Maven中使用ssm框架出现:org.apache.tomcat.util.modeler.BaseModelMBean.invoke 调用方法[manageApp]时发生异常
org.apache.tomcat.util.modeler.BaseModelMBean.invoke 调用方法[manageApp]时发生异常 首先可以排查一下像: @RequestMapping ...
- helm安装csi-driver-nfs-v4.1.0
Application version v4.1.0 Chart version v4.1.0 获取chart包 helm repo add csi-driver-nfs https://raw.gi ...
- 安卓平台RTMP推流或轻量级RTSP服务(摄像头或同屏)编码前数据接入类型总结
很多开发者在做Android平台RTMP推流或轻量级RTSP服务(摄像头或同屏)时,总感觉接口不够用,以大牛直播SDK为例 (Github) 我们来总结下,我们常规需要支持的编码前音视频数据有哪些类型 ...
- 使用Pipeline抽象业务生命周期流程
上篇关于流程引擎的文章还是快两年以前的<微服务业务生命周期流程管控引擎>,这中间各种低代码平台层出不穷,虽然有些仅仅是OA+表单的再度包装,但有些的确是在逻辑和操作单元层面进行了真正的高度 ...
- Dapr 证书过期了怎么办? 别慌,有救!
一.背景 Dapr 默认证书有效时间是1年,证书过期后就不能执行相关控制面和数据面的交互了,如下图: 二.查看证书有效时间 通过dapr mtls expiry 看到期时间,具体参见命令https:/ ...
- filebeat直接给es传输日志,自定义索引名
ElasticStack从2019年1月29日的6.6.0版本的开始,引入了索引生命周期管理的功能,新版本的Filebeat则默认的配置开启了ILM,导致索引的命名规则被ILM策略控制. 加上这个配置 ...
- 使用nginx反向代理RabbitMQ的web界面
直接贴nginx的conf配置: server { listen 80; server_name www.xxxxx.com; location / { client_body_buffer_size ...