Merge pull request #10 from JuanZoran/experimental

加入了一些主题配色选择
This commit is contained in:
Zoran 2023-01-25 13:45:05 +08:00 committed by GitHub
commit 5c12960245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 187 additions and 110 deletions

View File

@ -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,

View File

@ -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 })

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

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

@ -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',
},
},
}

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

@ -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