feat: all entry_makers are now overridable and icons for builtin.buffers (#364)

This commit is contained in:
tamago324
2020-12-28 01:15:52 +09:00
committed by GitHub
parent 3e884e863a
commit e555cd375f
5 changed files with 46 additions and 17 deletions

View File

@@ -33,6 +33,7 @@ local lsp_type_highlight = {
local make_entry = {}
local transform_devicons
local get_devicons
if has_devicons then
if not devicons.has_loaded() then
devicons.setup()
@@ -52,10 +53,27 @@ if has_devicons then
return icon_display
end
end
get_devicons = function(filename, disable_devicons)
if disable_devicons or not filename then
return ''
end
local icon, icon_highlight = devicons.get_icon(filename, string.match(filename, '%a+$'), { default = true })
if conf.color_devicons then
return icon, icon_highlight
else
return icon
end
end
else
transform_devicons = function(_, display, _)
return display
end
get_devicons = function(_, _)
return ''
end
end
do
@@ -426,11 +444,19 @@ end
function make_entry.gen_from_buffer(opts)
opts = opts or {}
local disable_devicons = opts.disable_devicons
local icon_width = 0
if not disable_devicons then
icon_width = vim.fn.strdisplaywidth(get_devicons('fname', disable_devicons))
end
local displayer = entry_display.create {
separator = " ",
items = {
{ width = opts.bufnr_width },
{ width = 4 },
{ width = icon_width },
{ remaining = true },
},
}
@@ -445,9 +471,12 @@ function make_entry.gen_from_buffer(opts)
display_bufname = entry.filename
end
local icon, hl_group = get_devicons(entry.filename, disable_devicons)
return displayer {
{entry.bufnr, "TelescopeResultsNumber"},
{entry.indicator, "TelescopeResultsComment"},
{ icon, hl_group },
display_bufname .. ":" .. entry.lnum
}
end