From 6ca84ad1c751a8092364749a159c10e6a88e9ad7 Mon Sep 17 00:00:00 2001 From: bekaboo <18127878294@qq.com> Date: Fri, 23 Aug 2024 01:41:23 -0400 Subject: [PATCH] refactor(utils.bar): add helper function `attach()` --- lua/dropbar.lua | 13 ++----------- lua/dropbar/utils/bar.lua | 11 +++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lua/dropbar.lua b/lua/dropbar.lua index c8c18a3e..d85c1cdd 100644 --- a/lua/dropbar.lua +++ b/lua/dropbar.lua @@ -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', }) diff --git a/lua/dropbar/utils/bar.lua b/lua/dropbar/utils/bar.lua index 9461e2c5..cc2a554b 100644 --- a/lua/dropbar/utils/bar.lua +++ b/lua/dropbar/utils/bar.lua @@ -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