diff options
-rw-r--r-- | README.md | 46 | ||||
-rw-r--r-- | lua/minitab.lua (renamed from lua/minitab/init.lua) | 19 |
2 files changed, 41 insertions, 24 deletions
@@ -1,30 +1,48 @@ # minitab.nvim -Fork of +Minitab is a minimal lua reimplementaion of the tabline render function with +some improvements. +It consists of only ~80 lines of code. + +Minitab started as a fork of [`alvarosevilla95/luatab.nvim`](https://github.com/alvarosevilla95/luatab.nvim) ## Features -* Just a lua rewrite of the tabline render function -* No weird mixing buffers and tabs stuff -* Size/position of tabs doesn't change +* Text only rendering +* Size/position of tabs doesn't change while switching between them +* File paths are not shown +* Smart handling of module files (e.g. `init.lua` => `module/init.lua`) + +## Example bar +` +2 README.md | minitab/init.lua | + [No Name] | ~/docs/src/ | newrw | zsh | TelescopePrompt ` + +The above text demonstrates or less what you can expect from this plugin's +default tabline rendering. ## Install -Using [`lazy.nvim`](https://github.com/folke/lazy.nvim) +Using a [`lazy.nvim`](https://github.com/folke/lazy.nvim) module ```lua return { url = 'https://git.tjkeller.xyz/minitab.nvim', config = true } ``` ## Configuration - -The plugin calls the `helpers.tabline` function to render the line. It uses the other functions defined in `helpers`, such as `cell,separator,devicon`. -You can pass overrides for any of these functions in `setup`. Please see `lua/minitab/init.lua` for details. +The plugin calls the `helpers.tabline` function to render the line. +It uses the other functions and constants defined in `helpers`. +You can pass overrides for any of these in `setup`. +Please see `lua/minitab.lua` for details. Example: -``` -require('minitab').setup{ - title = function() return '' end, - modified = function() return '' end, - windowCount = function() return '' end, - separator = function() return '' end, +```lua +require("minitab").setup{ + modifiedC = "*", + separator = function(index) + local sepC = "><" + if index == 0 then + sepC = "<" + elseif index == vim.fn.tabpagenr('$') + sepC = ">" + end + return '%#TabLine#' .. sepC + end, } ``` diff --git a/lua/minitab/init.lua b/lua/minitab.lua index 22beb44..17acbbf 100644 --- a/lua/minitab/init.lua +++ b/lua/minitab.lua @@ -4,7 +4,7 @@ local M = { modifiedC = "+", } -M.title = function(bufnr, isSelected) +M.title = function(bufnr) local file = vim.fn.simplify(vim.fn.bufname(bufnr)) local tail = vim.fn.fnamemodify(file, ':t') local buftype = vim.fn.getbufvar(bufnr, '&buftype') @@ -30,9 +30,9 @@ M.modified = function(bufnr) end M.windowCount = function(index, hl) - local nwins = #vim.tbl_filter(function(winnr) - return vim.fn.win_gettype(winnr) == "" -- windows will appear or disappear at random when editing files etc for no discernible reason - end, vim.api.nvim_tabpage_list_wins(index)) + local nwins = #vim.tbl_filter(function(bufnr) + return vim.fn.win_gettype(vim.fn.bufwinid(bufnr)) == "" -- windows will appear or disappear at random when editing files etc for no discernible reason + end, vim.fn.tabpagebuflist(index)) return nwins > 1 and '%#TabLineSel#' .. nwins .. hl or "" end @@ -50,20 +50,19 @@ M.cell = function(index) local prefix = M.windowCount(index, hl) .. M.modified(bufnr) .. " " return hl .. '%' .. index .. 'T' .. " " .. (prefix == " " and "" or prefix) .. - M.title(bufnr, isSelected) .. " " .. + M.title(bufnr) .. " " .. M.separator(index) end M.tabline = function() local line = "" + if vim.fn.tabpagenr('$') <= 1 then + return line + end for i = 1, vim.fn.tabpagenr('$'), 1 do line = line .. M.cell(i) end - line = line .. '%#TabLineFill#%=' - if vim.fn.tabpagenr("$") > 1 then - line = line .. '%#TabLine#%999XX' - end - return line + return line .. '%#TabLineFill#%=%#TabLine#%999XX' end local setup = function(opts) |