Skip to content

Commit b120dbc

Browse files
committed
wip
1 parent de3ee92 commit b120dbc

File tree

9 files changed

+459
-0
lines changed

9 files changed

+459
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
luacov.*.out
44

55
.tests
6+
7+
scratch/

.luarc.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
return {
2+
nvim = {
3+
packages = { "plenary.nvim" },
4+
},
5+
}

.prettierrc

Whitespace-only changes.

lua/nui/.DS_Store

6 KB
Binary file not shown.

test.lua

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
for pkg_name in pairs(package.loaded) do
2+
if pkg_name:match("^nui") then
3+
package.loaded[pkg_name] = nil
4+
end
5+
end
6+
7+
local Popup = require("nui.popup")
8+
local Input = require("nui.input")
9+
local Layout = require("nui.layout")
10+
11+
local popup = Popup({
12+
enter = false,
13+
focusable = true,
14+
})
15+
16+
local input = Input({}, {
17+
prompt = "> ",
18+
default_value = "Hello",
19+
on_close = function()
20+
print("Input Closed!")
21+
end,
22+
on_submit = function(value)
23+
print("Input Submitted: " .. value)
24+
end,
25+
})
26+
27+
local layout = Layout(
28+
{
29+
position = "50%",
30+
size = {
31+
width = 100,
32+
height = "40%",
33+
},
34+
},
35+
Layout.Box({
36+
Layout.Box(popup, { size = "80%" }),
37+
Layout.Box(input, { size = "20%" }),
38+
}, { dir = "col" })
39+
)
40+
41+
layout:mount()

test_input.lua

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
for name in pairs(package.loaded) do
2+
if name:find("^nui") then
3+
package.loaded[name] = nil
4+
end
5+
end
6+
7+
local Input = require("nui.input")
8+
local event = require("nui.utils.autocmd").event
9+
10+
local prompt_msg = "Close current file?"
11+
12+
local bufnr = vim.api.nvim_get_current_buf()
13+
14+
local input = Input({
15+
position = "50%",
16+
size = {
17+
width = #prompt_msg + 4,
18+
},
19+
border = {
20+
style = "single",
21+
text = {
22+
top = prompt_msg,
23+
top_align = "center",
24+
},
25+
},
26+
win_options = {
27+
winhighlight = "Normal:Normal,FloatBorder:Normal",
28+
},
29+
}, {
30+
prompt = "> ",
31+
default_value = "N",
32+
on_close = function()
33+
print("Input Closed!")
34+
end,
35+
on_submit = function(value)
36+
print("START - on_submit")
37+
if value:lower() == "y" then
38+
vim.api.nvim_buf_delete(bufnr, { force = true })
39+
end
40+
print("END - on_submit")
41+
end,
42+
})
43+
44+
input:mount()
45+
46+
input:on(event.BufLeave, function()
47+
input:unmount()
48+
end)

test_layout.lua

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
for pkg_name in pairs(package.loaded) do
2+
if pkg_name:match("^nui") then
3+
package.loaded[pkg_name] = nil
4+
end
5+
end
6+
7+
local Layout = require("nui.layout")
8+
local Popup = require("nui.popup")
9+
local Menu = require("nui.menu")
10+
11+
local popup = {
12+
a = Popup({ border = "single" }),
13+
b = Popup({ border = "single" }),
14+
c = Popup({ border = "single", focusable = false }),
15+
}
16+
17+
local menu = {
18+
a = Menu({ border = "single" }, {
19+
lines = {
20+
Menu.separator("Group One"),
21+
Menu.item("Item 1"),
22+
Menu.item("Item 2"),
23+
Menu.separator("Group Two", {
24+
char = "-",
25+
text_align = "right",
26+
}),
27+
Menu.item("Item 3"),
28+
Menu.item("Item 4"),
29+
},
30+
keymap = {
31+
focus_next = { "j", "<Down>", "<Tab>" },
32+
focus_prev = { "k", "<Up>", "<S-Tab>" },
33+
close = { "<Esc>", "<C-c>" },
34+
submit = { "<CR>", "<Space>" },
35+
},
36+
on_close = function()
37+
print("CLOSED")
38+
end,
39+
on_submit = function(item)
40+
print("SUBMITTED", vim.inspect(item))
41+
end,
42+
}),
43+
}
44+
45+
local layout = Layout(
46+
{
47+
relative = "editor",
48+
position = "50%",
49+
size = { height = 10, width = 60 },
50+
},
51+
Layout.Box({
52+
Layout.Box(popup.a, { grow = 1 }),
53+
Layout.Box(menu.a, { grow = 1 }),
54+
}, { dir = "row" })
55+
)
56+
57+
_G.l = layout
58+
_G.p = popup
59+
60+
for _, p in pairs(popup) do
61+
p:on("BufLeave", function()
62+
vim.schedule(function()
63+
local bufnr = vim.api.nvim_get_current_buf()
64+
for _, lp in pairs(popup) do
65+
if lp.bufnr == bufnr then
66+
return
67+
end
68+
end
69+
layout:unmount()
70+
end)
71+
end)
72+
end
73+
74+
layout:mount()
75+
76+
-- vim.api.nvim_set_current_win(popup.a.winid)

0 commit comments

Comments
 (0)