local M = {} local modes = { n = { "NORMAL", "StatuslineModeNormal" }, i = { "INSERT", "StatuslineModeInsert" }, v = { "VISUAL", "StatuslineModeVisual" }, V = { "V-LINE", "StatuslineModeVisual" }, [""] = { "V-BLOCK", "StatuslineModeVisual" }, R = { "REPLACE", "StatuslineModeReplace" }, c = { "COMMAND", "StatuslineModeCommand" }, } local function mode() local m = vim.fn.mode() local entry = modes[m] or { m, "StatusLine" } return string.format("%%#%s# %s %%#StatusLine#", entry[2], entry[1]) end ---------------------------------------------------------------------- -- Statusline-Sektionen (reine Darstellung, keine IO) ---------------------------------------------------------------------- -- Git-Branch (gitsigns setzt vim.b.gitsigns_head asynchron pro Buffer) local function git() local head = vim.b.gitsigns_head if not head or head == "" then return "" end return "  " .. head .. " " end -- Git-Diff (buffer-lokal, kein redraw-spam) local function git_diff() local gsd = vim.b.gitsigns_status_dict if not gsd then return "" end local parts = {} if gsd.added and gsd.added > 0 then table.insert(parts, "+" .. gsd.added) end if gsd.changed and gsd.changed > 0 then table.insert(parts, "~" .. gsd.changed) end if gsd.removed and gsd.removed > 0 then table.insert(parts, "-" .. gsd.removed) end if #parts > 0 then return " " .. table.concat(parts, " ") .. " " end return "" end ------------------------------------------------------------------------ -- Treesitter-Aktivität (buffer-lokal, kein redraw-spam) ------------------------------------------------------------------------ local function treesitter() local ok = vim.treesitter.highlighter.active[vim.api.nvim_get_current_buf()] if ok then return " 🌳 " end return "" end ------------------------------------------------------------------------ -- LSP-Clients des Buffers ------------------------------------------------------------------------ local function lsp() local clients = vim.lsp.get_clients({ bufnr = 0 }) if #clients == 0 then return "" end local names = {} for _, client in ipairs(clients) do table.insert(names, client.name) end return " " .. table.concat(names, ", ") .. " " end ------------------------------------------------------------------------ -- Diagnostik-Counts (buffer-lokal, kein redraw-spam) ------------------------------------------------------------------------ local function diagnostics() local counts = { error = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }), warn = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }), info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }), hint = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }), } local parts = {} if counts.error > 0 then table.insert(parts, "  " .. counts.error) end if counts.warn > 0 then table.insert(parts, "  " .. counts.warn) end if counts.info > 0 then table.insert(parts, "  " .. counts.info) end if counts.hint > 0 then table.insert(parts, "  " .. counts.hint) end if #parts > 0 then return " " .. table.concat(parts, " ") .. " " end return "" end ------------------------------------------------------------------------ -- Filetype & Encoding (buffer-lokal, kein redraw-spam) ------------------------------------------------------------------------ local function fileinfo() local ft = vim.bo.filetype ~= "" and vim.bo.filetype or "none" local enc = vim.bo.fileencoding ~= "" and vim.bo.fileencoding or vim.o.encoding return string.format(" %s %s ", ft, enc) end ---------------------------------------------------------------------- -- Öffentliche Statusline-Funktion ---------------------------------------------------------------------- function M.statusline() return table.concat({ -- LEFT: Mode & Context mode(), "%#PmenuSel#", git(), git_diff(), "%#StatusLine#", -- %f Dateiname, %m Modifikationsstatus; %(..%) faellt weg, wenn %m leer ist " %f%( %m%) ", "%=", -- RIGHT: Feedback & Meta diagnostics(), lsp(), treesitter(), fileinfo(), " %p%% ", " %l:%c ", }) end return M