feat: add some bugs
This commit is contained in:
7
lua/Trans/api/READMD.md
Normal file
7
lua/Trans/api/READMD.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# API说明
|
||||
|
||||
## 概述
|
||||
- 翻译查询
|
||||
- ``
|
||||
- 字段处理
|
||||
- 窗口显示
|
8
lua/Trans/api/init.lua
Normal file
8
lua/Trans/api/init.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
local M = {}
|
||||
|
||||
local query_warpper = require 'Trans.api.query'
|
||||
|
||||
M.query = query_warpper.query
|
||||
|
||||
|
||||
return M
|
51
lua/Trans/api/query.lua
Normal file
51
lua/Trans/api/query.lua
Normal file
@@ -0,0 +1,51 @@
|
||||
local M = {}
|
||||
local _, db = pcall(require, 'sqlite.db')
|
||||
if not _ then
|
||||
error('Please check out sqlite.lua')
|
||||
end
|
||||
local type_check = require("Trans.util.debug").type_check
|
||||
|
||||
-- INFO : init database
|
||||
local path = require("Trans.conf.loader").loaded_conf.base.db_path
|
||||
local dict = db:open(path)
|
||||
|
||||
-- INFO :Auto Close
|
||||
vim.api.nvim_create_autocmd('VimLeavePre', {
|
||||
group = require("Trans.conf.base").autogroup,
|
||||
callback = function()
|
||||
if db:isopen() then
|
||||
db:close()
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
local query_field = {
|
||||
'word',
|
||||
'phonetic',
|
||||
'definition',
|
||||
'translation',
|
||||
'pos',
|
||||
'collins',
|
||||
'oxford',
|
||||
'tag',
|
||||
'exchange',
|
||||
}
|
||||
|
||||
-- NOTE : local query
|
||||
M.query = function(arg)
|
||||
-- TODO : more opts
|
||||
type_check {
|
||||
arg = { arg, 'string' },
|
||||
}
|
||||
local res = dict:select('stardict', {
|
||||
where = {
|
||||
word = arg,
|
||||
},
|
||||
keys = query_field,
|
||||
})
|
||||
return res[1]
|
||||
end
|
||||
|
||||
|
||||
return M
|
Reference in New Issue
Block a user