Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
feat: add always_visible option for icons
Browse files Browse the repository at this point in the history
  • Loading branch information
famiu committed Sep 22, 2021
1 parent e6333ef commit 58ac1a4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,10 @@ enabled = function(winid)
end
```

- `icon` (table, string or function): Some inbuilt providers such as `git_branch` provide default icons. If you either don't have a patched font or don't like the default icon that Feline provides, or if you want an icon for a component that doesn't have any default icons, you may set this value to use any icon you want instead. By default, the icon inherits the component's highlight, but you can also change the highlight specifically for the icon. To do this, you need to pass a table containing `str` and `hl`, where `str` would represent the icon and `hl` would represent the icon highlight. The icon's highlight works just like the `hl` component's values. If it's a function, it can take either the window handler as an argument, or it can take no arguments. For example:
- `icon` (table, string or function): Some inbuilt providers such as `git_branch` provide default icons. If you either don't have a patched font or don't like the default icon that Feline provides, or if you want an icon for a component that doesn't have any default icons, you may set this value to use any icon you want instead.<br><br>
By default, the icon inherits the component's highlight, but you can also change the highlight specifically for the icon. To do this, you need to pass a table containing `str` and `hl`, where `str` would represent the icon and `hl` would represent the icon highlight. The icon's highlight works just like the `hl` component's values.<br><br>
There's also another value you can set if the value of `icon` is a table, which is `always_visible`. By default, the icon is not shown if the value returned by the provider is empty. If you want the icon to be shown even when the provider string is empty, you need to set `always_visible` to `true`.<br><br>
If the value of `icon` a function, it can take either the window handler as an argument, or it can take no arguments. For example:

```lua
-- Setting icon to a string
Expand All @@ -331,7 +334,18 @@ icon = function() return ' - ' end
-- Setting icon to a table
icon = {
str = ' ~ ',
hl = { fg = 'orange' },
hl = { fg = 'orange' }
}

-- Making icon always visible
icon = {
str = '',
hl = {
fg = require('feline.providers.vi_mode').get_mode_color(),
bg = 'black',
style = 'bold'
},
always_visible = true
}
```

Expand Down
15 changes: 11 additions & 4 deletions lua/feline/generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,20 @@ end

-- Parse component icon
-- By default, icon inherits component highlights
local function parse_icon(icon, parent_hl)
local function parse_icon(icon, parent_hl, is_component_empty)
if icon == nil then return '' end

local str
local hl
local str

if type(icon) == "string" then
if is_component_empty then return '' end

str = icon
hl = parent_hl
else
if is_component_empty and not icon.always_visible then return '' end

str = icon.str or ''
hl = icon.hl or parent_hl
end
Expand Down Expand Up @@ -264,17 +268,20 @@ local function parse_component(component, winid)
winid
)

icon = parse_icon(evaluate_if_function(component.icon or icon, winid), hl, is_component_empty)

if is_component_empty then
return string.format(
'%s%s',
'%s%s%s',
left_sep_str,
icon,
right_sep_str
)
else
return string.format(
'%s%s%%#%s#%s%s',
left_sep_str,
parse_icon(evaluate_if_function(component.icon or icon, winid), hl),
icon,
hlname or get_hlname(hl),
str,
right_sep_str
Expand Down

0 comments on commit 58ac1a4

Please sign in to comment.