fix: fix miss ',' and better youdao web format style
This commit is contained in:
@ -5,6 +5,38 @@ local interval = (' '):rep(4)
|
||||
---@type TransHoverRenderer
|
||||
local M = {}
|
||||
|
||||
function M.title(hover, result)
|
||||
local title = result.title
|
||||
if not title then return end
|
||||
if type(title) == 'string' then
|
||||
hover.buffer:setline(it(title, 'TransWord'))
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local icon = hover.opts.icon
|
||||
|
||||
local word = title.word
|
||||
local oxford = title.oxford
|
||||
local collins = title.collins
|
||||
local phonetic = title.phonetic
|
||||
|
||||
hover.buffer:setline(f {
|
||||
width = hover.opts.width,
|
||||
text = t {
|
||||
it(word, 'TransWord'),
|
||||
t {
|
||||
it('['),
|
||||
it((phonetic and phonetic ~= '') and phonetic or icon.notfound, 'TransPhonetic'),
|
||||
it(']')
|
||||
},
|
||||
|
||||
it(collins and icon.star:rep(collins) or icon.notfound, 'TransCollins'),
|
||||
it(oxford == 1 and icon.yes or icon.no)
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
function M.tag(hover, result)
|
||||
local tag = result.tag
|
||||
if not tag then return end
|
||||
@ -58,36 +90,4 @@ function M.pos(hover, result)
|
||||
buffer:setline('')
|
||||
end
|
||||
|
||||
function M.title(hover, result)
|
||||
local title = result.title
|
||||
if not title then return end
|
||||
if type(title) == 'string' then
|
||||
hover.buffer:setline(it(title, 'TransWord'))
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local icon = hover.opts.icon
|
||||
|
||||
local word = title.word
|
||||
local oxford = title.oxford
|
||||
local collins = title.collins
|
||||
local phonetic = title.phonetic
|
||||
|
||||
hover.buffer:setline(f {
|
||||
width = hover.opts.width,
|
||||
text = t {
|
||||
it(word, 'TransWord'),
|
||||
t {
|
||||
it('['),
|
||||
it((phonetic and phonetic ~= '') and phonetic or icon.notfound, 'TransPhonetic'),
|
||||
it(']')
|
||||
},
|
||||
|
||||
it(collins and icon.star:rep(collins) or icon.notfound, 'TransCollins'),
|
||||
it(oxford == 1 and icon.yes or icon.no)
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
|
@ -10,17 +10,23 @@ function M.web(hover, result)
|
||||
local buffer = hover.buffer
|
||||
buffer:setline(co('网络释义'))
|
||||
|
||||
local indent = interval .. interval .. hover.opts.icon.list .. ' '
|
||||
for _, w in ipairs(result.web) do
|
||||
buffer:setline(it(
|
||||
--- TODO :Better format style
|
||||
interval .. w.key .. interval .. table.concat(w.value, ' | '),
|
||||
interval .. w.key,
|
||||
'TransWeb'
|
||||
))
|
||||
|
||||
for _, v in ipairs(w.value) do
|
||||
buffer:setline(it(
|
||||
indent .. v,
|
||||
'TransWeb'
|
||||
))
|
||||
end
|
||||
end
|
||||
buffer:setline('')
|
||||
end
|
||||
|
||||
|
||||
function M.explains(hover, result)
|
||||
local explains = result.explains
|
||||
if not explains then return end
|
||||
|
Reference in New Issue
Block a user