chore: sync
This commit is contained in:
@@ -8,17 +8,17 @@ if vim.fn.has('nvim-0.9') == 1 then
|
||||
end
|
||||
|
||||
return {
|
||||
theme = 'default', -- see lua/Trans/style/theme.lua
|
||||
theme = 'default', -- see lua/Trans/style/theme.lua
|
||||
auto_play = true,
|
||||
dir = vim.fn.expand('$HOME/.vim/dict'),
|
||||
strategy = {
|
||||
dir = vim.fn.expand('$HOME/.vim/dict'),
|
||||
strategy = {
|
||||
frontend = 'hover',
|
||||
backend = '*',
|
||||
},
|
||||
backend = {
|
||||
backend = {
|
||||
timeout = 2000,
|
||||
},
|
||||
frontend = {
|
||||
frontend = {
|
||||
hover = {
|
||||
title = title, -- need nvim-0.9
|
||||
width = 37,
|
||||
@@ -54,12 +54,12 @@ return {
|
||||
},
|
||||
},
|
||||
-- or use emoji
|
||||
icon = {
|
||||
star = '', -- ⭐
|
||||
icon = {
|
||||
star = '', -- ⭐
|
||||
notfound = ' ', -- ❔
|
||||
yes = '✔', -- ✔️
|
||||
no = '', -- ❌
|
||||
cell = '■', -- ■ | □ | ▇ | ▏ ▎ ▍ ▌ ▋ ▊ ▉ █
|
||||
yes = '✔', -- ✔️
|
||||
no = '', -- ❌
|
||||
cell = '■', -- ■ | □ | ▇ | ▏ ▎ ▍ ▌ ▋ ▊ ▉ █
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
3
lua/Trans/core/defines.lua
Normal file
3
lua/Trans/core/defines.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
return {
|
||||
|
||||
}
|
||||
@@ -1,12 +1,38 @@
|
||||
local function set_backend_opts(conf)
|
||||
local strategys = conf.strategy
|
||||
|
||||
local backend = strategys.backend
|
||||
if type(backend) == 'string' then
|
||||
strategys.backend = backend == '*' and backend or { backend }
|
||||
end
|
||||
|
||||
for i = 2, #conf.backends do
|
||||
local name = conf.backends[i]
|
||||
if not strategys[name] then
|
||||
strategys[name] = {
|
||||
frontend = strategys.frontend,
|
||||
backend = strategys.backend,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function define_highlights(conf)
|
||||
local set_hl = vim.api.nvim_set_hl
|
||||
local highlights = require('Trans.style.theme')[conf.theme]
|
||||
for hl, opt in pairs(highlights) do
|
||||
set_hl(0, hl, opt)
|
||||
end
|
||||
end
|
||||
|
||||
return function(opts)
|
||||
local M = require('Trans')
|
||||
if opts then
|
||||
M.conf = vim.tbl_deep_extend('force', M.conf, opts)
|
||||
end
|
||||
local conf = M.conf
|
||||
|
||||
local set_hl = vim.api.nvim_set_hl
|
||||
local hls = require('Trans.style.theme')[M.conf.theme]
|
||||
for hl, opt in pairs(hls) do
|
||||
set_hl(0, hl, opt)
|
||||
end
|
||||
set_backend_opts(conf)
|
||||
define_highlights(conf)
|
||||
end
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
local Trans = require('Trans')
|
||||
local util = Trans.util
|
||||
|
||||
local backends = {
|
||||
'offline',
|
||||
'baidu',
|
||||
}
|
||||
local backends = Trans.conf.backends
|
||||
|
||||
local function new_data(opts)
|
||||
opts = opts or {}
|
||||
local method = opts.method or ({
|
||||
n = 'normal',
|
||||
v = 'visual',
|
||||
})(vim.api.nvim_get_mode().mode)
|
||||
})[vim.api.nvim_get_mode().mode]
|
||||
|
||||
local str = util.get_str(method)
|
||||
if str == '' then return end
|
||||
@@ -21,6 +18,7 @@ local function new_data(opts)
|
||||
str = str,
|
||||
method = method,
|
||||
frontend = strategy.frontend,
|
||||
result = {},
|
||||
}
|
||||
|
||||
local backend = strategy.backend
|
||||
@@ -40,6 +38,15 @@ local function new_data(opts)
|
||||
end
|
||||
|
||||
local function set_result(data)
|
||||
local t_backend = require('Trans.backend')
|
||||
for _, name in data.backend do
|
||||
local backend = t_backend[name]
|
||||
backend.query(data)
|
||||
if backend.no_wait then
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
require('Trans.backend').baidu.query(data)
|
||||
local thread = coroutine.running()
|
||||
local resume = function()
|
||||
@@ -57,9 +64,10 @@ local function set_result(data)
|
||||
end
|
||||
|
||||
local function render_window()
|
||||
|
||||
|
||||
end
|
||||
|
||||
-- HACK : Core process logic
|
||||
local function process(opts)
|
||||
Trans.translate = coroutine.wrap(process)
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ function M.get_str(method)
|
||||
input = function()
|
||||
return fn.input('请输入需要查询的单词:')
|
||||
end,
|
||||
})(method)()
|
||||
})[method]()
|
||||
end
|
||||
|
||||
function M.is_English(str)
|
||||
|
||||
Reference in New Issue
Block a user