Skip to content

Commit 6cdecdb

Browse files
committed
fix: Added missing setup function
refactor: Changed internal variable name `default` -> `custom`
1 parent be6dc4a commit 6cdecdb

6 files changed

Lines changed: 25 additions & 30 deletions

File tree

lua/bars/generic.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function generic:should_detach (win)
7474

7575
local current = self:current(win) or "";
7676

77-
if current ~= self.default then
77+
if current ~= self.custom then
7878
return false;
7979
end
8080

@@ -324,6 +324,14 @@ builder.new = function ()
324324
local out = setmetatable({}, generic);
325325
out:set_default_state();
326326

327+
out.setup = function (config)
328+
if type(config) == "boolean" then
329+
out.state.enable = config;
330+
elseif type(config) == "table" then
331+
out.config = vim.tbl_deep_extend("force", out.config, config);
332+
end
333+
end
334+
327335
return out;
328336
end
329337

lua/bars/statuscolumn.lua

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
---@diagnostic disable: duplicate-set-field
22
local statuscolumn = require("bars.generic").new();
33

4-
statuscolumn.default = "%!v:lua.require('bars.statuscolumn').render()";
4+
statuscolumn.custom = "%!v:lua.require('bars.statuscolumn').render()";
55
statuscolumn.var_name = "bars_statuscolumn_style";
66
-- statuscolumn.use_blank_output = true;
77

8-
---@class bars.statusline.state
9-
statuscolumn.state = {
10-
enable = true,
11-
window_state = {},
12-
};
13-
148
local gradient_map = {
159
default = "BarsNormal%d",
1610

@@ -241,11 +235,11 @@ end
241235
function statuscolumn:current (win) return vim.wo[win].statuscolumn; end
242236

243237
function statuscolumn:start ()
244-
if not statuscolumn.state.enable then
238+
if not self.state.enable then
245239
return;
246240
end
247241

248-
vim.api.nvim_set_option_value("statuscolumn", statuscolumn.default, { scope = "global" });
242+
vim.api.nvim_set_option_value("statuscolumn", statuscolumn.custom, { scope = "global" });
249243

250244
vim.api.nvim_set_option_value("number", true, { scope = "global" });
251245
vim.api.nvim_set_option_value("relativenumber", true, { scope = "global" });
@@ -259,7 +253,7 @@ end
259253

260254
---@param win integer
261255
function statuscolumn:set (win)
262-
vim.api.nvim_set_option_value("statuscolumn", statuscolumn.default, {
256+
vim.api.nvim_set_option_value("statuscolumn", statuscolumn.custom, {
263257
scope = "local",
264258
win = win
265259
});

lua/bars/statusline.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---@diagnostic disable: duplicate-set-field
22
local statusline = require("bars.generic").new();
33

4-
statusline.default = "%!v:lua.require('bars.statusline').render()";
4+
statusline.custom = "%!v:lua.require('bars.statusline').render()";
55
statusline.var_name = "bars_statusline_style";
66

77
--[[ Reusable configuration templates. ]]
@@ -515,11 +515,11 @@ end
515515
function statusline:current (win) return vim.wo[win].statusline; end
516516

517517
function statusline:start ()
518-
if not statusline.state.enable then
518+
if not self.state.enable then
519519
return;
520520
end
521521

522-
vim.api.nvim_set_option_value("statusline", statusline.default, { scope = "global" });
522+
vim.api.nvim_set_option_value("statusline", statusline.custom, { scope = "global" });
523523

524524
for _, win in ipairs(vim.api.nvim_list_wins()) do
525525
statusline:handle_new_window(win);
@@ -530,7 +530,7 @@ end
530530

531531
---@param win integer
532532
function statusline:set (win)
533-
vim.api.nvim_set_option_value("statusline", statusline.default, {
533+
vim.api.nvim_set_option_value("statusline", statusline.custom, {
534534
scope = "local",
535535
win = win
536536
});

lua/bars/tabline.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---@diagnostic disable: duplicate-set-field
22
local tabline = require("bars.generic").new();
33

4-
tabline.default = "%!v:lua.require('bars.tabline').render()";
4+
tabline.custom = "%!v:lua.require('bars.tabline').render()";
55
tabline.var_name = "bars_tabline_style";
66

77
---@class tabline.config
@@ -126,7 +126,7 @@ function tabline:start ()
126126
return;
127127
end
128128

129-
vim.api.nvim_set_option_value("tabline", tabline.default, { scope = "global" });
129+
vim.api.nvim_set_option_value("tabline", tabline.custom, { scope = "global" });
130130

131131
for _, win in ipairs(vim.api.nvim_list_wins()) do
132132
tabline:handle_new_window(win);
@@ -137,7 +137,7 @@ end
137137

138138
---@param _ integer
139139
function tabline:set (_)
140-
vim.api.nvim_set_option_value("tabline", tabline.default, {
140+
vim.api.nvim_set_option_value("tabline", tabline.custom, {
141141
scope = "global",
142142
});
143143
end

lua/bars/types/generics.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bar:enable(0);
1818
---@class bars.generic
1919
---
2020
---@field config bars.generic.config Bars configuration.
21-
---@field default string Default value for a `bar@` used by the plugin.
21+
---@field custom string Custom value for a `bar` used by the plugin.
2222
---@field state bars.generic.state Bars state.
2323
---@field use_blank_output? boolean Uses blank output for windows without styles.
2424
---@field var_name string Variable name for storing current style name.
@@ -34,6 +34,7 @@ bar:enable(0);
3434
---@field detach fun(self: bars.generic, win: integer): nil Detaches from a `window`.
3535
---@field handle_new_window fun(self: bars.generic, win: integer): nil Handle events that causes a window to be attached/detached. Mainly `WinNew`..
3636
---@field update_style fun(self: bars.generic, win: integer): nil Updates the bar/line style for a `window`.
37+
---@field setup fun(config: boolean | bars.generic.config): nil Sets up a `bar`.
3738
---
3839
---@field start fun(self: bars.generic): nil Starts a bar.
3940
---@field enable fun(self: bars.generic, win: integer): nil Enables bar/line for a `window`.

lua/bars/winbar.lua

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---@diagnostic disable: duplicate-set-field
22
local winbar = require("bars.generic").new();
33

4-
winbar.default = "%!v:lua.require('bars.winbar').render()";
4+
winbar.custom = "%!v:lua.require('bars.winbar').render()";
55
winbar.var_name = "bars_winbar_style";
66

77
---@class winbar.config
@@ -600,7 +600,7 @@ function winbar:start ()
600600
return;
601601
end
602602

603-
vim.api.nvim_set_option_value("winbar", winbar.default, { scope = "global" });
603+
vim.api.nvim_set_option_value("winbar", winbar.custom, { scope = "global" });
604604

605605
for _, win in ipairs(vim.api.nvim_list_wins()) do
606606
winbar:handle_new_window(win);
@@ -611,7 +611,7 @@ end
611611

612612
---@param win integer
613613
function winbar:set (win)
614-
vim.api.nvim_set_option_value("winbar", winbar.default, {
614+
vim.api.nvim_set_option_value("winbar", winbar.custom, {
615615
scope = "local",
616616
win = win
617617
});
@@ -633,12 +633,4 @@ function winbar:render ()
633633
return winbar:get_styled_output(win, components);
634634
end
635635

636-
function winbar.setup (config)
637-
if type(config) == "boolean" then
638-
winbar.state.enable = config;
639-
elseif type(config) == "table" then
640-
winbar.config = vim.tbl_extend("force", winbar.config, config);
641-
end
642-
end
643-
644636
return winbar;

0 commit comments

Comments
 (0)