From e59bfe0338dbe7294c131862cc44698059db6fae Mon Sep 17 00:00:00 2001 From: fm39hz-laptop Date: Tue, 4 Jun 2024 17:12:31 +0700 Subject: [PATCH] feat: add preview image method --- lua/plugins/override.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lua/plugins/override.lua b/lua/plugins/override.lua index a3cf2e1..d68ad42 100644 --- a/lua/plugins/override.lua +++ b/lua/plugins/override.lua @@ -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, + }, + }, + }, + }, }