谷歌拼音自带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 ...
随机推荐
- Digester解析xml原理
Tomcat内部是使用Digester来解析xml文件的,将xml转化为java对象. digester底层是基于SAX+事件驱动+栈的方式来搭建实现的,SAX主要用来解析xml,事件驱动主要是在解析 ...
- java-异常处理和线程的一些简单方法及使用
1.1 子类重写父类含有throws声明异常抛出的方法时的规则: 1.允许不再抛出任何异常. 2.仅抛出部分异常. 3.抛出父类方法抛出异常的子类型异常. 4.不可以抛出额外异常. 5.不能抛出父类方 ...
- WebStorm 配置 Vue3 的文件模板
WebStorm 默认的 Vue 模板不是 setup 函数(组合式 API)模板,而是 Options API 模板.在设置中搜索 File and Code Templates 编辑创建 vue ...
- React报错之React Hook 'useEffect' is called in function
正文从这开始~ 总览 为了解决错误"React Hook 'useEffect' is called in function that is neither a React function ...
- PlayCover for mac-Mac 上全屏运行 iOS 应用程序
前言 如何在Mac电脑运行ios应用呢?PlayCover for Mac一款彻底解放苹果电脑的iOS软件安装工具,无需付费,操作简单,可以安装ipa文件,可以通过鼠标.键盘和控制器 在Mac上全屏运 ...
- C# winfrom ListView控件实现自由设置每一行字体及背景色等
背景:公司经常会需要将日志信息,输出到一个对话框中显示出来.之前一直采用的listbox控件,操作简单,使用方便,但是遗憾的是,不能自由控制每一行的状态. 于是想了如下几个方案: (1)重绘listb ...
- 原生JavaScript对【DOM元素】的操作——增、删、改、查
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- PLSQL Developer安装详细步骤,小白,转发
下载软件可以直接在百度网盘里面下载 链接:https://pan.baidu.com/s/1bZNJ71d2-hvkM6PTbdpgAA 提取码:t9sh 然后直接参考这个链接进行安装https:// ...
- 装饰Hexo博客以及部署个人站点
我的博客最开始采用的是Hexo+hexo-theme-next搭建的,使用GitHub Pages托管并进行自动化部署,写文发布的流程非常简单方便,云端写作发布也轻而易举. 本来事情到这里就应该结束了 ...
- Kubernetes容器运行时弃用Docker转型Containerd
文章转载自:https://i4t.com/5435.html Kubernetes社区在2020年7月份发布的版本中已经开始了dockershim的移除计划,在1.20版本中将内置的dockersh ...