Summary Files Commits Branches @commit @diff @stats
path: root / lua / plugins / heirline.lua
diff options
context:
space:
mode:
Commit5166d3842f613c710d168985259ffcdc09813942 (patch)
Author
 Syndamia <kamen@syndamia.com>
2024-08-06 15:29:29 +0300
Committer
 Syndamia <kamen@syndamia.com>
2024-08-06 15:29:29 +0300
Files862b8390f093bd651daf5c4227fc1610eb6140c6 /lua/plugins/heirline.lua
anderson-5166d3842f613c710d168985259ffcdc09813942.tar
anderson-5166d3842f613c710d168985259ffcdc09813942.tar.gz
anderson-5166d3842f613c710d168985259ffcdc09813942.zip
Parent082efd84bbcc2344ec82fd339c9a8addbae49fbe (diff)
feat(heirline): Implemented vim tabline
1 files changed, 95 insertions, 1 deletions
-rw-r--r--lua/plugins/heirline.lua96
diff --git a/lua/plugins/heirline.lua b/lua/plugins/heirline.lua
index 00e0ca7..dcd7e7d 100644
--- a/lua/plugins/heirline.lua
+++ b/lua/plugins/heirline.lua
@@ -58,6 +58,11 @@ return {
}
end
+ function set_hl(name, val)
+ vim.api.nvim_set_hl(0, name, val)
+ return val
+ end
+
--[=[ Common elements ]=]--
local FileStat = {
@@ -159,10 +164,99 @@ return {
CursorChar, RightSep, FileType, Space, LineAndColumn
}
- --[=[ Setup ]=]--
+ --[=[ Tabline ]=]--
+ local hl_TabLine = set_hl("TabLine", { ctermfg = 252, ctermbg = 242 })
+ local hl_TabLineSel = set_hl("TabLineSel", { ctermfg = 252, ctermbg = 235 })
+ local hl_TabLineFill = set_hl("TabLineFill", { ctermfg = 248, ctermbg = 238 })
+ set_hl("TabLineRFR", { ctermfg = hl_TabLine.ctermbg, ctermbg = hl_TabLineFill.ctermbg }) -- nonactive Right Full, Rightmost
+ set_hl("TabLineSelRF", { ctermfg = hl_TabLineSel.ctermbg, ctermbg = hl_TabLine.ctermbg }) -- active Right Full
+ set_hl("TabLineSelRFR", { ctermfg = hl_TabLineSel.ctermbg, ctermbg = hl_TabLineFill.ctermbg }) -- active Right Full, Rightmost
+ set_hl("TabLineSelLF", { ctermfg = hl_TabLine.ctermbg, ctermbg = hl_TabLineSel.ctermbg }) -- active Left Full (left one's Right Full)
+
+ local TabPage = {
+ init = function(self)
+ self.pages = vim.api.nvim_list_tabpages()
+ end,
+ {
+ static = {
+ get_icon = require("nvim-web-devicons").get_icon,
+ ft_icon = require("nvim-web-devicons").get_icon_by_filetype,
+ none_icon = "",
+ },
+ init = function(self)
+ self.bufnr = vim.api.nvim_win_get_buf(vim.api.nvim_tabpage_get_win(self.tabpage))
+ end,
+ provider = function(self)
+ --[==[ Filename ]==]--
+ local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(self.bufnr), ":t")
+ if #filename == 0 then filename = "[No Name]" end
+
+ local max_name_len = vim.o.columns / (5 + #self.pages)
+ filename = (self.get_icon(filename, vim.fn.fnamemodify(filename, ":e")) or self.ft_icon(vim.bo[self.bufnr].filetype) or self.none_icon) ..
+ " " .. string.sub(filename, 1, max_name_len)
+
+ --[==[ Readonly ]==]--
+ local readonly = vim.bo[self.bufnr].readonly and " " or ""
+ --[==[ Modification ]==]--
+ local mod = vim.bo[self.bufnr].modified and " "
+ or (vim.bo[self.bufnr].modifiable and "" or " ")
+
+ --[==[ Tab ]==]--
+ return
+ "%" .. self.tabnr .. "T" ..
+ " " ..
+ filename .. readonly .. mod ..
+ " "
+ end,
+ hl = function(self)
+ if not self.is_active then
+ return "TabLine"
+ else
+ return "TabLineSel"
+ end
+ end,
+ },
+ {
+ init = function(self)
+ local activenr = vim.api.nvim_tabpage_get_number(vim.api.nvim_get_current_tabpage())
+
+ self.dist = self.tabnr - activenr
+ self.last = self.tabnr == #self.pages
+ end,
+ provider = function(self)
+ return (self.last or self.dist == -1 or self.dist == 0)
+ and delimiters.FilledCircle[2] or delimiters.Circle[2]
+ end,
+ hl = function(self)
+ if not self.is_active then
+ return self.last and "TabLineRFR" or (self.dist == -1 and "TabLineSelLF" or "TabLine")
+ else
+ return self.last and "TabLineSelRFR" or "TabLineSelRF"
+ end
+ end,
+ },
+ {
+ provider = "%T"
+ }
+ }
+
+ local TabPages = {
+ -- only show this component if there's 2 or more tabpages
+ condition = function()
+ return #vim.api.nvim_list_tabpages() >= 2
+ end,
+ utils.make_tablist(TabPage),
+ }
+
+ local TabLine = {
+ TabPages,
+ }
+
+ --[=[ Setup ]=]--
return {
statusline = StatusLine,
+ tabline = TabLine,
}
end,
}