|
| 1 | +local function title(bufnr, sel) |
| 2 | + local bufname = vim.api.nvim_buf_get_name(bufnr) |
| 3 | + local fname = bufname ~= "" and vim.fn.fnamemodify(bufname, ":t") or "[EMPTY]" |
| 4 | + local c = "%#TabLine#" |
| 5 | + if sel then |
| 6 | + c = "%#TabLineSel#" |
| 7 | + end |
| 8 | + return table.concat({ c, (" %s "):format(fname) }) |
| 9 | +end |
| 10 | + |
| 11 | +local function modified(bufnr, sel) |
| 12 | + if vim.api.nvim_buf_get_name(bufnr) == "" then |
| 13 | + return "" |
| 14 | + end |
| 15 | + |
| 16 | + if not vim.api.nvim_buf_get_option(bufnr, "modified") then |
| 17 | + return "" |
| 18 | + end |
| 19 | + |
| 20 | + return table.concat({ |
| 21 | + sel and "" or " ", |
| 22 | + sel and "%#TabLineModifiedSel#" or "%#TabLineModified#", |
| 23 | + "●", |
| 24 | + }) |
| 25 | +end |
| 26 | + |
| 27 | +local function separator(sel) |
| 28 | + return table.concat({ sel and "%#TabLineSepSel#" or "%#TabLineSep#", "▏" }) |
| 29 | +end |
| 30 | + |
| 31 | +local function draw() |
| 32 | + local tabline = {} |
| 33 | + |
| 34 | + for _, tab in ipairs(vim.api.nvim_list_tabpages()) do |
| 35 | + local sel = tab == vim.api.nvim_get_current_tabpage() |
| 36 | + local bufnr = vim.api.nvim_win_get_buf(vim.api.nvim_tabpage_get_win(tab)) |
| 37 | + local label = { ("%%%dT"):format(vim.api.nvim_tabpage_get_number(tab)) } |
| 38 | + table.insert(label, separator(sel)) |
| 39 | + table.insert(label, title(bufnr, sel)) |
| 40 | + table.insert(label, modified(bufnr, sel)) |
| 41 | + table.insert(label, " %#TabLineFill#") |
| 42 | + |
| 43 | + table.insert(tabline, table.concat(label)) |
| 44 | + end |
| 45 | + |
| 46 | + return table.concat(tabline) |
| 47 | +end |
| 48 | + |
| 49 | +return { |
| 50 | + draw = draw, |
| 51 | +} |
0 commit comments