diff --git a/README.md b/README.md index b2f2b52..4b90469 100644 --- a/README.md +++ b/README.md @@ -163,8 +163,8 @@ require'Trans'.setup { v = 'hover', }, hover = { - width = 36, - height = 26, + width = 37, + height = 27, border = 'rounded', title = { { '', 'TransTitleRound' }, @@ -192,7 +192,7 @@ require'Trans'.setup { 'CursorMoved', 'BufLeave', }, - auto_play = true, -- WARN : 请阅读说明 + auto_play = true, }, float = { width = 0.8, @@ -210,43 +210,37 @@ require'Trans'.setup { open = 'fold', close = 'fold', interval = 10, + }, + tag = { + wait = '#519aba', + fail = '#e46876', + success = '#10b981', + }, + engine = { + '本地', } }, - order = { - -- offline = { + order = { -- only work on hover mode 'title', 'tag', 'pos', 'exchange', 'translation', 'definition', - -- }, - -- online = { - -- -- TODO - -- }, }, icon = { star = '', - -- notfound = '❔', notfound = ' ', yes = ' ', no = '' + -- star = '⭐', + -- notfound = '❔', -- yes = '✔️', -- no = '❌' - -- star = '⭐', }, - + theme = 'default', -- 目前可选的: default, tokyonight, dracula db_path = '$HOME/.vim/dict/ultimate.db', - -- TODO : - -- engine = { - -- -- TODO - -- 'offline', - -- } - -- history = { - -- -- TOOD - -- } - -- TODO add online translate engine -- online_search = { -- enable = false, diff --git a/lua/Trans/init.lua b/lua/Trans/init.lua index c61569c..9ebf9db 100644 --- a/lua/Trans/init.lua +++ b/lua/Trans/init.lua @@ -82,25 +82,19 @@ M.conf = { -- yes = '✔️', -- no = '❌' }, + theme = 'default', + -- theme = 'dracula', + -- theme = 'tokyonight', db_path = '$HOME/.vim/dict/ultimate.db', -- TODO : - -- engine = { - -- -- TODO - -- 'offline', - -- } + -- register word -- history = { -- -- TOOD -- } - -- TODO add online translate engine - -- online_search = { - -- enable = false, - -- engine = {}, - -- } - - -- TODO register word + -- TODO :add online translate engine } M.setup = function(opts) @@ -118,7 +112,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..737936f --- /dev/null +++ b/lua/Trans/theme.lua @@ -0,0 +1,140 @@ +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 = '#4ed4bc', + bold = true, + }, + TransPhonetic = { + link = 'Comment', + }, + TransTitle = { + fg = '#0f0f15', + bg = '#82aaff', + bold = true, + }, + TransTitleRound = { + fg = '#82aaff', + }, + TransTag = { + fg = '#6d8fda', + }, + TransExchange = { + link = 'TransTag', + }, + TransPos = { + link = 'TransTag', + }, + TransTranslation = { + link = 'TransWord', + }, + TransDefinition = { + fg = '#82aaff', + }, + TransWin = { + link = 'Normal', + }, + TransBorder = { + fg = '#8269b5', + }, + TransCollins = { + fg = '#cfa364', + bold = true, + }, + TransFailed = { + fg = '#f4b085', + }, + }, + dracula = { + TransWord = { + fg = '#50fa7b', + bold = true, + }, + TransPhonetic = { + fg = '#6272a4', + }, + TransTitle = { + fg = '#0f0f15', + bg = '#bd93f9', + bold = true, + }, + TransTitleRound = { + fg = '#bd93f9', + }, + TransTag = { + fg = '#ffb86c', + }, + TransExchange = { + link = 'TransTag', + }, + TransPos = { + link = 'TransTag', + }, + TransTranslation = { + link = 'TransWord', + }, + TransDefinition = { + fg = '#8be9fd', + }, + TransWin = { + link = 'Normal', + }, + TransBorder = { + fg = '#9274c0', + }, + TransCollins = { + fg = '#f1fa8c', + bold = true, + }, + TransFailed = { + fg = '#8be9fd', + }, + }, +} 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