tamton-aquib / staline.nvim

A modern lightweight statusline and bufferline plugin for neovim in lua.
MIT License
380 stars 17 forks source link

[stabline] [FEAT]: Add tab index #62

Open bogdan-the-great opened 8 months ago

bogdan-the-great commented 8 months ago

Make bufferline (stabline) to have a tab indicator at the right side, where it would show current tab number and other tabs like buffers dimmed. Basically make it look like in nvim-bufbar or in bufferline.nvim. Would be nice to show only numbers when there are more than one tabs in the session.

I think that it would make the stabline more complete and useful with this update.

Screenshot: image

tamton-aquib commented 8 months ago

Adding that should be simple but the styling is whats difficult 😅. But I'll try to do it this weekend.

Meanwhile you could try something with stab_end temporarily, for example:

require("stabline").setup({ stab_end="%{tabpagenr()}" })
bogdan-the-great commented 8 months ago

An example solution from nvim-bufbar:

local function get_tabs()
    local tabs = {}
    local current_tab = fn.tabpagenr()

    for _, tabinfo in ipairs(fn.gettabinfo()) do
        local tab = {
            tabnr = tabinfo.tabnr,
            current = tabinfo.tabnr == current_tab,
        }

        table.insert(tabs, tab)
    end

    return tabs
end

...
    if M.options.show_tabs then
        local tabs, tablist = get_tabs(), {}

        for _, tab in ipairs(tabs) do
            local level = tab.current and 'active' or 'inactive'
            local tabname = set_hlgroup(fmt(' %d ', tab.tabnr), 'tabs', level)

            table.insert(tablist, tabname)
        end

        table.insert(bufferline, table.concat(tablist, separator))
    end
...