nanozuki / tabby.nvim

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

[Bug]? line.tabs().foreach(function(tab) .. returns no tabs when only 1 tab? #151

Closed Ajaymamtora closed 2 months ago

Ajaymamtora commented 2 months ago

This is my setup where no tabline is drawn when I have 1 tab:

Is there any way around this? It wasn't an issue with the old config when looping over tabs manually

  tabby.setup({
    line = function(line)
      return {
        {
          { " " .. icons.common.vim2 .. " ", hl = { bg = colours.tabbar_bg, fg = colours.icons_fg, style = "bold" } },
          line.sep("", { fg = colours.icons_bg, bg = colours.tabbar_bg, style = "bold" }, colours.tabbar_bg),
        },
        -- Windows in current tab
        (function()
          local wins = tabby_api.get_tab_wins(vim.api.nvim_get_current_tabpage())
          local components = {}
          for _, win_id in ipairs(wins) do
            local buf = vim.api.nvim_win_get_buf(win_id)
            local ft = vim.api.nvim_buf_get_option(buf, "filetype")
            if not vim.tbl_contains(exclude, ft) then
              local is_current = win_id == vim.api.nvim_get_current_win()
              local hl = is_current
                  and {
                    bg = colours.current_single_tab_bg,
                    fg = colours.current_single_tab_fg,
                    style = "bold",
                  }
                or {
                  bg = colours.inactive_single_tab_bg,
                  fg = colours.inactive_single_tab_fg,
                }
              local buf_name = vim.fn.fnamemodify(tabby_filename.unique(win_id), ":t")
              local file_icon, file_icon_color = get_file_icon(buf_name)
              table.insert(components, line.sep("", hl, colours.tabbar_bg))
              table.insert(components, { is_current and "" or "", hl = hl })
              table.insert(components, { " " .. file_icon .. " ", hl = { fg = file_icon_color, bg = hl.bg } })
              table.insert(components, { buf_name, hl = hl })
              table.insert(components, { vim.bo[buf].modified and " * " or " ", hl = hl })
              table.insert(components, line.sep("", hl, colours.tabbar_bg))
            end
          end
          return components
        end)(),
        line.spacer(),
        -- Tab groups
        (function()
          local tabs = line.tabs().foreach(function(tab)
            local hl = tab.is_current()
                and {
                  bg = colours.current_group_tab_bg,
                  fg = colours.current_group_tab_fg,
                  style = "bold",
                }
              or {
                bg = colours.inactive_group_tab_bg,
                fg = colours.inactive_group_tab_fg,
              }
            local tab_icon = get_tab_group_icon(tab.id)
            return {
              line.sep("", hl, colours.tabbar_bg),
              tab_icon and (" " .. tab_icon) or "",
              (tab_icon and "" or " ") .. tab.name() .. " ",
              hl = hl,
              line.sep("", hl, colours.tabbar_bg),
            }
          end)

          -- Always show at least one tab
          if #tabs == 0 then
            local current_tab = vim.api.nvim_get_current_tabpage()
            local hl = {
              bg = colours.current_group_tab_bg,
              fg = colours.current_group_tab_fg,
              style = "bold",
            }
            local tab_name = "Tab " .. current_tab
            local tab_icon = get_tab_group_icon(current_tab)
            table.insert(tabs, {
              line.sep("", hl, colours.tabbar_bg),
              tab_icon and (" " .. tab_icon) or "",
              (tab_icon and "" or " ") .. tab_name .. " ",
              hl = hl,
              line.sep("", hl, colours.tabbar_bg),
            })
          end

          return tabs
        end)(),
        hl = { bg = colours.tabbar_bg },
      }
    end,
  })
nanozuki commented 2 months ago

Not a bug, this behavior is controlled by neovim's option showtabline. Tabby V2 step back, not to touch this option to give users more control.

You can see more detail in neovim manual, :help showtabline