feat: Use colors from nvim-devicons
This commit is contained in:
@@ -14,9 +14,10 @@ if has_devicons then
|
|||||||
return display
|
return display
|
||||||
end
|
end
|
||||||
|
|
||||||
local icon_display = (devicons.get_icon(filename, string.match(filename, '%a+$')) or ' ') .. ' ' .. display
|
local icon, icon_highlight = devicons.get_icon(filename, string.match(filename, '%a+$'), { default = true })
|
||||||
|
local icon_display = (icon or ' ') .. ' ' .. display
|
||||||
|
|
||||||
return icon_display
|
return icon_display, icon_highlight
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
transform_devicons = function(_, display, _)
|
transform_devicons = function(_, display, _)
|
||||||
@@ -66,12 +67,18 @@ do
|
|||||||
|
|
||||||
mt_file_entry.cwd = cwd
|
mt_file_entry.cwd = cwd
|
||||||
mt_file_entry.display = function(entry)
|
mt_file_entry.display = function(entry)
|
||||||
local display = entry.value
|
local display, hl_group = entry.value, nil
|
||||||
if shorten_path then
|
if shorten_path then
|
||||||
display = utils.path_shorten(display)
|
display = utils.path_shorten(display)
|
||||||
end
|
end
|
||||||
|
|
||||||
return transform_devicons(entry.value, display, disable_devicons)
|
display, hl_group = transform_devicons(entry.value, display, disable_devicons)
|
||||||
|
|
||||||
|
if hl_group then
|
||||||
|
return display, { { {1, 3}, hl_group } }
|
||||||
|
else
|
||||||
|
return display
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mt_file_entry.__index = function(t, k)
|
mt_file_entry.__index = function(t, k)
|
||||||
@@ -151,7 +158,7 @@ do
|
|||||||
|
|
||||||
mt_vimgrep_entry.cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
|
mt_vimgrep_entry.cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
|
||||||
mt_vimgrep_entry.display = function(entry)
|
mt_vimgrep_entry.display = function(entry)
|
||||||
local display = entry.value
|
local display, hl_group = entry.value, nil
|
||||||
|
|
||||||
local display_filename
|
local display_filename
|
||||||
if shorten_path then
|
if shorten_path then
|
||||||
@@ -165,13 +172,17 @@ do
|
|||||||
coordinates = string.format("%s:%s:", entry.lnum, entry.col)
|
coordinates = string.format("%s:%s:", entry.lnum, entry.col)
|
||||||
end
|
end
|
||||||
|
|
||||||
display = transform_devicons(
|
display, hl_group = transform_devicons(
|
||||||
entry.filename,
|
entry.filename,
|
||||||
string.format(display_string, display_filename, coordinates, entry.text),
|
string.format(display_string, display_filename, coordinates, entry.text),
|
||||||
disable_devicons
|
disable_devicons
|
||||||
)
|
)
|
||||||
|
|
||||||
return display
|
if hl_group then
|
||||||
|
return display, { { {1, 3}, hl_group } }
|
||||||
|
else
|
||||||
|
return display
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mt_vimgrep_entry.__index = function(t, k)
|
mt_vimgrep_entry.__index = function(t, k)
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ local extend = function(opts, defaults)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local ns_telescope_selection = a.nvim_create_namespace('telescope_selection')
|
local ns_telescope_selection = a.nvim_create_namespace('telescope_selection')
|
||||||
|
local ns_telescope_entry = a.nvim_create_namespace('telescope_entry')
|
||||||
local ns_telescope_matching = a.nvim_create_namespace('telescope_matching')
|
local ns_telescope_matching = a.nvim_create_namespace('telescope_matching')
|
||||||
local ns_telescope_prompt = a.nvim_create_namespace('telescope_prompt')
|
local ns_telescope_prompt = a.nvim_create_namespace('telescope_prompt')
|
||||||
local ns_telescope_prompt_prefix = a.nvim_create_namespace('telescope_prompt_prefix')
|
local ns_telescope_prompt_prefix = a.nvim_create_namespace('telescope_prompt_prefix')
|
||||||
@@ -772,10 +773,10 @@ function Picker:entry_adder(index, entry, score)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local display
|
local display, display_highlights
|
||||||
if type(entry.display) == 'function' then
|
if type(entry.display) == 'function' then
|
||||||
self:_increment("display_fn")
|
self:_increment("display_fn")
|
||||||
display = entry:display()
|
display, display_highlights = entry:display()
|
||||||
elseif type(entry.display) == 'string' then
|
elseif type(entry.display) == 'string' then
|
||||||
display = entry.display
|
display = entry.display
|
||||||
else
|
else
|
||||||
@@ -786,11 +787,8 @@ function Picker:entry_adder(index, entry, score)
|
|||||||
-- This is the two spaces to manage the '> ' stuff.
|
-- This is the two spaces to manage the '> ' stuff.
|
||||||
-- Maybe someday we can use extmarks or floaty text or something to draw this and not insert here.
|
-- Maybe someday we can use extmarks or floaty text or something to draw this and not insert here.
|
||||||
-- until then, insert two spaces
|
-- until then, insert two spaces
|
||||||
if TELESCOPE_DEBUG then
|
local prefix = TELESCOPE_DEBUG and (' ' .. score) or ' '
|
||||||
display = ' ' .. score .. display
|
display = prefix .. display
|
||||||
else
|
|
||||||
display = ' ' .. display
|
|
||||||
end
|
|
||||||
|
|
||||||
self:_increment("displayed")
|
self:_increment("displayed")
|
||||||
|
|
||||||
@@ -803,6 +801,11 @@ function Picker:entry_adder(index, entry, score)
|
|||||||
|
|
||||||
|
|
||||||
local set_ok = pcall(vim.api.nvim_buf_set_lines, self.results_bufnr, row, row + 1, false, {display})
|
local set_ok = pcall(vim.api.nvim_buf_set_lines, self.results_bufnr, row, row + 1, false, {display})
|
||||||
|
if set_ok and display_highlights then
|
||||||
|
for _, hl_block in ipairs(display_highlights) do
|
||||||
|
a.nvim_buf_add_highlight(self.results_bufnr, ns_telescope_entry, hl_block[2], row, #prefix + hl_block[1][1], #prefix + hl_block[1][2])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- This pretty much only fails when people leave newlines in their results.
|
-- This pretty much only fails when people leave newlines in their results.
|
||||||
-- So we'll clean it up for them if it fails.
|
-- So we'll clean it up for them if it fails.
|
||||||
|
|||||||
Reference in New Issue
Block a user