nanozuki / tabby.nvim

A declarative, highly configurable, and neovim style tabline plugin. Use your nvim tabs as a workspace multiplexer!
MIT License
577 stars 21 forks source link

Have buffers inside the tabline #27

Closed is0n closed 2 years ago

is0n commented 2 years ago

I know that in the README, tabby.nvim is not supposed to be a buffers list but it also says that it is possible with low-level api...

Tabby.nvim focuses on a vim-style tab instead of buffers list, so tabby only displays the buffers in tabpage(although you can use low-level API to write a bufferline)

What would the configuration for this look like (assuming it's possible)?

Here's my config btw...

local filename = require('tabby.filename')
local util = require('tabby.util')

local hl_tabline = util.extract_nvim_hl('TabLine')
local hl_normal = util.extract_nvim_hl('Normal')
local hl_tabline_sel = util.extract_nvim_hl('TabLineSel')

local active_tab_hl = { fg = hl_normal.fg, bg = hl_normal.bg, style = 'bold' }
local inactive_tab_hl = { fg = hl_tabline.fg, bg = hl_tabline.bg }

local tabline = {
  hl = 'TabLineFill',
  layout = 'active_wins_at_tail',
  head = {
      { '    ', hl = { fg = hl_tabline_sel.fg, bg = hl_tabline_sel.bg, style = 'bold' } },
      { ' ', hl = 'TabLineFill' }
  },
  active_tab = {
    label = function(tabid)
      return {
        '    ' .. tabid .. '  ',
        hl = active_tab_hl,
      }
    end,
  },
  inactive_tab = {
    label = function(tabid)
      return {
        '    ' .. tabid .. '  ',
        hl = inactive_tab_hl,
      }
    end,
  },
  top_win = {
    label = function(winid)
      return {
          '  ' .. filename.unique(winid) .. ' ',
        hl = active_tab_hl
      }
    end,
    left_sep = { ' ', hl = 'TabLineFill' },
  },
  win = {
    label = function(winid)
      return {
          '  ' .. filename.unique(winid) .. ' ',
        hl = 'TabLine',
      }
    end,
    left_sep = { ' ', hl = 'TabLineFill' },
    },
}

require('tabby').setup{
    tabline = tabline,
}
nanozuki commented 2 years ago

Yes, you can set a buffer line by tabby.nvim. But you can only use low level API to make it, because the layout of high level is fixed. Here is a simple example:

local components = function()
  local coms = {}
  local cur_bufid = vim.api.nvim_get_current_buf()
  for _, bufid in ipairs(vim.api.nvim_list_bufs()) do
    if vim.api.nvim_buf_is_valid(bufid) and vim.bo[bufid].buflisted then
      local hl = 'TabLine'
      if bufid == cur_bufid then
        hl = 'TabLineSel'
      end
      local buf_name = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufid), ':~:.')
      table.insert(coms, {
        type = 'text',
        text = {
          string.format(' %d: %s ', bufid, buf_name),
          hl = hl,
        },
      })
      table.insert(coms, {
        type = 'text',
        text = {
          ' ',
          hl = 'TabLineFill',
        },
      })
    end
  end
  return coms
end
require('tabby').setup({
  components = components,
})
image
nanozuki commented 2 years ago

But for now, the customer handler of mouse click not implemented(in TODO list). So cannot click buffer label to switch buffer yet.

is0n commented 2 years ago

How could I put the buffers at the tail of my config?

nanozuki commented 2 years ago

You can put a separator in the front of the components array.

{ type = "spring" }

and the buffer labels will be pushed to the end.

Do you mind I covert this issue to a discussion? I think this may be helping other users.

is0n commented 2 years ago

You can put a separator in the front of the components array.

Could you be a bit more specific?

Do you mind I covert this issue to a discussion? I think this may be helping other users.

I think that's a great idea :D