fix: add max_size support and definition need better format
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
local M = {}
|
||||
local type_check = require("Trans.util.debug").type_check
|
||||
local type_check = vim.validate
|
||||
M.__index = M
|
||||
M.lines = {}
|
||||
M.highlight = {}
|
||||
M.height = 0
|
||||
M.width = 0
|
||||
M.interval = ' '
|
||||
M.opts = {}
|
||||
|
||||
|
||||
function M:new()
|
||||
|
||||
function M:new(opts)
|
||||
if opts then
|
||||
self.opts = opts
|
||||
end
|
||||
|
||||
local content = {}
|
||||
setmetatable(content, self)
|
||||
return content
|
||||
@@ -111,26 +117,26 @@ function M:data()
|
||||
return lines, highlights
|
||||
end
|
||||
|
||||
function M:attach(bufnr, winid)
|
||||
local height = vim.api.nvim_win_get_height(winid)
|
||||
local width = vim.api.nvim_win_get_width(winid)
|
||||
|
||||
vim.api.nvim_win_set_height(winid, self.height)
|
||||
function M:attach()
|
||||
local height = self.opts.win.height
|
||||
local width = self.opts.win.width
|
||||
|
||||
local lines, hls = self:data()
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
vim.api.nvim_buf_set_lines(self.opts.bufnr, 0, -1, false, lines)
|
||||
|
||||
for line, l_hl in ipairs(hls) do
|
||||
for _, hl in ipairs(l_hl) do
|
||||
vim.api.nvim_buf_add_highlight(bufnr, -1, hl.name, line - 1, hl._start, hl._end)
|
||||
vim.api.nvim_buf_add_highlight(self.opts.bufnr, -1, hl.name, line - 1, hl._start, hl._end)
|
||||
end
|
||||
end
|
||||
|
||||
if self.height < height then
|
||||
vim.api.nvim_win_set_height(winid, self.height)
|
||||
vim.api.nvim_win_set_height(self.opts.winid, self.height)
|
||||
end
|
||||
|
||||
if self.width < width then
|
||||
vim.api.nvim_win_set_width(winid, self.width)
|
||||
vim.api.nvim_win_set_width(self.opts.winid, self.width)
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -1,11 +0,0 @@
|
||||
local M = {}
|
||||
local type_check = require("Trans.util.debug").type_check
|
||||
M.__index = M
|
||||
|
||||
function M:new()
|
||||
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
|
@@ -1,7 +1,68 @@
|
||||
local M = {}
|
||||
|
||||
M.component = function (field)
|
||||
-- TODO
|
||||
M.component = function (field, max_size)
|
||||
if field.definition and field.definition ~= '' then
|
||||
local ref = {
|
||||
{ '英文注释', 'TransRef' }
|
||||
}
|
||||
|
||||
local definitions = {
|
||||
highlight = 'TransDefinition',
|
||||
needformat = true,
|
||||
indent = 4,
|
||||
}
|
||||
local size = 0
|
||||
for defin in vim.gsplit(field.definition, '\n', true) do
|
||||
if defin ~= '' then
|
||||
table.insert(definitions, defin)
|
||||
|
||||
size = size + 1
|
||||
if size == max_size then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return { ref, definitions }
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
--[[n a formation of people or things one beside another
|
||||
n a mark that is long relative to its width
|
||||
n a formation of people or things one behind another
|
||||
n a length (straight or curved) without breadth or thickness; the trace of a moving point
|
||||
n text consisting of a row of words written across a page or computer screen
|
||||
n a single frequency (or very narrow band) of radiation in a spectrum
|
||||
n a fortified position (especially one marking the most forward position of troops)
|
||||
n a course of reasoning aimed at demonstrating a truth or falsehood; the methodical process of logical reasoning
|
||||
n a conductor for transmitting electrical or optical signals or electric power
|
||||
n a connected series of events or actions or developments
|
||||
n a spatial location defined by a real or imaginary unidimensional extent
|
||||
n a slight depression in the smoothness of a surface
|
||||
n a pipe used to transport liquids or gases
|
||||
n the road consisting of railroad track and roadbed
|
||||
n a telephone connection
|
||||
n acting in conformity
|
||||
n the descendants of one individual
|
||||
n something (as a cord or rope) that is long and thin and flexible
|
||||
n the principal activity in your life that you do to earn money
|
||||
n in games or sports; a mark indicating positions or bounds of the playing area
|
||||
n (often plural) a means of communication or access
|
||||
n a particular kind of product or merchandise
|
||||
n a commercial organization serving as a common carrier
|
||||
n space for one line of print (one column wide and 1/14 inch deep) used to measure advertising
|
||||
n the maximum credit that a customer is allowed
|
||||
n a succession of notes forming a distinctive sequence
|
||||
n persuasive but insincere talk that is usually intended to deceive or impress
|
||||
n a short personal letter
|
||||
n a conceptual separation or distinction
|
||||
n mechanical system in a factory whereby an article is conveyed through sites at which successive operations are performed on it
|
||||
v be in line with; form a line along
|
||||
v cover the interior of
|
||||
v make a mark or lines on a surface
|
||||
v mark with lines
|
||||
v fill plentifully
|
||||
v reinforce with fabric
|
||||
--]]
|
||||
|
@@ -1,7 +1,45 @@
|
||||
local M = {}
|
||||
|
||||
M.component = function (field)
|
||||
-- TODO
|
||||
local exchange_map = {
|
||||
p = '过去式',
|
||||
d = '过去分词',
|
||||
i = '现在分词',
|
||||
r = '形容词比较级',
|
||||
t = '形容词最高级',
|
||||
s = '名词复数形式',
|
||||
f = '第三人称单数',
|
||||
['0'] = '词根',
|
||||
['1'] = '词根的变化形式',
|
||||
['3'] = '第三人称单数',
|
||||
}
|
||||
|
||||
M.component = function(field)
|
||||
-- TODO
|
||||
if field.exchange and field.exchange ~= '' then
|
||||
local ref = {
|
||||
{ '词型变化', 'TransRef' },
|
||||
}
|
||||
local exchanges = {
|
||||
needformat = true,
|
||||
highlight = 'TransExchange',
|
||||
indent = 4,
|
||||
emptyline = true,
|
||||
}
|
||||
|
||||
for _exchange in vim.gsplit(field.exchange, '/', true) do
|
||||
local prefix = exchange_map[_exchange:sub(1, 1)]
|
||||
if prefix then
|
||||
local exchange = prefix .. _exchange:sub(2)
|
||||
-- local exchange = exchange_map[_exchange:sub(1, 1)] .. _exchange:sub(2)
|
||||
table.insert(exchanges, exchange)
|
||||
|
||||
else
|
||||
error('add exchange_map for [' .. _exchange .. ']')
|
||||
end
|
||||
end
|
||||
|
||||
return { ref, exchanges }
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
@@ -1,7 +1,20 @@
|
||||
local M = {}
|
||||
|
||||
M.component = function (field)
|
||||
-- TODO
|
||||
M.component = function(field)
|
||||
-- TODO
|
||||
if field.pos and field.pos ~= '' then
|
||||
local ref = {
|
||||
{ '词性:', 'TransRef' },
|
||||
}
|
||||
local pos = {
|
||||
{ field.pos },
|
||||
highlight = 'TransPos',
|
||||
indent = 4,
|
||||
emptyline = true,
|
||||
}
|
||||
|
||||
return { ref, pos }
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
@@ -25,17 +25,16 @@ M.component = function(field)
|
||||
needformat = true,
|
||||
highlight = 'TransTag',
|
||||
indent = 4,
|
||||
emptyline = true,
|
||||
}
|
||||
|
||||
for _tag in vim.gsplit(field.tag, ' ', true) do
|
||||
if _tag ~= '' then
|
||||
local tag = tag_map[_tag]
|
||||
local tag = tag_map[_tag]
|
||||
|
||||
if tag then
|
||||
table.insert(tags, tag)
|
||||
else
|
||||
error('add tag_map for [' .. _tag .. ']')
|
||||
end
|
||||
if tag then
|
||||
table.insert(tags, tag)
|
||||
else
|
||||
error('add tag_map for [' .. _tag .. ']')
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -1,7 +1,23 @@
|
||||
local M = {}
|
||||
|
||||
M.component = function (field)
|
||||
-- TODO
|
||||
M.component = function(field)
|
||||
if field.translation then
|
||||
local ref = {
|
||||
{ '中文翻译', 'TransRef' }
|
||||
}
|
||||
|
||||
local translations = {
|
||||
highlight = 'TransTranslation',
|
||||
indent = 4,
|
||||
emptyline = true,
|
||||
needformat = true,
|
||||
}
|
||||
for trans in vim.gsplit(field.translation, '\n', true) do
|
||||
table.insert(translations, trans)
|
||||
end
|
||||
|
||||
return { ref, translations }
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
Reference in New Issue
Block a user