-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Show popup message as reminder, clears after x seconds (#5)
- Loading branch information
Showing
5 changed files
with
55 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
local M = {} | ||
|
||
--- Create a simple popup message, positioned in the bottom right corner of the buffer | ||
--- Automatically close this popup after 5 seconds | ||
--- Courtersy of encourage.nvim | ||
---@param message string | ||
---@return nil | ||
function M.show(message) | ||
local width = #message | ||
local height = 1 | ||
local buf = vim.api.nvim_create_buf(false, true) | ||
local current_win = vim.api.nvim_get_current_win() | ||
local win_config = vim.api.nvim_win_get_config(current_win) | ||
local win_width = win_config.width | ||
local win_height = win_config.height | ||
|
||
local opts = { | ||
style = "minimal", | ||
relative = "win", | ||
win = current_win, | ||
width = width, | ||
height = height, | ||
row = win_height - height - 2, | ||
col = win_width - width - 2, | ||
border = "rounded", | ||
} | ||
|
||
local win = vim.api.nvim_open_win(buf, false, opts) | ||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { message }) | ||
vim.api.nvim_win_set_option(win, "winhl", "Normal:NormalFloat,FloatBorder:FloatBorder") | ||
|
||
vim.defer_fn(function() | ||
if vim.api.nvim_win_is_valid(win) then | ||
vim.api.nvim_win_close(win, true) | ||
end | ||
end, 5000) | ||
end | ||
|
||
return M |
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