-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
80 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,60 @@ | ||
local notify_ok, nvim_notify = pcall(require, "notify") | ||
|
||
local PLUGIN_NAME = notify_ok and "Jupynium" or "Jupynium" | ||
|
||
Jupynium_notify = {} | ||
|
||
---Wraper for vim.notify and nvim-notify | ||
---@param msg table | ||
---@param msg string[] | ||
---@param level number vim.levels[level] | ||
---@vararg string Strings for substitute | ||
Jupynium_notify.notify = function(msg, level) | ||
---@param code string? | ||
Jupynium_notify.notify = function(msg, level, code) | ||
level = level or vim.log.levels.INFO | ||
|
||
if code ~= nil and vim.g.jupynium_notify_ignore_codes[code] then | ||
return | ||
end | ||
|
||
local title | ||
if code ~= nil then | ||
title = ("Jupynium [%s]"):format(code) | ||
else | ||
title = "Jupynium" | ||
end | ||
|
||
if notify_ok then | ||
-- Make it possible to use newline within the message table | ||
lines = {} | ||
local lines = {} | ||
for _, str in ipairs(msg) do | ||
for s in str:gmatch "[^\r\n]+" do | ||
table.insert(lines, s) | ||
end | ||
end | ||
|
||
nvim_notify(lines, level, { | ||
title = PLUGIN_NAME, | ||
title = title, | ||
on_open = function(win) | ||
local buf = vim.api.nvim_win_get_buf(win) | ||
vim.api.nvim_buf_set_option(buf, "filetype", "markdown") | ||
vim.bo[buf].filetype = "markdown" | ||
end, | ||
}) | ||
else | ||
vim.notify(("[%s]: %s"):format(PLUGIN_NAME, table.concat(msg, " ")), level) | ||
vim.notify(("%s: %s"):format(title, table.concat(msg, " ")), level) | ||
end | ||
end | ||
|
||
Jupynium_notify.error = function(msg) | ||
Jupynium_notify.notify(msg, vim.log.levels.ERROR) | ||
---@param msg string[] | ||
---@param code string? | ||
Jupynium_notify.error = function(msg, code) | ||
Jupynium_notify.notify(msg, vim.log.levels.ERROR, code) | ||
end | ||
|
||
Jupynium_notify.warn = function(msg) | ||
Jupynium_notify.notify(msg, vim.log.levels.WARN) | ||
---@param msg string[] | ||
---@param code string? | ||
Jupynium_notify.warn = function(msg, code) | ||
Jupynium_notify.notify(msg, vim.log.levels.WARN, code) | ||
end | ||
|
||
Jupynium_notify.info = function(msg) | ||
Jupynium_notify.notify(msg, vim.log.levels.INFO) | ||
---@param msg string[] | ||
---@param code string? | ||
Jupynium_notify.info = function(msg, code) | ||
Jupynium_notify.notify(msg, vim.log.levels.INFO, code) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters