|
|
|
@ -4,31 +4,30 @@ local utils = require "fzf-lua.utils"
|
|
|
|
|
local config = require "fzf-lua.config"
|
|
|
|
|
local actions = require "fzf-lua.actions"
|
|
|
|
|
local win = require "fzf-lua.win"
|
|
|
|
|
local string_byte = string.byte
|
|
|
|
|
local string_byte_a = string_byte("a")
|
|
|
|
|
local string_byte_z = string_byte("z")
|
|
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
|
|
M.fzf = function(opts, contents, previewer)
|
|
|
|
|
M.fzf = function(opts, contents)
|
|
|
|
|
-- setup the fzf window and preview layout
|
|
|
|
|
local fzf_win = win(opts)
|
|
|
|
|
-- instantiate the previewer
|
|
|
|
|
-- if not opts.preview and not previewer and
|
|
|
|
|
if not previewer and
|
|
|
|
|
opts.previewer and type(opts.previewer) == 'string' then
|
|
|
|
|
local preview_opts = config.globals.previewers[opts.previewer]
|
|
|
|
|
if preview_opts then
|
|
|
|
|
previewer = preview_opts._new()(preview_opts, opts, fzf_win)
|
|
|
|
|
opts.preview = previewer:cmdline()
|
|
|
|
|
if type(previewer.override_fzf_preview_window) == 'function' then
|
|
|
|
|
-- do we need to override the preview_window args?
|
|
|
|
|
-- this can happen with the builtin previewer
|
|
|
|
|
-- (1) when using a split we use the previewer as placeholder
|
|
|
|
|
-- (2) we use 'right:0' to call the previewer function only
|
|
|
|
|
if previewer:override_fzf_preview_window() then
|
|
|
|
|
opts.preview_window = previewer:preview_window()
|
|
|
|
|
end
|
|
|
|
|
local previewer, preview_opts = nil, nil
|
|
|
|
|
if opts.previewer and type(opts.previewer) == 'string' then
|
|
|
|
|
preview_opts = config.globals.previewers[opts.previewer]
|
|
|
|
|
elseif opts.previewer and type(opts.previewer) == 'table' then
|
|
|
|
|
preview_opts = opts.previewer
|
|
|
|
|
end
|
|
|
|
|
if preview_opts then
|
|
|
|
|
previewer = preview_opts._new()(preview_opts, opts, fzf_win)
|
|
|
|
|
opts.preview = previewer:cmdline()
|
|
|
|
|
if type(previewer.override_fzf_preview_window) == 'function' then
|
|
|
|
|
-- do we need to override the preview_window args?
|
|
|
|
|
-- this can happen with the builtin previewer
|
|
|
|
|
-- (1) when using a split we use the previewer as placeholder
|
|
|
|
|
-- (2) we use 'right:0' to call the previewer function only
|
|
|
|
|
if previewer:override_fzf_preview_window() then
|
|
|
|
|
opts.preview_window = previewer:preview_window()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
@ -41,21 +40,10 @@ M.fzf = function(opts, contents, previewer)
|
|
|
|
|
return selected
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function char_is_lower(str, idx)
|
|
|
|
|
local byte = string_byte(str, idx)
|
|
|
|
|
return byte >= string_byte_a and byte <= string_byte_z
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
M.get_devicon = function(file, ext)
|
|
|
|
|
local icon, hl
|
|
|
|
|
if config._has_devicons and config._devicons then
|
|
|
|
|
icon, hl = config._devicons.get_icon(file, ext:lower(), {default = true})
|
|
|
|
|
--[[ if hl and #hl>7 and char_is_lower(hl, 8) then
|
|
|
|
|
-- workaround for issue #119, devicons returns
|
|
|
|
|
-- highlights with lowercase icon names
|
|
|
|
|
-- (i.e. DevIconpy instead of DevIconPy)
|
|
|
|
|
hl = hl:sub(1,7) .. hl:sub(8,8):upper() .. hl:sub(9)
|
|
|
|
|
end ]]
|
|
|
|
|
else
|
|
|
|
|
icon, hl = '', 'dark_grey'
|
|
|
|
|
end
|
|
|
|
|