mirror of
https://github.com/jiriks74/presence.nvim
synced 2025-06-19 19:38:57 +02:00
Allow cancelling presence on remote nvim instances
- Add msgpack lib - Restructure to have lib and deps folders - Add cancellation methods and invoke remote cancellation on update
This commit is contained in:
parent
42f6c79eb0
commit
66bd159dd3
5 changed files with 602 additions and 3 deletions
lua/lib
48
lua/lib/log.lua
Normal file
48
lua/lib/log.lua
Normal file
|
@ -0,0 +1,48 @@
|
|||
local Log = {}
|
||||
|
||||
Log.codes = {}
|
||||
|
||||
Log.levels = {
|
||||
{ "debug", "Comment" },
|
||||
{ "info", "None" },
|
||||
{ "warn", "WarningMsg" },
|
||||
{ "error", "ErrorMsg" },
|
||||
}
|
||||
|
||||
function Log.new(options)
|
||||
options = options or {}
|
||||
|
||||
local logger = vim.deepcopy(Log)
|
||||
logger.options = options
|
||||
logger.options.level = options.level
|
||||
|
||||
return logger
|
||||
end
|
||||
|
||||
setmetatable(Log, {
|
||||
__call = function(_, ...)
|
||||
return Log.new(...)
|
||||
end,
|
||||
})
|
||||
|
||||
-- Initialize logger with log functions for each level
|
||||
for i = 1, #Log.levels do
|
||||
local level, hl = unpack(Log.levels[i])
|
||||
|
||||
Log.codes[level] = i
|
||||
|
||||
Log[level] = function(self, message)
|
||||
-- Skip if log level is not set or the log is below the configured or default level
|
||||
if not self.options.level or self.codes[level] < self.codes[self.options.level] then
|
||||
return
|
||||
end
|
||||
|
||||
vim.schedule(function()
|
||||
vim.cmd(string.format("echohl %s", hl))
|
||||
vim.cmd(string.format([[echom "[%s] %s"]], "presence.nvim", vim.fn.escape(message, '"')))
|
||||
vim.cmd("echohl NONE")
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
return Log
|
Loading…
Add table
Add a link
Reference in a new issue