Skip to content

Commit d09dbc7

Browse files
committed
feat: Custom statusline for help files
1 parent 7e5777b commit d09dbc7

File tree

3 files changed

+119
-57
lines changed

3 files changed

+119
-57
lines changed

lua/bars/highlights.lua

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,82 @@ hl.groups = {
10131013

10141014
---|fE
10151015
end,
1016+
1017+
help_gradient = function ()
1018+
---|fS
1019+
1020+
---@type number, number, number Background color.
1021+
local ML, MA, MB = hl.rgb_to_oklab(
1022+
hl.num_to_rgb(
1023+
hl.get_attr("bg", { "StatusLine", "Normal" }) or hl.choice(15725045, 1973806)
1024+
)
1025+
);
1026+
1027+
ML = ML * 1.5;
1028+
MA = MA * 1.5;
1029+
MB = MB * 1.5;
1030+
1031+
---@type number, number, number Background color.
1032+
local BL, BA, BB = hl.rgb_to_oklab(
1033+
hl.num_to_rgb(
1034+
hl.get_attr("bg", { "StatusLine", "Normal" }) or hl.choice(15725045, 1973806)
1035+
)
1036+
);
1037+
1038+
local gradient = {};
1039+
local qf_steps = 15;
1040+
1041+
for s = 0, qf_steps - 1, 1 do
1042+
---|fS
1043+
1044+
local GL, GA, GB = hl.interpolate(
1045+
ML, MA, MB,
1046+
BL, BA, BB,
1047+
s / (qf_steps - 1)
1048+
);
1049+
1050+
local next_color;
1051+
1052+
if s ~= 0 then
1053+
next_color = string.format(
1054+
"#%02x%02x%02x",
1055+
hl.oklab_to_rgb(
1056+
hl.interpolate(
1057+
ML, MA, MB,
1058+
BL, BA, BB,
1059+
(s - 1) / (qf_steps - 1)
1060+
)
1061+
)
1062+
);
1063+
end
1064+
1065+
table.insert(gradient, {
1066+
group_name = "BarsHelp" .. (s + 1),
1067+
value = {
1068+
bg = string.format("#%02x%02x%02x", hl.oklab_to_rgb(GL, GA, GB)),
1069+
fg = next_color
1070+
}
1071+
});
1072+
1073+
---|fE
1074+
end
1075+
1076+
return vim.list_extend(gradient, {
1077+
{
1078+
group_name = "BarsHelp",
1079+
value = {
1080+
bg = string.format("#%02x%02x%02x", hl.oklab_to_rgb(ML, MA, MB)),
1081+
fg = string.format("#%02x%02x%02x", hl.oklab_to_rgb(
1082+
hl.visible_fg(ML)
1083+
)),
1084+
1085+
bold = true
1086+
}
1087+
}
1088+
});
1089+
1090+
---|fE
1091+
end,
10161092
};
10171093

10181094
hl.setup = function ()

lua/bars/statusline.lua

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -395,16 +395,11 @@ statusline.config = {
395395
return vim.bo[buffer].buftype == "help";
396396
end,
397397
components = {
398-
{ kind = "empty" },
399-
TEMPLATES.mode,
398+
vim.tbl_extend("force", TEMPLATES.mode, {
399+
compact = true
400+
}),
400401
{
401402
kind = "ruler",
402-
condition = function ()
403-
local mode = vim.api.nvim_get_mode().mode;
404-
local visual_modes = { "v", "V", "" };
405-
406-
return vim.list_contains(visual_modes, mode);
407-
end,
408403

409404
default = {
410405
padding_left = " ",
@@ -413,17 +408,39 @@ statusline.config = {
413408

414409
separator = " 󰇛 ",
415410

416-
hl = "BarsRuler"
411+
hl = "BarsFt0"
417412
},
413+
},
414+
{ kind = "empty", hl = "StatusLine" },
415+
{
416+
kind = "custom",
417+
value = function ()
418+
local text = "";
418419

419-
visual = {
420-
icon = "",
420+
for i = 15, 2, -1 do
421+
text = text .. string.format("%%#BarsHelp%d#", i);
422+
text = text .. "";
423+
end
421424

422-
hl = "BarsRuler"
423-
}
425+
return text;
426+
end
427+
},
428+
{
429+
kind = "bufname",
430+
max_len = 25,
431+
432+
default = {
433+
padding_left = " ",
434+
padding_right = " ",
435+
436+
icon = "",
437+
nomodifiable_icon_hl = "BarsFt1",
438+
nomodifiable_icon = "󰌾 ",
439+
icon_hl = {
440+
"BarsFt0", "BarsFt1", "BarsFt2", "BarsFt3", "BarsFt4", "BarsFt5", "BarsFt6"
441+
},
442+
},
424443
},
425-
TEMPLATES.bufname,
426-
{ kind = "empty", hl = "StatusLine" },
427444
}
428445

429446
---|fE
@@ -654,4 +671,3 @@ statusline.setup = function (config)
654671
end
655672

656673
return statusline;
657-
--- vim:foldmethod=markers:

plugin/bars.lua

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
---@diagnostic disable: undefined-field
22

3+
---|fS "chore: Cache default values"
4+
35
vim.g.__statusline = vim.api.nvim_get_option_value("statusline", { scope = "global" });
46
vim.g.__statuscolumn = vim.o.statuscolumn;
7+
vim.g.__winbar = vim.api.nvim_get_option_value("winbar", { scope = "global" });
8+
9+
vim.g.__tabline = vim.o.tabline;
10+
11+
---|fE
512

613
--- Update the tab list when opening new windows.
714
vim.api.nvim_create_autocmd({ "VimEnter" }, {
@@ -15,12 +22,13 @@ vim.api.nvim_create_autocmd({ "VimEnter" }, {
1522
require("bars.statusline").start();
1623
require("bars.winbar").start();
1724

18-
require("bars.tabline").attach();
25+
require("bars.tabline").start();
1926
end
2027
});
2128

2229
---@type table Timer for the update task.
2330
local timer = vim.uv.new_timer();
31+
2432
---@type integer Debounce delay.
2533
local DELAY = 100;
2634

@@ -64,20 +72,13 @@ vim.api.nvim_create_autocmd({
6472
end
6573
});
6674

67-
6875
local mode_timer = vim.uv.new_timer();
6976

7077
--- Update various bars & lines on Vim mode change.
7178
vim.api.nvim_create_autocmd({ "ModeChanged" }, {
7279
callback = function ()
7380
mode_timer:stop();
74-
75-
--- We wrap this in `vim.schedule()` so
76-
--- that the update happens after doing
77-
--- something like,
7881
mode_timer:start(DELAY, 0, vim.schedule_wrap(function ()
79-
--- Unstable API function.
80-
--- Use `pcall()`
8182
pcall(vim.api.nvim__redraw, {
8283
statuscolumn = true,
8384
winbar = true,
@@ -87,22 +88,9 @@ vim.api.nvim_create_autocmd({ "ModeChanged" }, {
8788
end
8889
});
8990

90-
91-
92-
93-
94-
95-
96-
97-
98-
99-
100-
101-
--- Update the tab list when opening new windows.
91+
--- Update the tab list when opening new tabs.
10292
vim.api.nvim_create_autocmd({ "TabNew" }, {
10393
callback = function ()
104-
---|fS
105-
10694
local max = vim.g.__tabline_max_tabs or 5;
10795
local tabs = #vim.api.nvim_list_tabpages();
10896

@@ -116,31 +104,13 @@ vim.api.nvim_create_autocmd({ "TabNew" }, {
116104
end
117105

118106
vim.g.__bars_tabpage_from = math.max(1, tabs - math.floor(max * 0.25));
119-
---|fE
120107
end
121108
});
122109

123110
--- Update the tab list when opening new windows.
124111
vim.api.nvim_create_autocmd({ "ColorScheme" }, {
125112
callback = function ()
126-
---|fS
127-
128-
---|fS "Cache default values."
129-
130-
vim.g.__statusline = vim.o.statusline;
131-
132-
vim.g.__relativenumber = vim.o.relativenumber;
133-
vim.g.__numberwidth = vim.o.numberwidth;
134-
vim.g.__statuscolumn = vim.o.statuscolumn;
135-
136-
vim.g.__winbar = vim.o.winbar;
137-
vim.g.__tabline = vim.o.tabline;
138-
139-
---|fE
140-
141113
require("bars.highlights").setup();
142-
143-
---|fE
144114
end
145115
});
146116

@@ -361,7 +331,7 @@ vim.api.nvim_create_autocmd("LspProgress", {
361331
set_state(nil);
362332
end
363333

364-
vim.api.nvim__redraw({ statusline = true });
334+
vim.cmd("redrawstatus");
365335
end, 500);
366336
end
367337

0 commit comments

Comments
 (0)