Skip to content

Commit

Permalink
feat: allow configuring highlight reset triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
famiu committed Oct 3, 2021
1 parent c1efdc1 commit b0df1df
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
3 changes: 3 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ Here is a list of all possible vi_mode names used with the default color associa
| `TERM` | Terminal mode | `'green'` |
| `NONE` | None | `'yellow'` |

- `highlight_reset_triggers` - Feline automatically resets its cached highlights on certain autocommands to prevent the statusline colors from getting messed up. The value of `highlight_reset_triggers` can be set to a table containing a list of autocommands that'll trigger a highlight reset.<br>
Default: `{'SessionLoadPost', 'ColorScheme'}`

## Example configuration

You can check out the code in the [default preset](lua/feline/presets/default.lua) to see how the components in it are set up so you can get a good practical idea of how to use the tools that Feline gives you to create all kinds of different statusline components.
Expand Down
5 changes: 5 additions & 0 deletions lua/feline/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ M.force_inactive = {

M.disable = {}

M.highlight_reset_triggers = {
'SessionLoadPost',
'ColorScheme'
}

return M
24 changes: 17 additions & 7 deletions lua/feline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,23 @@ function M.setup(config)

vim.o.statusline = '%{%v:lua.require\'feline\'.statusline()%}'

utils.create_augroup({
{
'SessionLoadPost,ColorScheme',
'*',
'lua require("feline").reset_highlights()'
}
}, 'feline')
local highlight_reset_triggers = parse_config(
config,
'highlight_reset_triggers',
'table',
defaults.highlight_reset_triggers
)

-- Autocommand to reset highlights according to the `highlight_reset_triggers` configuration
if next(highlight_reset_triggers) then
utils.create_augroup({
{
table.concat(highlight_reset_triggers, ','),
'*',
'lua require("feline").reset_highlights()'
}
}, 'feline')
end
end

function M.statusline()
Expand Down

0 comments on commit b0df1df

Please sign in to comment.