feat: tabline
This commit is contained in:
parent
d4ec924088
commit
804832e0c3
1
init.lua
1
init.lua
@ -21,6 +21,7 @@ require('config.autocmds')
|
||||
require('config.clipboard')
|
||||
require('config.terminal')
|
||||
require('custom.navigation')
|
||||
require('custom.tabline').setup()
|
||||
require('lazy').setup({
|
||||
spec = { { import = 'plugins' } },
|
||||
install = { missing = false },
|
||||
|
||||
86
lua/custom/tabline.lua
Normal file
86
lua/custom/tabline.lua
Normal file
@ -0,0 +1,86 @@
|
||||
-- ~/.config/nvim/lua/custom/tabline.lua
|
||||
-- Custom Lua tabline with proper modified/unsaved and window count handling
|
||||
|
||||
local M = {}
|
||||
|
||||
-- Helper to get label for each tab page
|
||||
local function tab_label(n)
|
||||
local buflist = vim.fn.tabpagebuflist(n)
|
||||
local winnr = vim.fn.tabpagewinnr(n)
|
||||
local bufname = vim.fn.bufname(buflist[winnr])
|
||||
|
||||
if bufname == '' then
|
||||
bufname = '[No Name]'
|
||||
else
|
||||
bufname = vim.fn.fnamemodify(bufname, ':t') -- tail only
|
||||
end
|
||||
|
||||
-- Determine window count reliably
|
||||
local win_count = vim.fn.tabpagewinnr(n, '$')
|
||||
|
||||
-- Check if any buffer in the tab is modified
|
||||
local modified = false
|
||||
for _, buf in ipairs(buflist) do
|
||||
if vim.fn.getbufvar(buf, '&modified') == 1 then
|
||||
modified = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- Construct label according to rules:
|
||||
-- single clean: File
|
||||
-- single edited: +:File
|
||||
-- multi clean: 2:File
|
||||
-- multi edited: 2+:File
|
||||
if win_count == 1 then
|
||||
if modified then
|
||||
bufname = '+:' .. bufname
|
||||
end
|
||||
else
|
||||
local prefix = tostring(win_count)
|
||||
if modified then
|
||||
prefix = prefix .. '+'
|
||||
end
|
||||
bufname = prefix .. ':' .. bufname
|
||||
end
|
||||
|
||||
-- Truncate overly long names
|
||||
if #bufname > 20 then
|
||||
bufname = bufname:sub(1, 17) .. '…'
|
||||
end
|
||||
|
||||
return bufname
|
||||
end
|
||||
|
||||
-- Main tabline builder
|
||||
function M.tabline()
|
||||
local s = ''
|
||||
local num_tabs = vim.fn.tabpagenr('$')
|
||||
|
||||
for i = 1, num_tabs do
|
||||
-- Highlight current tab
|
||||
if i == vim.fn.tabpagenr() then
|
||||
s = s .. '%#TabLineSel#'
|
||||
else
|
||||
s = s .. '%#TabLine#'
|
||||
end
|
||||
|
||||
-- Mouse click target
|
||||
s = s .. '%' .. i .. 'T'
|
||||
|
||||
-- Label
|
||||
s = s .. ' ' .. tab_label(i) .. ' '
|
||||
end
|
||||
|
||||
-- Fill empty space
|
||||
s = s .. '%#TabLineFill#%T'
|
||||
|
||||
return s
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
vim.o.showtabline = 1
|
||||
vim.o.tabline = "%!v:lua.require'custom.tabline'.tabline()"
|
||||
end
|
||||
|
||||
return M
|
||||
@ -12,9 +12,13 @@ return {
|
||||
highlights = function(c, tool)
|
||||
c.bg_float = tool(152)
|
||||
return {
|
||||
ModeMsg = { fg = c.yellow, bg = c.none, bold = true },
|
||||
WinSeparator = { fg = c.outline, bg = c.base },
|
||||
StatusLine = { fg = c.outline, bg = c.base },
|
||||
StatusLineNC = { fg = c.text, bg = c.base, bold = true },
|
||||
TabLine = { fg = c.muted, bg = c.none },
|
||||
TabLineSel = { fg = c.text, bg = c.none, bold = true },
|
||||
TabLineFill = { fg = c.outline_light, bg = c.none },
|
||||
}
|
||||
end,
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user