Skip to content

Commit

Permalink
feat: missing icon keys will be set to the default (#49) (#51)
Browse files Browse the repository at this point in the history
It is now possible to specify part of the icon table fields for file
providers (i.e. file_type). The missing fields will resort to default
values.
  • Loading branch information
freddiehaddad authored Nov 19, 2023
1 parent f488f9d commit b315e31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lua/feline/generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ local function parse_component(gen, component, use_short_provider, winid, sectio

local right_sep_str = parse_sep_list(gen, component.right_sep, hl.bg, is_component_empty)

icon = parse_icon(gen, component.icon or icon, hl, is_component_empty)
icon = parse_icon(gen, icon or component.icon, hl, is_component_empty)

return string.format(
'%s%s%%#%s#%s%s',
Expand Down
23 changes: 14 additions & 9 deletions lua/feline/providers/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,21 @@ function M.file_info(component, opts)
local readonly_str, modified_str, icon

-- Avoid loading nvim-web-devicons if an icon is provided already
if not component.icon then
if not component.icon or type(component.icon) == 'table' then
local icon_str, icon_color = require('nvim-web-devicons').get_icon_color(
fn.expand('%:t'),
nil, -- extension is already computed by nvim-web-devicons
{ default = true }
)

icon = { str = icon_str }
local default_icon = {}
default_icon.str = icon_str

if opts.colored_icon == nil or opts.colored_icon then
icon.hl = { fg = icon_color }
default_icon.hl = { fg = icon_color }
end

icon = vim.tbl_deep_extend('keep', component.icon or {}, default_icon)
end

local filename = api.nvim_buf_get_name(0)
Expand Down Expand Up @@ -168,23 +171,25 @@ function M.file_type(component, opts)
local filetype = bo.filetype
local icon

-- Avoid loading nvim-web-devicons if an icon is provided already
if opts.filetype_icon then
if not component.icon then
if not component.icon or type(component.icon) == 'table' then
local icon_str, icon_color = require('nvim-web-devicons').get_icon_color(
fn.expand('%:t'),
nil, -- extension is already computed by nvim-web-devicons
{ default = true }
)

icon = { str = icon_str }
local default_icon = {}
default_icon.str = icon_str

if opts.colored_icon ~= false then
icon.hl = { fg = icon_color }
default_icon.hl = { fg = icon_color }
end
end

filetype = ' ' .. filetype
icon = vim.tbl_deep_extend('keep', component.icon or {}, default_icon)

filetype = ' ' .. filetype
end
end

if opts.case == 'titlecase' then
Expand Down

0 comments on commit b315e31

Please sign in to comment.