feat: add snacks.picker support

This commit is contained in:
Kristofers Solo 2025-10-08 18:57:23 +03:00 committed by Barrett Ruth
parent 6ff6a63598
commit 67beb093c5
2 changed files with 42 additions and 3 deletions

35
lua/http-codes/snacks.lua Normal file
View 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,
}