-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Close #33 fix: default prompt border highlight * docs: improve command formatting * docs: Add highlights options * Close #45 - fix: unmount nui prompt correctly
- Loading branch information
Showing
3 changed files
with
47 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,63 @@ | ||
-- UI module for creating the nui.nvim input popup | ||
-- Author: Anexon <[email protected]> | ||
-- Description: UI module for creating the prompt with nui.nvim input popup. | ||
|
||
local Input = require('nui.input') | ||
local Event = require('nui.utils.autocmd').event | ||
|
||
local UI = {} | ||
|
||
-- TODO: Expose option configuration. | ||
local opts = { | ||
default_value = '', | ||
winblend = 0, | ||
style = 'rounded' | ||
} | ||
|
||
-- Prompts the user for input. | ||
--- @param title string The title of the prompt. | ||
--- @param on_submit function The function to call when the user submits the prompt. | ||
function UI.prompt(title, on_submit) | ||
-- TODO: Make escape keys configurable. | ||
local exit_keys = { | ||
{'n', 'q', | ||
function(_) | ||
vim.api.nvim_command(':q') | ||
end, {noremap = true}, | ||
}, | ||
{'n', '<ESC>', | ||
function(_) | ||
vim.api.nvim_command(':q') | ||
end, {noremap = true}, | ||
}, | ||
{'i', '<ESC>', | ||
function(_) | ||
vim.api.nvim_command(':q') | ||
end, {noremap = true}, | ||
}, | ||
{'i', '<C-c>', | ||
function(_) | ||
vim.api.nvim_command(':q') | ||
end, {noremap = true}, | ||
}, | ||
} | ||
|
||
-- TODO: Make prompt more configurable. | ||
local input = Input({ | ||
position = {row = '85.2%', col = '50%'}, | ||
size = { | ||
width = '51.8%', | ||
height = '20%', | ||
}, | ||
size = { width = '51.8%', height = '20%'}, | ||
relative = 'editor', | ||
border = { | ||
highlight = 'NeuralPromptBorder', | ||
style = 'rounded', | ||
style = opts.style, | ||
text = { | ||
top = title, | ||
top_align = 'center', | ||
}, | ||
}, | ||
win_options = { | ||
winblend = 10, | ||
winhighlight = 'Normal:Normal', | ||
winblend = opts.winblend, | ||
}, | ||
}, { | ||
prompt = vim.g.neural.ui.prompt_icon .. ' ', | ||
default_value = '', | ||
default_value = opts.default_value, | ||
on_close = function() end, | ||
on_submit = function(value) | ||
on_submit(value) | ||
end, | ||
}) | ||
input:mount() | ||
|
||
-- Handle unmounting | ||
input:on(Event.BufLeave, function() | ||
input:unmount() | ||
end) | ||
for _, v in ipairs(exit_keys) do | ||
input:map(unpack(v)) | ||
|
||
local exit_keys = { | ||
{'n', 'q'}, | ||
{'n', '<ESC>'}, | ||
{'i', '<ESC>'}, | ||
{'n', '<C-c>'}, | ||
{'i', '<C-c>'}, | ||
} | ||
for _, key in ipairs(exit_keys) do | ||
input:map(key[1], key[2], function() | ||
input:unmount() | ||
end, { noremap = true }) | ||
end | ||
end | ||
|
||
|