diff options
Diffstat (limited to 'lua/alpha/telescope')
| -rw-r--r-- | lua/alpha/telescope/init.lua | 14 | ||||
| -rw-r--r-- | lua/alpha/telescope/my_actions.lua (renamed from lua/alpha/telescope/actions.lua) | 0 | ||||
| -rw-r--r-- | lua/alpha/telescope/setup.lua | 52 |
3 files changed, 58 insertions, 8 deletions
diff --git a/lua/alpha/telescope/init.lua b/lua/alpha/telescope/init.lua index 38cd9be..c278028 100644 --- a/lua/alpha/telescope/init.lua +++ b/lua/alpha/telescope/init.lua @@ -1,16 +1,16 @@ -SHOULD_RELOAD_TELESCOPE = true +local SHOULD_RELOAD_TELESCOPE = true local reloader = function() if SHOULD_RELOAD_TELESCOPE then - RELOAD "plenary" - RELOAD "telescope" - RELOAD "alpha.telescope.setup" + Reload "plenary" + Reload "telescope" + Reload "alpha.telescope.setup" end end local fb_actions = require("telescope").extensions.file_browser.actions local actions = require "telescope.actions" -local my_actions = require "alpha.telescope.actions" +local my_actions = require "alpha.telescope.my_actions" local M = {} @@ -52,8 +52,8 @@ M.find_nvim_plugin = function() prompt_title = "< Plugins >", cwd = "$HOME/.config/nvim/lua/plugins/", attach_mappings = function(_, map) - map("i", "<C-t>", my_actions.create_plugin) - map("i", "<C-d>", my_actions.disable_plugin) + map("i", "<C-y>", my_actions.create_plugin) + map("i", "<C-w>", my_actions.disable_plugin) map("i", "<C-e>", my_actions.enable_plugin) return true diff --git a/lua/alpha/telescope/actions.lua b/lua/alpha/telescope/my_actions.lua index b0e9f10..b0e9f10 100644 --- a/lua/alpha/telescope/actions.lua +++ b/lua/alpha/telescope/my_actions.lua diff --git a/lua/alpha/telescope/setup.lua b/lua/alpha/telescope/setup.lua index cd5ad63..0e368c7 100644 --- a/lua/alpha/telescope/setup.lua +++ b/lua/alpha/telescope/setup.lua @@ -11,8 +11,57 @@ local set_prompt_to_entry_value = function(prompt_bufnr) action_state.get_current_picker(prompt_bufnr):reset_prompt(entry.ordinal) end +local filetype_hook = function(filepath, bufnr, opts) + -- Here for example you can say: if ft == "xyz" then this_regex_highlighing else nothing end + -- + local is_image = function(filepath) + local image_extensions = { "png", "jpg" } -- Supported image formats + local split_path = vim.split(filepath:lower(), ".", { plain = true }) + local extension = split_path[#split_path] + return vim.tbl_contains(image_extensions, extension) + end + if not is_image(filepath) then + return true + end + local ui = require "image.ui" + local options = require "image.options" + local dimensions = require "image.dimensions" + local api = require "image.api" + local config = require "image.config" + local user_opts = { + render = { + foreground_color = true, + background_color = true, + }, + } + local global_opts = vim.tbl_deep_extend("force", config.DEFAULT_OPTS, user_opts) + + local ascii_width, ascii_height, horizontal_padding, vertical_padding, img_width, img_height = + dimensions.calculate_ascii_width_height(opts.winid, filepath, global_opts) + options.set_options_before_render(bufnr) + ui.buf_clear(bufnr) + local label = ui.create_label( + filepath, + ascii_width, + horizontal_padding, + global_opts.render.show_image_dimensions, + img_width, + img_height + ) + + api.get_ascii_data_sync(filepath, ascii_width, ascii_height, global_opts, function(ascii_data) + ui.buf_insert_data_with_padding(bufnr, ascii_data, horizontal_padding, vertical_padding, label, global_opts) + + options.set_options_after_render(bufnr) + end) + return false +end + require("telescope").setup { defaults = { + preview = { + filetype_hook = filetype_hook, + }, prompt_prefix = "❯ ", selection_caret = "❯ ", @@ -30,7 +79,7 @@ require("telescope").setup { if cols > 200 then return math.floor(cols * 0.5) else - return math.floor(cols * 0.6) + return math.floor(cols * 0.7) end end, }, @@ -100,6 +149,7 @@ require("telescope").setup { path = "~/.local/share/nvim/databases/telescope_history.sqlite3", limit = 100, }, + -- buffer_previewer_maker = new_maker, }, pickers = { |