-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.lua
More file actions
50 lines (41 loc) · 1.49 KB
/
menu.lua
File metadata and controls
50 lines (41 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local M = {}
local win_id
local content
function M.createPopup()
local input = vim.fn.input("Enter your query: ")
local bufnr = vim.api.nvim_create_buf(false, true)
local handle = io.popen('python3 /mnt/c/Users/KIIT/Desktop/courses/ai/luna/spicefy/neovim-spotify/songnamefinder.py "' .. input .. '"')
local result = handle:read("*a")
handle:close()
-- Convert the JSON string to Lua table
content = vim.fn.json_decode(result)
local max_width = 60
win_id = vim.api.nvim_open_win(bufnr, true, {
relative = 'editor',
width = max_width + 2,
height = #content + 2,
style = 'minimal',
border = 'single',
row = vim.fn.line('.') + 1,
col = vim.fn.wincol() + 1,
})
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, content)
vim.api.nvim_buf_set_keymap(bufnr, "n", "q", "<cmd>lua require('menu').close()<CR>", { silent = true })
vim.api.nvim_buf_set_keymap(bufnr, "n", "<CR>", ":lua require('menu').executeOption()<CR>", { silent = true })
end
function M.executeOption()
local line = vim.fn.line('.')
local option = content[line]
if option then
os.execute("python3 /mnt/c/Users/KIIT/Desktop/courses/ai/luna/spicefy/neovim-spotify/spotify.py " .. vim.fn.shellescape(option))
else
print("Invalid option")
end
end
function M.close()
if win_id and vim.api.nvim_win_is_valid(win_id) then
pcall(vim.api.nvim_win_close, win_id, true)
win_id = nil
end
end
return M