Skip to content

Instantly share code, notes, and snippets.

@seandewar
Created May 17, 2024 08:45
Show Gist options
  • Save seandewar/bbbf6f276f980c091e22801c0db9656c to your computer and use it in GitHub Desktop.
Save seandewar/bbbf6f276f980c091e22801c0db9656c to your computer and use it in GitHub Desktop.
Are deprecation messages in Neovim too annoying? Then enhance them with this little script!
local 🏷️ πŸͺ = vim.api.nvim_create_namespace('depreCATE')
vim.deprecate = function(name, alternative, version, plugin, backtrace)
local lines = {
"",
"🚨 πŸ§πŸ“£ W A R N I N G ! ! ! ! 🚨",
"",
"",
"😱 " .. name .. " IS DEPRECATED!!!! 😱",
"",
"IT WILL BE REMOVED IN " .. (plugin or "NVIM") .. " VERSION " .. version .. "!",
"",
}
if backtrace == nil or backtrace then
vim.list_extend(lines, vim.split(debug.traceback('', 2):sub(2), "\n"))
lines[#lines + 1] = ""
end
local w = vim.iter(lines):fold(0, function(acc, l)
return math.max(acc, #l)
end)
local h = #lines
vim.schedule(function()
local b = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(b, 0, -1, true, lines)
for i = 1, math.random(1, 1) do
local x = math.random(1, vim.o.columns - w - 3)
local y = math.random(1, vim.o.lines - h - vim.o.cmdheight - 3)
local πŸͺŸ = vim.api.nvim_open_win(b, true, {
relative = "editor",
row = y,
col = x,
width = w,
height = h,
border = "rounded",
zindex = 9001,
style = "minimal",
})
vim.wo[πŸͺŸ].winfixbuf=true
vim.api.nvim_win_set_hl_ns(πŸͺŸ, 🏷️ πŸͺ)
vim.api.nvim_set_hl(🏷️ πŸͺ, 'FloatBorder', {link = 'NormalFloat'})
local ⏰ = vim.uv.new_timer()
local 🚨 = false
⏰:start(0, 250, vim.schedule_wrap(function()
if not vim.api.nvim_win_is_valid(πŸͺŸ) then
return
end
🚨 = not 🚨
vim.api.nvim_set_hl(🏷️ πŸͺ, 'NormalFloat', {bg = 🚨 and '#ff0000' or '#ffff00', ctermbg = 🚨 and 'red' or 'yellow',
fg = 🚨 and '#ffffff' or '#000000', ctermfg = 🚨 and 'white' or 'black'})
vim.api.nvim__redraw({win = πŸͺŸ, valid = false})
end))
local ⏰2 = vim.uv.new_timer()
local vx = math.random(2) == 1 and 1 or -1
local vy = math.random(2) == 1 and 1 or -1
⏰2:start(0, 50, vim.schedule_wrap(function()
if not vim.api.nvim_win_is_valid(πŸͺŸ) then
return
end
x = x + vx
if x <= 1 or x >= vim.o.columns - w - 2 then
vx = -vx
end
y = y + vy
if y <= 1 or y >= vim.o.lines - h - vim.o.cmdheight - 2 then
vy = -vy
end
vim.api.nvim_win_set_config(πŸͺŸ, {relative='editor',row = y, col = x})
end))
vim.api.nvim_create_autocmd('WinClosed', {pattern = tostring(πŸͺŸ), callback = function()
⏰:stop()
⏰:close()
⏰2:stop()
⏰2:close()
end})
end
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment