Skip to content

Commit 080afb0

Browse files
committed
feat(tabline): add tabline module
1 parent 2d92b21 commit 080afb0

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/arsham/arshamiser.nvim)
44
![License](https://img.shields.io/github/license/arsham/arshamiser.nvim)
55

6-
Neovim status bar, colour scheme, and foldtext function.
6+
Neovim status bar, colour scheme, foldtext and tabline functions.
77

88
1. [Demo](#demo)
99
2. [Requirements](#requirements)
@@ -54,6 +54,8 @@ use({
5454
-- require("arshamiser.heirliniser")
5555
_G.custom_foldtext = require("arshamiser.folding").foldtext
5656
vim.opt.foldtext = "v:lua.custom_foldtext()"
57+
-- if you want to draw a tabline:
58+
vim.api.nvim_set_option("tabline", [[%{%v:lua.require("arshamiser.tabline").draw()%}]])
5759
end,
5860
})
5961
```
@@ -93,6 +95,8 @@ use({
9395
-- require("arshamiser.heirliniser")
9496
_G.custom_foldtext = require("arshamiser.folding").foldtext
9597
vim.opt.foldtext = "v:lua.custom_foldtext()"
98+
-- if you want to draw a tabline:
99+
vim.api.nvim_set_option("tabline", [[%{%v:lua.require("arshamiser.tabline").draw()%}]])
96100
end,
97101
})
98102
end,

lua/arshamiser/tabline.lua

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
local function title(bufnr, sel)
2+
local bufname = vim.api.nvim_buf_get_name(bufnr)
3+
local fname = bufname ~= "" and vim.fn.fnamemodify(bufname, ":t") or "[EMPTY]"
4+
local c = "%#TabLine#"
5+
if sel then
6+
c = "%#TabLineSel#"
7+
end
8+
return table.concat({ c, (" %s "):format(fname) })
9+
end
10+
11+
local function modified(bufnr, sel)
12+
if vim.api.nvim_buf_get_name(bufnr) == "" then
13+
return ""
14+
end
15+
16+
if not vim.api.nvim_buf_get_option(bufnr, "modified") then
17+
return ""
18+
end
19+
20+
return table.concat({
21+
sel and "" or " ",
22+
sel and "%#TabLineModifiedSel#" or "%#TabLineModified#",
23+
"",
24+
})
25+
end
26+
27+
local function separator(sel)
28+
return table.concat({ sel and "%#TabLineSepSel#" or "%#TabLineSep#", "" })
29+
end
30+
31+
local function draw()
32+
local tabline = {}
33+
34+
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
35+
local sel = tab == vim.api.nvim_get_current_tabpage()
36+
local bufnr = vim.api.nvim_win_get_buf(vim.api.nvim_tabpage_get_win(tab))
37+
local label = { ("%%%dT"):format(vim.api.nvim_tabpage_get_number(tab)) }
38+
table.insert(label, separator(sel))
39+
table.insert(label, title(bufnr, sel))
40+
table.insert(label, modified(bufnr, sel))
41+
table.insert(label, " %#TabLineFill#")
42+
43+
table.insert(tabline, table.concat(label))
44+
end
45+
46+
return table.concat(tabline)
47+
end
48+
49+
return {
50+
draw = draw,
51+
}

0 commit comments

Comments
 (0)