Neovim library for popup utilities written in Lua
- This library has been developed on and for Linux following open source philosophy.
Packer
use 'javiorfo/nvim-popcorn'
Lazy
{ 'javiorfo/nvim-popcorn' }
Feature | nvim-popcorn | NOTE |
---|---|---|
Popup borders | ✔️ | Includes 5 different borders (also opened to implementation) |
Set width and height | ✔️ | |
Set title | ✔️ | Optional. Centered with highlighting options |
Set footer | ✔️ | Optional. Centered with highlighting options |
Title or footer with right or left align | ❌ | |
Backgroung color | ❌ | Same of editor |
Content in text format | ✔️ | By table. With highlighting options |
Content file | ✔️ | By string |
Content open to implementation | ✔️ | By function |
Callback | ✔️ | Optional. By function |
Close popup | ✔️ | Pressing or Clicking outside of it |
- This is an object description. Notice that some values are required and others are optional:
local popcorn = require'popcorn'
local borders = require'popcorn.borders'
local opts = {
-- Required
width = 50,
-- Required
height = 8,
-- Optional. If not set then simple_thick_border will be the default
border = borders.rounded_corners_border,
-- Optional. The first table value is the title text, the second one is the group to link
-- The second value is optional too. In this case It will highlight "Popcorn Title" linking to "Type" group
title = { "Popcorn Title", "Type" },
-- Optional. The first table value is the footer text, the second one is the group to link
-- The second value is optional too. In this case It will highlight "Popcorn Footer" linking to "String" group
footer = { "Popcorn Footer", "String" },
-- Optional. This will be the body of the popup
-- content is a table
content = {
{ "Results: ", "Constant" }, -- The second value is the group to link to
{ " - Some text here" },
{ " - More text here" }
},
-- Optional. A second approach could be to open a file and show the content in the popup body
-- content is a string
-- content = "path/to/file/to/show/file.txt"
-- Optional. A third approach could be to implement some code in a function
-- content is a function
-- In this example a terminal is opened in the popup body
-- content = function() vim.cmd("start | term") end
-- Optional. If a callback is necessary this is the keymap to execute it
-- Default value is <CR> if this variable is not set
callback_keymap = "<CR>",
-- Optional. If a callback is necessary this is the implementation
-- Pressing <CR> (variable above) will execute the callback
-- In this example It will print the first line of the popup body
callback = function()
print("Callback result => " .. vim.fn.getline(1))
end,
-- Optional
-- Add some actions after all the popup configuration is set
-- I could be autocmd's for example
do_after = function()
-- do something after...
end
}
-- Open popup
popcorn:new(opts):pop() -- pop() returns popup buffer id
- Check the borders available in this file
- You can add your own border if you like. Further information in
:help popcorn
Examples of the differents popup's included in this library. Run :luafile %
in these files
NOTE: The colorscheme umbra from nvim-nyctophilia is used in this image.