2023-03-16 19:25:08 +08:00
|
|
|
local node = require('Trans').util.node
|
|
|
|
local it, t, f, co = node.item, node.text, node.format, node.conjunction
|
|
|
|
|
2023-03-16 17:17:30 +08:00
|
|
|
---@type TransHoverRenderer
|
|
|
|
local M = {}
|
2023-03-16 21:15:00 +08:00
|
|
|
local interval = (' '):rep(4)
|
2023-03-16 17:17:30 +08:00
|
|
|
|
2023-03-16 19:25:08 +08:00
|
|
|
function M.web(hover, result)
|
|
|
|
if not result.web then return end
|
2023-03-16 21:15:00 +08:00
|
|
|
local buffer = hover.buffer
|
|
|
|
buffer:setline(co('网络释义'))
|
|
|
|
|
|
|
|
for _, w in ipairs(result.web) do
|
|
|
|
buffer:setline(it(
|
|
|
|
--- TODO :Better format style
|
|
|
|
interval .. w.key .. interval .. table.concat(w.value, ' | '),
|
|
|
|
'TransWeb'
|
|
|
|
))
|
|
|
|
end
|
|
|
|
buffer:setline('')
|
|
|
|
end
|
2023-03-16 19:25:08 +08:00
|
|
|
|
2023-03-16 17:17:30 +08:00
|
|
|
|
2023-03-16 21:15:00 +08:00
|
|
|
function M.explains(hover, result)
|
|
|
|
local explains = result.explains
|
|
|
|
if not explains then return end
|
|
|
|
local buffer = hover.buffer
|
|
|
|
buffer:setline(co('基本释义'))
|
|
|
|
|
|
|
|
|
|
|
|
for i = 1, #explains, 2 do
|
|
|
|
buffer:setline(it(
|
|
|
|
interval .. explains[i] ..
|
|
|
|
(explains[i + 1] and interval .. explains[i + 1] or ''),
|
|
|
|
'TransExplains'
|
|
|
|
))
|
|
|
|
end
|
|
|
|
buffer:setline('')
|
2023-03-16 17:17:30 +08:00
|
|
|
end
|
|
|
|
|
2023-03-16 21:15:00 +08:00
|
|
|
M.title = require('Trans').frontend.hover.offline.title
|
|
|
|
|
2023-03-16 17:17:30 +08:00
|
|
|
return M
|