local highlight = require("rc.highlight") local line = require("rc.line") local ui = require("rc.ui") ---@return string local function overseer_info() local result = "" if not package.loaded.overseer then return result end local tasks = require("overseer.task_list").list_tasks({ unique = true }) local tasks_by_status = require("overseer.util").tbl_group_by(tasks, "status") for status, symbol in pairs(ui.status) do status = status:upper() local task = tasks_by_status[status] if task then result = result .. line.with_hl( symbol .. " " .. #task, highlight.ensure("TabLineOverseer" .. status, function() return highlight.get("Overseer" .. status):extend("TabLineFill") end) ) .. " " end end return result end ---@param buf integer ---@return boolean local function is_modified(buf) return vim.api.nvim_get_option_value("modified", { buf = buf }) end ---@param buffer integer ---@param is_selected boolean ---@return string local function buffer_info(buffer, is_selected) local bufname = vim.api.nvim_buf_get_name(buffer) local hl_suffix = is_selected and "Sel" or "" local hl_group = "TabLine" .. hl_suffix local t = "" local sep_hl = highlight.ensure("TabLineSep", function() return highlight.get("TabLineFill"):extend(highlight.get("Normal"):reverse():clear_bg()) end) if is_selected then t = t .. line.with_hl("", sep_hl.name) end t = t .. line.with_hl((is_selected and " " or " "), hl_group) t = t .. line.with_hl(" " .. vim.fs.basename(bufname) .. " ", hl_group) if is_modified(buffer) then t = t .. line.with_hl( "" .. (is_selected and "" or " "), highlight.ensure("TabLineModified" .. hl_suffix, function() return highlight.get("Function"):extend(hl_group) end) ) else t = t .. line.with_hl(" ", hl_group) end t = t .. line.with_hl(is_selected and " " or "", hl_group) if is_selected then t = t .. line.with_hl("", sep_hl) end return t end ---@param buffer integer local function filter_buffer(buffer) return vim.api.nvim_buf_is_loaded(buffer) and vim.api.nvim_get_option_value("buflisted", { buf = buffer }) and vim.api.nvim_buf_get_name(buffer) ~= "" end ---@return string local function get_tabline() local current_buf = vim.api.nvim_get_current_buf() local tabline = vim.iter(vim.api.nvim_list_bufs()) :filter(filter_buffer) :map(function(buf) return buffer_info(buf, buf == current_buf) end) :join("") tabline = tabline .. "%=" .. overseer_info() return tabline end local M = {} function M.setup() vim.o.showtabline = 2 vim.o.tabline = line.as_opt(get_tabline) vim.api.nvim_create_autocmd({ "BufAdd", "BufDelete" }, { command = "redrawtabline" }) end return M