From 934231183d96a3e3569a74c0ee31df933209cf43 Mon Sep 17 00:00:00 2001 From: JuanZoran <1430359574@qq.com> Date: Wed, 25 Jan 2023 11:04:18 +0800 Subject: [PATCH] feat: change cmp window border --- lua/Trans/init.lua | 21 ++++++++- lua/Trans/setup.lua | 66 ---------------------------- lua/Trans/theme.lua | 95 ++++++++++++++++++++++++++++++++++++++++ lua/Trans/view/float.lua | 12 ++--- lua/Trans/view/hover.lua | 2 +- lua/Trans/window.lua | 6 ++- 6 files changed, 123 insertions(+), 79 deletions(-) delete mode 100644 lua/Trans/setup.lua create mode 100644 lua/Trans/theme.lua diff --git a/lua/Trans/init.lua b/lua/Trans/init.lua index c61569c..2a56cd9 100644 --- a/lua/Trans/init.lua +++ b/lua/Trans/init.lua @@ -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 }) diff --git a/lua/Trans/setup.lua b/lua/Trans/setup.lua deleted file mode 100644 index ad49e4d..0000000 --- a/lua/Trans/setup.lua +++ /dev/null @@ -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 diff --git a/lua/Trans/theme.lua b/lua/Trans/theme.lua new file mode 100644 index 0000000..c94292d --- /dev/null +++ b/lua/Trans/theme.lua @@ -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', + }, + }, +} diff --git a/lua/Trans/view/float.lua b/lua/Trans/view/float.lua index 640bf39..650335a 100644 --- a/lua/Trans/view/float.lua +++ b/lua/Trans/view/float.lua @@ -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 diff --git a/lua/Trans/view/hover.lua b/lua/Trans/view/hover.lua index a2bc350..5fde976 100644 --- a/lua/Trans/view/hover.lua +++ b/lua/Trans/view/hover.lua @@ -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, { diff --git a/lua/Trans/window.lua b/lua/Trans/window.lua index 8b889e4..99f6c2a 100644 --- a/lua/Trans/window.lua +++ b/lua/Trans/window.lua @@ -179,7 +179,7 @@ local window = { self.winid = -1 end end - end, + end, reopen = function(self, entry, opt, callback) check_busy() @@ -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