feat: add snacks.picker support
This commit is contained in:
parent
6ff6a63598
commit
67beb093c5
2 changed files with 42 additions and 3 deletions
|
|
@ -24,19 +24,21 @@ local function init()
|
||||||
if not config.use then
|
if not config.use then
|
||||||
if pcall(require, 'fzf-lua') then
|
if pcall(require, 'fzf-lua') then
|
||||||
config.use = 'fzf-lua'
|
config.use = 'fzf-lua'
|
||||||
|
elseif pcall(require, 'snacks') then
|
||||||
|
config.use = 'snacks'
|
||||||
elseif pcall(require, 'telescope') then
|
elseif pcall(require, 'telescope') then
|
||||||
config.use = 'telescope'
|
config.use = 'telescope'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not config.use then
|
if not config.use then
|
||||||
vim.notify_once('http-codes.nvim: install fzf-lua or telescope.nvim', vim.log.levels.ERROR)
|
vim.notify_once('http-codes.nvim: install fzf-lua, snacks.nvim, or telescope.nvim', vim.log.levels.ERROR)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if not vim.tbl_contains({ 'fzf-lua', 'telescope' }, config.use) then
|
if not vim.tbl_contains({ 'fzf-lua', 'snacks', 'telescope' }, config.use) then
|
||||||
vim.notify_once(
|
vim.notify_once(
|
||||||
"http-codes.nvim: 'use' must be 'fzf-lua' or 'telescope'",
|
"http-codes.nvim: 'use' must be 'fzf-lua', 'snacks', or 'telescope'",
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.ERROR
|
||||||
)
|
)
|
||||||
return false
|
return false
|
||||||
|
|
@ -59,6 +61,8 @@ function M.pick()
|
||||||
require('telescope').extensions.http.list(config.open_url)
|
require('telescope').extensions.http.list(config.open_url)
|
||||||
elseif config.use == 'fzf-lua' then
|
elseif config.use == 'fzf-lua' then
|
||||||
require('http-codes.fzf-lua').pick(config.open_url)
|
require('http-codes.fzf-lua').pick(config.open_url)
|
||||||
|
elseif config.use == 'snacks' then
|
||||||
|
require('http-codes.snacks').pick(config.open_url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
35
lua/http-codes/snacks.lua
Normal file
35
lua/http-codes/snacks.lua
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
local codes = require 'http-codes.codes'
|
||||||
|
local cached_items = nil
|
||||||
|
|
||||||
|
local function codes_to_snack_items(codes)
|
||||||
|
if cached_items then return cached_items end
|
||||||
|
|
||||||
|
local items = {}
|
||||||
|
|
||||||
|
local idx = 1
|
||||||
|
for status, _ in pairs(codes) do
|
||||||
|
table.insert(items, { idx = idx, text = status })
|
||||||
|
idx = idx + 1
|
||||||
|
end
|
||||||
|
cached_items = items
|
||||||
|
return items
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
pick = function(open_url)
|
||||||
|
require('snacks.picker').pick(nil, {
|
||||||
|
title = 'HTTP Codes',
|
||||||
|
items = codes_to_snack_items(codes),
|
||||||
|
format = 'text',
|
||||||
|
layout = {
|
||||||
|
preset = 'select',
|
||||||
|
hidden = { 'preview' },
|
||||||
|
},
|
||||||
|
confirm = function(picker, item)
|
||||||
|
local link = codes[item.text]
|
||||||
|
picker:close()
|
||||||
|
vim.fn.jobstart(open_url:format(link))
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue