Trans.nvim/lua/Trans/core/setup.lua

64 lines
1.5 KiB
Lua
Raw Normal View History

2023-03-24 00:56:36 +08:00
local Trans = require 'Trans'
2023-03-12 09:56:31 +08:00
local function set_strategy_opts(conf)
local all_backends = Trans.backend.all_name
2023-03-25 09:41:06 +08:00
local g_strategy = conf.strategy
2023-03-18 21:56:12 +08:00
2023-03-12 09:56:31 +08:00
local function parse_backend(backend)
if type(backend) == 'string' then
return backend == '*' and all_backends or { backend }
end
return backend
2023-03-11 11:32:13 +08:00
end
2023-03-25 09:41:06 +08:00
local default_strategy = g_strategy.default
default_strategy.backend = parse_backend(default_strategy.backend)
default_strategy.__index = default_strategy
2023-03-25 09:41:06 +08:00
g_strategy.default = nil
2023-03-25 09:41:06 +08:00
setmetatable(g_strategy, {
__index = function()
return default_strategy
2023-03-24 00:56:36 +08:00
end,
})
2023-03-12 09:56:31 +08:00
2023-03-25 09:41:06 +08:00
for _, strategy in pairs(g_strategy) do
strategy.backend = parse_backend(strategy.backend)
setmetatable(strategy, default_strategy)
2023-03-11 11:32:13 +08:00
end
end
2023-03-12 09:56:31 +08:00
2023-03-11 11:32:13 +08:00
local function define_highlights(conf)
2023-03-12 09:56:31 +08:00
local set_hl = vim.api.nvim_set_hl
local highlights = Trans.style.theme[conf.theme]
2023-03-11 11:32:13 +08:00
for hl, opt in pairs(highlights) do
set_hl(0, hl, opt)
end
end
2023-03-12 21:33:00 +08:00
2023-03-14 18:17:07 +08:00
---@class Trans
---@field setup fun(opts: { mode: string, mode: string })
2023-03-09 19:42:41 +08:00
return function(opts)
if opts then
Trans.conf = vim.tbl_deep_extend('force', Trans.conf, opts)
2023-03-09 19:42:41 +08:00
end
local conf = Trans.conf
2023-03-12 09:56:31 +08:00
conf.dir = vim.fn.expand(conf.dir)
2023-03-12 09:56:31 +08:00
set_strategy_opts(conf)
2023-03-11 11:32:13 +08:00
define_highlights(conf)
2023-04-07 19:57:52 +08:00
if Trans.conf.warning then
vim.notify([[
v2已经发布, :
https://github.com/JuanZoran/Trans.nvim
使(v2)
]], vim.log.levels.WARN)
end
2023-03-09 19:42:41 +08:00
end