Skip to content

Commit 208e0b8

Browse files
committed
refactor(core): Changed how different methods work
1 parent 4a8cdd6 commit 208e0b8

File tree

4 files changed

+86
-107
lines changed

4 files changed

+86
-107
lines changed

lua/bars/statuscolumn.lua

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -453,33 +453,6 @@ end
453453

454454
----------------------------------------------------------------------
455455

456-
--- Toggles state of given window.
457-
---@param window integer
458-
statuscolumn.toggle = function (window)
459-
if type(window) ~= "number" or statuscolumn.state.attached_windows[window] == nil then
460-
return;
461-
elseif statuscolumn.state.attached_windows[window] == true then
462-
statuscolumn.detach(window);
463-
else
464-
statuscolumn.attach(window, true);
465-
end
466-
end
467-
468-
--- Toggles statuscolumn **globally**.
469-
statuscolumn.Toggle = function ()
470-
--- true -> false,
471-
--- false -> true
472-
statuscolumn.state.enable = not statuscolumn.state.enable;
473-
474-
for window, state in pairs(statuscolumn.state.attached_windows) do
475-
if state ~= nil then
476-
statuscolumn.toggle(window);
477-
end
478-
end
479-
end
480-
481-
----------------------------------------------------------------------
482-
483456
--- Enables statuscolumn for `window`.
484457
---@param window integer
485458
statuscolumn.enable = function (window)
@@ -496,7 +469,7 @@ statuscolumn.Enable = function ()
496469

497470
for window, state in pairs(statuscolumn.state.attached_windows) do
498471
if state ~= true then
499-
statuscolumn.attach(window);
472+
statuscolumn.enable(window);
500473
end
501474
end
502475
end
@@ -515,7 +488,7 @@ end
515488
statuscolumn.Disable = function ()
516489
for window, state in pairs(statuscolumn.state.attached_windows) do
517490
if state ~= false then
518-
statuscolumn.detach(window);
491+
statuscolumn.disable(window);
519492
end
520493
end
521494

@@ -524,6 +497,29 @@ end
524497

525498
----------------------------------------------------------------------
526499

500+
--- Toggles state of given window.
501+
---@param window integer
502+
statuscolumn.toggle = function (window)
503+
if type(window) ~= "number" or statuscolumn.state.attached_windows[window] == nil then
504+
return;
505+
elseif statuscolumn.state.attached_windows[window] == true then
506+
statuscolumn.disable(window);
507+
else
508+
statuscolumn.enable(window);
509+
end
510+
end
511+
512+
--- Toggles statuscolumn **globally**.
513+
statuscolumn.Toggle = function ()
514+
if statuscolumn.state.enable == true then
515+
statuscolumn.Disable();
516+
else
517+
statuscolumn.Enable();
518+
end
519+
end
520+
521+
----------------------------------------------------------------------
522+
527523
--- Sets up the statuscolumn module.
528524
---@param config statuscolumn.config | nil
529525
statuscolumn.setup = function (config)

lua/bars/statusline.lua

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -676,33 +676,6 @@ end
676676

677677
----------------------------------------------------------------------
678678

679-
--- Toggles state of given window.
680-
---@param window integer
681-
statusline.toggle = function (window)
682-
if type(window) ~= "number" or statusline.state.attached_windows[window] == nil then
683-
return;
684-
elseif statusline.state.attached_windows[window] == true then
685-
statusline.detach(window);
686-
else
687-
statusline.attach(window, true);
688-
end
689-
end
690-
691-
--- Toggles statusline **globally**.
692-
statusline.Toggle = function ()
693-
--- true -> false,
694-
--- false -> true
695-
statusline.state.enable = not statusline.state.enable;
696-
697-
for window, state in pairs(statusline.state.attached_windows) do
698-
if state ~= nil then
699-
statusline.toggle(window);
700-
end
701-
end
702-
end
703-
704-
----------------------------------------------------------------------
705-
706679
--- Enables statusline for `window`.
707680
---@param window integer
708681
statusline.enable = function (window)
@@ -719,7 +692,7 @@ statusline.Enable = function ()
719692

720693
for window, state in pairs(statusline.state.attached_windows) do
721694
if state ~= true then
722-
statusline.attach(window);
695+
statusline.enable(window);
723696
end
724697
end
725698
end
@@ -738,7 +711,7 @@ end
738711
statusline.Disable = function ()
739712
for window, state in pairs(statusline.state.attached_windows) do
740713
if state ~= false then
741-
statusline.detach(window);
714+
statusline.disable(window);
742715
end
743716
end
744717

@@ -747,6 +720,29 @@ end
747720

748721
----------------------------------------------------------------------
749722

723+
--- Toggles state of given window.
724+
---@param window integer
725+
statusline.toggle = function (window)
726+
if type(window) ~= "number" or statusline.state.attached_windows[window] == nil then
727+
return;
728+
elseif statusline.state.attached_windows[window] == true then
729+
statusline.disable(window);
730+
else
731+
statusline.enable(window);
732+
end
733+
end
734+
735+
--- Toggles statusline **globally**.
736+
statusline.Toggle = function ()
737+
if statusline.state.enable == true then
738+
statusline.Disable();
739+
else
740+
statusline.Enable();
741+
end
742+
end
743+
744+
----------------------------------------------------------------------
745+
750746
--- Sets up the statusline module.
751747
---@param config statusline.config | nil
752748
statusline.setup = function (config)

lua/bars/tabline.lua

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -281,26 +281,6 @@ end
281281

282282
----------------------------------------------------------------------
283283

284-
--- Toggles state of tabline.
285-
tabline.toggle = function ()
286-
if tabline.state.attached == true then
287-
tabline.detach();
288-
else
289-
tabline.attach();
290-
end
291-
end
292-
293-
--- Toggles tabline.
294-
tabline.Toggle = function ()
295-
--- true -> false,
296-
--- false -> true
297-
tabline.state.enable = not tabline.state.enable;
298-
299-
tabline.toggle();
300-
end
301-
302-
----------------------------------------------------------------------
303-
304284
--- Enables *all* attached windows.
305285
tabline.Enable = function ()
306286
tabline.state.enable = true;
@@ -317,6 +297,17 @@ end
317297

318298
----------------------------------------------------------------------
319299

300+
--- Toggles tabline.
301+
tabline.Toggle = function ()
302+
if tabline.state.enable == true then
303+
tabline.Disable();
304+
else
305+
tabline.Enable();
306+
end
307+
end
308+
309+
----------------------------------------------------------------------
310+
320311
--- Sets up the tabline module.
321312
---@param config tabline.config | nil
322313
tabline.setup = function (config)

lua/bars/winbar.lua

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -826,33 +826,6 @@ end
826826

827827
----------------------------------------------------------------------
828828

829-
--- Toggles state of given window.
830-
---@param window integer
831-
winbar.toggle = function (window)
832-
if type(window) ~= "number" or winbar.state.attached_windows[window] == nil then
833-
return;
834-
elseif winbar.state.attached_windows[window] == true then
835-
winbar.detach(window);
836-
else
837-
winbar.attach(window, true);
838-
end
839-
end
840-
841-
--- Toggles winbar **globally**.
842-
winbar.Toggle = function ()
843-
--- true -> false,
844-
--- false -> true
845-
winbar.state.enable = not winbar.state.enable;
846-
847-
for window, state in pairs(winbar.state.attached_windows) do
848-
if state ~= nil then
849-
winbar.toggle(window);
850-
end
851-
end
852-
end
853-
854-
----------------------------------------------------------------------
855-
856829
--- Enables winbar for `window`.
857830
---@param window integer
858831
winbar.enable = function (window)
@@ -869,7 +842,7 @@ winbar.Enable = function ()
869842

870843
for window, state in pairs(winbar.state.attached_windows) do
871844
if state ~= true then
872-
winbar.attach(window);
845+
winbar.enable(window);
873846
end
874847
end
875848
end
@@ -888,7 +861,7 @@ end
888861
winbar.Disable = function ()
889862
for window, state in pairs(winbar.state.attached_windows) do
890863
if state ~= false then
891-
winbar.detach(window);
864+
winbar.disable(window);
892865
end
893866
end
894867

@@ -897,6 +870,29 @@ end
897870

898871
----------------------------------------------------------------------
899872

873+
--- Toggles state of given window.
874+
---@param window integer
875+
winbar.toggle = function (window)
876+
if type(window) ~= "number" or winbar.state.attached_windows[window] == nil then
877+
return;
878+
elseif winbar.state.attached_windows[window] == true then
879+
winbar.disable(window);
880+
else
881+
winbar.enable(window);
882+
end
883+
end
884+
885+
--- Toggles winbar **globally**.
886+
winbar.Toggle = function ()
887+
if winbar.state.enable == true then
888+
winbar.Disable();
889+
else
890+
winbar.Enable();
891+
end
892+
end
893+
894+
----------------------------------------------------------------------
895+
900896
--- Sets up the winbar module.
901897
---@param config winbar.config | nil
902898
winbar.setup = function (config)

0 commit comments

Comments
 (0)