1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:10:04 +08:00

perf(a.lua): use lua notify api

This commit is contained in:
wsdjeg 2023-06-24 21:55:10 +08:00
parent ae7f1da0f3
commit 47bfdd06ca
2 changed files with 12 additions and 7 deletions

View File

@ -36,6 +36,7 @@ M.winblend = 0
M.timeout = 3000
M.hashkey = ''
M.config = {}
M.notification_color = 'Normal'
---@param msg string|table<string> notification messages
---@param opts table notify options
@ -50,7 +51,11 @@ function M.notify(msg, opts) -- {{{
if M.notify_max_width == 0 then
M.notify_max_width = vim.o.columns * 0.35
end
M.notification_color = opts.color or 'Normal'
if type(opts) == 'string' then
M.notification_color = opts
elseif type(opts) == 'table' then
M.notification_color = opts.color or 'Normal'
end
if empty(M.hashkey) then
M.hashkey = M.__password.generate_simple(10)
end
@ -238,8 +243,11 @@ function M.close(...) -- {{{
end
if #M.message == 0 then
if M.win_is_open() then
local ei = vim.o.eventignore
vim.o.eventignore = 'all'
vim.api.nvim_win_close(M.border.winid, true)
vim.api.nvim_win_close(M.winid, true)
vim.o.eventignore = ei
end
if notifications[M.hashkey] then
notifications[M.hashkey] = nil

View File

@ -15,6 +15,7 @@ local sp_opt = require('spacevim.opt')
local sp_json = require('spacevim.api').import('data.json')
local logger = require('spacevim.logger').derive('a.lua')
local fn = vim.fn or require('spacevim').fn
local nt = require('spacevim.api').import('notify')
local alternate_conf = {}
alternate_conf['_'] = '.project_alt.json'
@ -62,9 +63,7 @@ function M.alt(request_parse, ...)
if fn.exists('b:alternate_file_config') ~= 1 then
local conf_file_path = M.getConfigPath()
if vim.fn.filereadable(conf_file_path) ~= 1 then
vim.api.nvim_eval(
'SpaceVim#api#notify#get().notify("no alternate config file!", "WarningMsg")'
)
nt.notify('no alternate config file!', 'WarningMsg')
return
end
local file = sp_file.unify_path(fn.bufname('%'), ':.')
@ -74,9 +73,7 @@ function M.alt(request_parse, ...)
if alt ~= nil and alt ~= '' then
cmd('e ' .. alt)
else
vim.api.nvim_eval(
'SpaceVim#api#notify#get().notify("failed to find alternate file!", "WarningMsg")'
)
nt.notify('failed to find alternate file!', 'WarningMsg')
end
end