Skip to content

Commit

Permalink
refactor(utils.bar): add helper function attach()
Browse files Browse the repository at this point in the history
  • Loading branch information
bekaboo committed Aug 23, 2024
1 parent d26bf92 commit 6ca84ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 2 additions & 11 deletions lua/dropbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,14 @@ local function setup(opts)
configs.set(opts)
hlgroups.init()
local groupid = vim.api.nvim_create_augroup('DropBar', {})
---Attach dropbar to window
---@param win integer
---@param buf integer
---@param info table? info from autocmd
local function attach(buf, win, info)
if configs.eval(configs.opts.general.enable, buf, win, info) then
vim.wo.winbar = '%{%v:lua.dropbar.get_dropbar_str()%}'
end
end
for _, win in ipairs(vim.api.nvim_list_wins()) do
attach(vim.api.nvim_win_get_buf(win), win)
utils.bar.attach(vim.api.nvim_win_get_buf(win), win)
end
if not vim.tbl_isempty(configs.opts.general.attach_events) then
vim.api.nvim_create_autocmd(configs.opts.general.attach_events, {
group = groupid,
callback = function(info)
attach(info.buf, 0, info)
utils.bar.attach(info.buf, 0, info)
end,
desc = 'Attach dropbar',
})
Expand Down
11 changes: 11 additions & 0 deletions lua/dropbar/utils/bar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,15 @@ function M.update_hover_hl(mouse)
last_hovered_dropbar = dropbar
end

---Attach dropbar to window
---@param win integer
---@param buf integer
---@param info table? info from autocmd
function M.attach(buf, win, info)
local configs = require('dropbar.configs')
if configs.eval(configs.opts.general.enable, buf, win, info) then
vim.wo[win].winbar = '%{%v:lua.dropbar.get_dropbar_str()%}'
end
end

return M

0 comments on commit 6ca84ad

Please sign in to comment.