Skip to content

Commit 5b42f8e

Browse files
committed
refactor(statuscolumn): Replcaced # with strdisplaywidth() for getting lnum width
feat(tabline): Added tabline component to show tabs
1 parent e801a2d commit 5b42f8e

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

lua/bars/components/statuscolumn.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ scC.lnum = function (buffer, window, config)
2929

3030
local _o = "";
3131

32-
local max_width = #tostring(vim.api.nvim_buf_line_count(buffer));
32+
local max_width = vim.fn.strdisplaywidth(
33+
tostring(vim.api.nvim_buf_line_count(buffer))
34+
);
3335

3436
local function get (entry, index, ignore)
3537
if vim.islist(entry) then

lua/bars/components/tabline.lua

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
local tlC = {};
2+
local utils = require("bars.utils");
3+
4+
tlC.tabs = function (config)
5+
local tabs = vim.api.nvim_list_tabpages();
6+
local _o = "";
7+
8+
for t, tab in ipairs(tabs) do
9+
local current = tab == vim.api.nvim_get_current_tabpage();
10+
local tab_config = utils.match(config, current == true and "active" or "inactive", {});
11+
12+
_o = table.concat({
13+
_o,
14+
15+
"%" .. t .. "T",
16+
17+
utils.set_hl(tab_config.corner_left_hl or tab_config.hl),
18+
tab_config.corner_left or "",
19+
20+
utils.set_hl(tab_config.padding_left_hl or tab_config.hl),
21+
tab_config.padding_left or "",
22+
23+
utils.set_hl(tab_config.icon_hl or tab_config.hl),
24+
tab_config.icon or "",
25+
26+
utils.set_hl(tab_config.hl),
27+
tab,
28+
29+
utils.set_hl(tab_config.padding_right_hl or tab_config.hl),
30+
tab_config.padding_right or "",
31+
32+
utils.set_hl(tab_config.corner_right_hl or tab_config.hl),
33+
tab_config.corner_right or "",
34+
35+
"%X"
36+
});
37+
end
38+
39+
return _o;
40+
end
41+
42+
--- Returns the output of the section {name}.
43+
---@param part_config table
44+
---@param tabline string
45+
---@return string
46+
tlC.get = function (name, part_config, tabline)
47+
---|fS
48+
49+
if type(name) ~= "string" then
50+
--- Component doesn't exist.
51+
return "";
52+
elseif type(tlC[name]) ~= "function" then
53+
--- Attempting to get internal property.
54+
return "";
55+
else
56+
if part_config.condition ~= nil then
57+
if part_config.condition == false then
58+
--- Part is disabled.
59+
return "";
60+
else
61+
local sucess, val = pcall(part_config.condition, tabline);
62+
63+
if sucess == false then
64+
return "";
65+
elseif val == false then
66+
return "";
67+
end
68+
end
69+
end
70+
71+
local static_config = vim.deepcopy(part_config);
72+
73+
for key, value in pairs(static_config) do
74+
if type(value) ~= "function" then
75+
goto continue;
76+
end
77+
78+
local s_success, s_val = pcall(value, tabline);
79+
80+
if s_success == false then
81+
static_config[key] = nil;
82+
else
83+
static_config[key] = s_val;
84+
end
85+
86+
::continue::
87+
end
88+
89+
--- Return component value.
90+
return tlC[name](static_config, tabline) or "";
91+
end
92+
93+
---|fE
94+
end
95+
96+
return tlC;

0 commit comments

Comments
 (0)