-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui,notifications: add a module which creates a notification popup
this commit adds a lua module for generating a notification popup. wired into the async symbol gather function so users get an idea that work is being done instead of just waiting for the calltree to open. Signed-off-by: ldelossa <[email protected]>
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
local M = {} | ||
|
||
local float_wins = {} | ||
|
||
function M.close_notify_popup() | ||
for _, float_win in ipairs(float_wins) do | ||
if vim.api.nvim_win_is_valid(float_win) then | ||
vim.api.nvim_win_close(float_win, true) | ||
end | ||
end | ||
float_wins = nil | ||
end | ||
|
||
function M.notify_popup(text) | ||
if float_wins == nil then | ||
float_wins = {} | ||
end | ||
|
||
local buf = vim.api.nvim_create_buf(false, true) | ||
if buf == 0 then | ||
vim.api.nvim_err_writeln("details_popup: could not create details buffer") | ||
return | ||
end | ||
vim.api.nvim_buf_set_option(buf, 'bufhidden', 'delete') | ||
vim.api.nvim_buf_set_option(buf, 'syntax', 'yaml') | ||
|
||
local lines = {text} | ||
local width = 20 | ||
local line_width = vim.fn.strdisplaywidth(text) | ||
if line_width > width then | ||
width = line_width | ||
end | ||
|
||
vim.api.nvim_buf_set_option(buf, 'modifiable', true) | ||
vim.api.nvim_buf_set_lines(buf, 0, #lines, false, lines) | ||
vim.api.nvim_buf_set_option(buf, 'modifiable', false) | ||
local popup_conf = { | ||
relative = "win", | ||
anchor = "SE", | ||
width = width, | ||
height = 1, | ||
focusable = false, | ||
zindex = 99, | ||
style = "minimal", | ||
border = "rounded", | ||
bufpos = {999999999, -1} | ||
} | ||
table.insert(float_wins, vim.api.nvim_open_win(buf, false, popup_conf)) | ||
end | ||
|
||
return M |