refactor: add node file for utility
This commit is contained in:
@@ -9,6 +9,11 @@ local engine_map = {
|
||||
['有道'] = 'youdao',
|
||||
}
|
||||
|
||||
local node = require("Trans.node")
|
||||
local t = node.text
|
||||
local it = node.item
|
||||
|
||||
|
||||
local function set_tag_hl(name, status)
|
||||
local hl = conf.float.tag[status]
|
||||
m_window:set_hl(name, {
|
||||
@@ -25,13 +30,10 @@ local function set_title()
|
||||
local title = m_window.contents[1]
|
||||
local github = ' https://github.com/JuanZoran/Trans.nvim'
|
||||
|
||||
local item = title.item_wrap
|
||||
|
||||
title:addline(
|
||||
title:center(item(github, '@text.uri'))
|
||||
title:center(it(github, '@text.uri'))
|
||||
)
|
||||
|
||||
local text = title.text_wrap
|
||||
local format = '%s(%d)'
|
||||
for i, engine_ch in ipairs(conf.float.engine) do
|
||||
local engine_us = engine_map[engine_ch]
|
||||
@@ -39,10 +41,10 @@ local function set_title()
|
||||
|
||||
local round = engine_us .. 'round'
|
||||
title:addline(
|
||||
text(
|
||||
item('', round),
|
||||
item(format:format(engine_ch, i), engine_us),
|
||||
item('', round)
|
||||
t(
|
||||
it('', round),
|
||||
it(format:format(engine_ch, i), engine_us),
|
||||
it('', round)
|
||||
)
|
||||
)
|
||||
end
|
||||
@@ -56,7 +58,7 @@ local action = {
|
||||
|
||||
|
||||
local function process()
|
||||
|
||||
-- TODO :
|
||||
end
|
||||
|
||||
return function(word)
|
||||
|
@@ -5,18 +5,15 @@ local m_window
|
||||
local m_result
|
||||
local m_content
|
||||
-- content utility
|
||||
local text
|
||||
local item
|
||||
local node = require("Trans.node")
|
||||
local t = node.text
|
||||
local it = node.item
|
||||
|
||||
local m_indent = ' '
|
||||
|
||||
local title = function(str)
|
||||
m_content:addline(
|
||||
text(
|
||||
item('', 'TransTitleRound'),
|
||||
item(str, 'TransTitle'),
|
||||
item('', 'TransTitleRound')
|
||||
)
|
||||
t(it('', 'TransTitleRound'), it(str, 'TransTitle'), it('', 'TransTitleRound'))
|
||||
)
|
||||
end
|
||||
|
||||
@@ -31,14 +28,14 @@ local process = {
|
||||
|
||||
m_content:addline(
|
||||
m_content:format(
|
||||
item(m_result.word, 'TransWord'),
|
||||
text(
|
||||
item('['),
|
||||
item(exist(m_result.phonetic) and m_result.phonetic or icon.notfound, 'TransPhonetic'),
|
||||
item(']')
|
||||
it(m_result.word, 'TransWord'),
|
||||
t(
|
||||
it('['),
|
||||
it(exist(m_result.phonetic) and m_result.phonetic or icon.notfound, 'TransPhonetic'),
|
||||
it(']')
|
||||
),
|
||||
item(m_result.collins and icon.star:rep(m_result.collins) or icon.notfound, 'TransCollins'),
|
||||
item(m_result.oxford == 1 and icon.yes or icon.no)
|
||||
it(m_result.collins and icon.star:rep(m_result.collins) or icon.notfound, 'TransCollins'),
|
||||
it(m_result.oxford == 1 and icon.yes or icon.no)
|
||||
)
|
||||
)
|
||||
end,
|
||||
@@ -68,7 +65,7 @@ local process = {
|
||||
|
||||
for i = 1, size, 3 do
|
||||
m_content:addline(
|
||||
item(
|
||||
it(
|
||||
m_indent ..
|
||||
tags[i] ..
|
||||
(tags[i + 1] and interval .. tags[i + 1] ..
|
||||
@@ -102,7 +99,7 @@ local process = {
|
||||
}
|
||||
for pos in vim.gsplit(m_result.pos, '/', true) do
|
||||
m_content:addline(
|
||||
item(m_indent .. pos_map[pos:sub(1, 1)] .. pos:sub(3) .. '%', 'TransPos')
|
||||
it(m_indent .. pos_map[pos:sub(1, 1)] .. pos:sub(3) .. '%', 'TransPos')
|
||||
)
|
||||
end
|
||||
|
||||
@@ -129,7 +126,7 @@ local process = {
|
||||
|
||||
for exc in vim.gsplit(m_result.exchange, '/', true) do
|
||||
m_content:addline(
|
||||
item(m_indent .. exchange_map[exc:sub(1, 1)] .. interval .. exc:sub(3), 'TransExchange')
|
||||
it(m_indent .. exchange_map[exc:sub(1, 1)] .. interval .. exc:sub(3), 'TransExchange')
|
||||
)
|
||||
end
|
||||
|
||||
@@ -142,7 +139,7 @@ local process = {
|
||||
|
||||
for trs in vim.gsplit(m_result.translation, '\n', true) do
|
||||
m_content:addline(
|
||||
item(m_indent .. trs, 'TransTranslation')
|
||||
it(m_indent .. trs, 'TransTranslation')
|
||||
)
|
||||
end
|
||||
|
||||
@@ -156,7 +153,7 @@ local process = {
|
||||
for def in vim.gsplit(m_result.definition, '\n', true) do
|
||||
def = def:gsub('^%s+', '', 1) -- TODO :判断是否需要分割空格
|
||||
m_content:addline(
|
||||
item(m_indent .. def, 'TransDefinition')
|
||||
it(m_indent .. def, 'TransDefinition')
|
||||
)
|
||||
end
|
||||
|
||||
@@ -166,7 +163,7 @@ local process = {
|
||||
|
||||
failed = function()
|
||||
m_content:addline(
|
||||
item(conf.icon.notfound .. m_indent .. '没有找到相关的翻译', 'TransFailed')
|
||||
it(conf.icon.notfound .. m_indent .. '没有找到相关的翻译', 'TransFailed')
|
||||
)
|
||||
|
||||
m_window:set_width(m_content.lines[1]:width())
|
||||
@@ -275,18 +272,13 @@ return function(word)
|
||||
height = hover.height,
|
||||
title = hover.title,
|
||||
border = hover.border,
|
||||
col = 2,
|
||||
row = 2,
|
||||
col = 1,
|
||||
row = 1,
|
||||
})
|
||||
|
||||
m_window.animation = hover.animation
|
||||
m_content = m_window.contents[1]
|
||||
|
||||
if not text then
|
||||
text = m_content.text_wrap
|
||||
item = m_content.item_wrap
|
||||
end
|
||||
|
||||
if m_result then
|
||||
if hover.auto_play then action.play() end
|
||||
|
||||
@@ -312,7 +304,6 @@ return function(word)
|
||||
m_window:set('wrap', true)
|
||||
end)
|
||||
|
||||
|
||||
-- Auto Close
|
||||
cmd_id = api.nvim_create_autocmd(
|
||||
hover.auto_close_events, {
|
||||
|
Reference in New Issue
Block a user