Skip to content

Commit

Permalink
feat: make force_inactive and disable use Lua patterns (#92)
Browse files Browse the repository at this point in the history
BREAKING_CHANGE: `force_inactive` and `disable` no longer do equality
checks, which may break existing workflows
  • Loading branch information
famiu authored Sep 19, 2021
1 parent 079c614 commit 20b8c43
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,22 +585,22 @@ Now that we've learned to set up both the components table, it's finally time to
- `separators` - A table containing custom [separator value presets](#value-presets).
- `update_triggers` - A list of autocmds that trigger an update of the statusline in inactive windows.<br>
Default: `{'VimEnter', 'WinEnter', 'WinClosed', 'FileChangedShellPost'}`
- `force_inactive` - A table that determines which buffers should always have the inactive statusline, even when they are active. It can have 3 values inside of it, `filetypes`, `buftypes` and `bufnames`, all three of them are tables which contain file types, buffer types and buffer names respectively.<br><br>
- `force_inactive` - A table that determines which buffers should always have the inactive statusline, even when they are active. It can have 3 values inside of it, `filetypes`, `buftypes` and `bufnames`, all three of them are tables which contain Lua patterns to match against file type, buffer type and buffer name respectively.<br><br>
Default:

```lua
{
filetypes = {
'NvimTree',
'packer',
'startify',
'fugitive',
'fugitiveblame',
'qf',
'help'
'^NvimTree$',
'^packer$',
'^startify$',
'^fugitive$',
'^fugitiveblame$',
'^qf$',
'^help$'
},
buftypes = {
'terminal'
'^terminal$'
},
bufnames = {}
}
Expand Down
22 changes: 9 additions & 13 deletions lua/feline/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,21 @@ M.vi_mode_colors = {

M.force_inactive = {
filetypes = {
'NvimTree',
'packer',
'startify',
'fugitive',
'fugitiveblame',
'qf',
'help'
'^NvimTree$',
'^packer$',
'^startify$',
'^fugitive$',
'^fugitiveblame$',
'^qf$',
'^help$'
},
buftypes = {
'terminal'
'^terminal$'
},
bufnames = {}
}

M.disable = {
filetypes = {},
buftypes = {},
bufnames = {}
}
M.disable = {}

M.update_triggers = {
'VimEnter',
Expand Down
22 changes: 16 additions & 6 deletions lua/feline/generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@ local M = {
highlights = {}
}

-- Return true if any string in table matches pattern
local function find_pattern_match(tbl, val)
return next(vim.tbl_filter(
function(pattern)
return string.match(val, pattern)
end,
tbl
))
end

-- Check if current buffer is forced to have inactive statusline
local function is_forced_inactive()
local buftype = bo.buftype
local filetype = bo.filetype
local bufname = api.nvim_buf_get_name(0)

return (force_inactive.filetypes and vim.tbl_contains(force_inactive.filetypes, filetype)) or
(force_inactive.buftypes and vim.tbl_contains(force_inactive.buftypes, buftype)) or
(force_inactive.bufnames and vim.tbl_contains(force_inactive.bufnames, bufname))
return (force_inactive.filetypes and find_pattern_match(force_inactive.filetypes, filetype)) or
(force_inactive.buftypes and find_pattern_match(force_inactive.buftypes, buftype)) or
(force_inactive.bufnames and find_pattern_match(force_inactive.bufnames, bufname))
end

-- Check if buffer contained in window is configured to have statusline disabled
Expand All @@ -32,9 +42,9 @@ local function is_disabled(winid)
local filetype = bo[bufnr].filetype
local bufname = api.nvim_buf_get_name(bufnr)

return (disable.filetypes and vim.tbl_contains(disable.filetypes, filetype)) or
(disable.buftypes and vim.tbl_contains(disable.buftypes, buftype)) or
(disable.bufnames and vim.tbl_contains(disable.bufnames, bufname))
return (disable.filetypes and find_pattern_match(disable.filetypes, filetype)) or
(disable.buftypes and find_pattern_match(disable.buftypes, buftype)) or
(disable.bufnames and find_pattern_match(disable.bufnames, bufname))
end

-- Evaluate a component key if it is a function, else return the value
Expand Down

0 comments on commit 20b8c43

Please sign in to comment.