feat: add preview image method

pull/99/head
fm39hz-laptop 2024-06-04 17:12:31 +07:00
parent 6ff761b0c1
commit a314ae7dfa
1 changed files with 32 additions and 0 deletions

View File

@ -140,4 +140,36 @@ return {
},
},
},
{
"nvim-telescope/telescope.nvim",
opts = {
defaults = {
preview = {
mime_hook = function(filepath, bufnr, opts)
local is_image = function(_filepath)
local image_extensions = { "png", "jpg" }
local split_path = vim.split(_filepath:lower(), ".", { plain = true })
local extension = split_path[#split_path]
return vim.tbl_contains(image_extensions, extension)
end
if is_image(filepath) then
local term = vim.api.nvim_open_term(bufnr, {})
local function send_output(_, data, _)
for _, d in ipairs(data) do
vim.api.nvim_chan_send(term, d .. "\r\n")
end
end
vim.fn.jobstart({
"kitten",
"icat",
filepath,
}, { on_stdout = send_output, stdout_buffered = true, pty = true })
else
require("telescope.previewers.utils").set_preview_message(bufnr, opts.winid, "Binary cannot be previewed")
end
end,
},
},
},
},
}