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', v = 'hover',
}, },
hover = { hover = {
width = 36, width = 37,
height = 26, height = 27,
border = 'rounded', border = 'rounded',
title = { title = {
{ '', 'TransTitleRound' }, { '', 'TransTitleRound' },
@ -192,7 +192,7 @@ require'Trans'.setup {
'CursorMoved', 'CursorMoved',
'BufLeave', 'BufLeave',
}, },
auto_play = true, -- WARN : 请阅读说明 auto_play = true,
}, },
float = { float = {
width = 0.8, width = 0.8,
@ -210,43 +210,37 @@ require'Trans'.setup {
open = 'fold', open = 'fold',
close = 'fold', close = 'fold',
interval = 10, interval = 10,
},
tag = {
wait = '#519aba',
fail = '#e46876',
success = '#10b981',
},
engine = {
'本地',
} }
}, },
order = { order = { -- only work on hover mode
-- offline = {
'title', 'title',
'tag', 'tag',
'pos', 'pos',
'exchange', 'exchange',
'translation', 'translation',
'definition', 'definition',
-- },
-- online = {
-- -- TODO
-- },
}, },
icon = { icon = {
star = '', star = '',
-- notfound = '❔',
notfound = ' ', notfound = ' ',
yes = ' ', yes = ' ',
no = '' no = ''
-- star = '⭐',
-- notfound = '❔',
-- yes = '✔️', -- yes = '✔️',
-- no = '❌' -- no = '❌'
-- star = '⭐',
}, },
theme = 'default', -- 目前可选的: default, tokyonight, dracula
db_path = '$HOME/.vim/dict/ultimate.db', db_path = '$HOME/.vim/dict/ultimate.db',
-- TODO :
-- engine = {
-- -- TODO
-- 'offline',
-- }
-- history = {
-- -- TOOD
-- }
-- TODO add online translate engine -- TODO add online translate engine
-- online_search = { -- online_search = {
-- enable = false, -- enable = false,

View File

@ -82,25 +82,19 @@ M.conf = {
-- yes = '✔️', -- yes = '✔️',
-- no = '❌' -- no = '❌'
}, },
theme = 'default',
-- theme = 'dracula',
-- theme = 'tokyonight',
db_path = '$HOME/.vim/dict/ultimate.db', db_path = '$HOME/.vim/dict/ultimate.db',
-- TODO : -- TODO :
-- engine = { -- register word
-- -- TODO
-- 'offline',
-- }
-- history = { -- history = {
-- -- TOOD -- -- TOOD
-- } -- }
-- TODO add online translate engine -- TODO :add online translate engine
-- online_search = {
-- enable = false,
-- engine = {},
-- }
-- TODO register word
} }
M.setup = function(opts) M.setup = function(opts)
@ -118,7 +112,24 @@ M.setup = function(opts)
float.width = math.floor(vim.o.columns * float.width) float.width = math.floor(vim.o.columns * float.width)
M.translate = require('Trans.translate') 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 end
M.augroup = vim.api.nvim_create_augroup('Trans', { clear = true }) 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 = { local function process()
title = function()
-- TODO : end
end,
}
return function(word) return function(word)
-- TODO :online query -- TODO :online query
@ -89,9 +87,7 @@ return function(word)
if m_result then if m_result then
set_tag_hl(engine_us, 'success') set_tag_hl(engine_us, 'success')
for _, proc in pairs(handle) do process()
proc()
end
else else
set_tag_hl(engine_us, 'fail') set_tag_hl(engine_us, 'fail')
end end

View File

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

View File

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