feat: change cmp window border

This commit is contained in:
JuanZoran 2023-01-25 11:04:18 +08:00
parent 8fde14e267
commit 934231183d
6 changed files with 123 additions and 79 deletions

View File

@ -82,7 +82,7 @@ M.conf = {
-- yes = '✔️',
-- no = '❌'
},
theme = 'default',
db_path = '$HOME/.vim/dict/ultimate.db',
-- TODO :
@ -118,7 +118,24 @@ M.setup = function(opts)
float.width = math.floor(vim.o.columns * float.width)
M.translate = require('Trans.translate')
require("Trans.setup")
if vim.fn.executable('sqlite3') ~= 1 then
error('Please check out sqlite3')
end
vim.api.nvim_create_user_command('Translate', function()
require("Trans").translate()
end, { desc = ' 单词翻译', })
vim.api.nvim_create_user_command('TranslateInput', function()
require("Trans").translate('i')
end, { desc = ' 搜索翻译' })
local hls = require('Trans.theme')[M.conf.theme]
for hl, opt in pairs(hls) do
vim.api.nvim_set_hl(0, hl, opt)
end
end
M.augroup = vim.api.nvim_create_augroup('Trans', { clear = true })

View File

@ -1,66 +0,0 @@
if vim.fn.executable('sqlite3') ~= 1 then
error('Please check out sqlite3')
end
vim.api.nvim_create_user_command('Translate', function()
require("Trans").translate()
end, { desc = ' 单词翻译', })
vim.api.nvim_create_user_command('TranslateInput', function()
require("Trans").translate('i')
end, { desc = ' 搜索翻译' })
-- vim.api.nvim_create_user_command('TranslateLast', function()
-- require("Trans").translate('last')
-- end, { desc = ' 显示上一次查询的内容' })
local hls = {
TransWord = {
fg = '#7ee787',
bold = true,
},
TransPhonetic = {
link = 'Linenr'
},
TransTitle = {
fg = '#0f0f15',
bg = '#75beff',
bold = true,
},
TransTitleRound = {
fg = '#75beff',
},
TransTag = {
fg = '#e5c07b',
},
TransExchange = {
link = 'TransTag',
},
TransPos = {
link = 'TransTag',
},
TransTranslation = {
link = 'TransWord',
},
TransDefinition = {
link = 'Moremsg',
},
TransWin = {
link = 'Normal',
},
TransBorder = {
link = 'FloatBorder',
},
TransCollins = {
fg = '#faf743',
bold = true,
},
TransFailed = {
fg = '#7aa89f',
},
}
for hl, opt in pairs(hls) do
vim.api.nvim_set_hl(0, hl, opt)
end

95
lua/Trans/theme.lua Normal file
View File

@ -0,0 +1,95 @@
return {
default = {
TransWord = {
fg = '#7ee787',
bold = true,
},
TransPhonetic = {
link = 'Linenr'
},
TransTitle = {
fg = '#0f0f15',
bg = '#75beff',
bold = true,
},
TransTitleRound = {
fg = '#75beff',
},
TransTag = {
-- fg = '#e5c07b',
link = '@tag'
},
TransExchange = {
link = 'TransTag',
},
TransPos = {
link = 'TransTag',
},
TransTranslation = {
link = 'TransWord',
},
TransDefinition = {
link = 'Moremsg',
},
TransWin = {
link = 'Normal',
},
TransBorder = {
fg = '#89B4FA',
},
TransCollins = {
fg = '#faf743',
bold = true,
},
TransFailed = {
fg = '#7aa89f',
},
},
--- TODO :
tokyonight = {
TransWord = {
fg = '#7ee787',
bold = true,
},
TransPhonetic = {
link = 'Comment',
},
TransTitle = {
fg = '#0f0f15',
bg = '#75beff',
bold = true,
},
TransTitleRound = {
fg = '#75beff',
},
TransTag = {
fg = '#e5c07b',
},
TransExchange = {
link = 'TransTag',
},
TransPos = {
link = 'TransTag',
},
TransTranslation = {
link = 'TransWord',
},
TransDefinition = {
link = 'Moremsg',
},
TransWin = {
link = 'Normal',
},
TransBorder = {
fg = '#8269b5',
},
TransCollins = {
fg = '#faf743',
bold = true,
},
TransFailed = {
fg = '#7aa89f',
},
},
}

View File

@ -56,11 +56,9 @@ local action = {
}
local handle = {
title = function()
-- TODO :
end,
}
local function process()
end
return function(word)
-- TODO :online query
@ -89,9 +87,7 @@ return function(word)
if m_result then
set_tag_hl(engine_us, 'success')
for _, proc in pairs(handle) do
proc()
end
process()
else
set_tag_hl(engine_us, 'fail')
end

View File

@ -10,7 +10,6 @@ local item
local m_indent = ' '
local title = function(str)
m_content:addline(
text(
@ -313,6 +312,7 @@ return function(word)
m_window:set('wrap', true)
end)
-- Auto Close
cmd_id = api.nvim_create_autocmd(
hover.auto_close_events, {

View File

@ -258,11 +258,13 @@ return function(entry, option)
}
setmetatable(win, { __index = window })
win:set('winhl', 'Normal:TransWin,FloatBorder:TransBorder')
-- FIXME :config this
win:bufset('filetype', 'Trans')
win:bufset('buftype', 'nofile')
api.nvim_win_set_hl_ns(win.winid, win.hl)
win:set('winhl', 'Normal:TransWin,FloatBorder:TransBorder,NormalFloat:TransBorder')
---@diagnostic disable-next-line: return-type-mismatch
return win
end