dotfiles/config/nvim/lua/ruler.lua (view raw)
| 1 | ---@param itms table<string> |
| 2 | local function join(itms) |
| 3 | return vim.iter(itms) |
| 4 | :filter(function(e) return e ~= "" end) |
| 5 | :join " " |
| 6 | end |
| 7 | |
| 8 | local function diagnostics() |
| 9 | local counts = vim.diagnostic.count(vim.api.nvim_get_current_buf()) |
| 10 | local errors = counts[vim.diagnostic.severity.ERROR] or 0 |
| 11 | local warns = counts[vim.diagnostic.severity.WARN] or 0 |
| 12 | local infos = counts[vim.diagnostic.severity.INFO] or 0 |
| 13 | local hints = counts[vim.diagnostic.severity.HINT] or 0 |
| 14 | return join { |
| 15 | errors > 0 and ("%#DiagnosticError# " .. errors .. "%*") or "", |
| 16 | warns > 0 and ("%#DiagnosticWarn# " .. warns .. "%*") or "", |
| 17 | infos > 0 and ("%#DiagnosticInfo# " .. infos .. "%*") or "", |
| 18 | hints > 0 and ("%#DiagnosticHint# " .. hints .. "%*") or "", |
| 19 | } |
| 20 | end |
| 21 | |
| 22 | local function git_diff() |
| 23 | local diff = vim.b.gitsigns_status_dict |
| 24 | if diff == nil then return "" end |
| 25 | return join { |
| 26 | (diff.added ~= nil and diff.added > 0) and ("%#GitSignsAdd#+" .. diff.added .. "%*") or "", |
| 27 | (diff.changed ~= nil and diff.changed > 0) and ("%#GitSignsChange#~" .. diff.changed .. "%*") or "", |
| 28 | (diff.removed ~= nil and diff.removed > 0) and ("%#GitSignsDelete#-" .. diff.removed .. "%*") or "", |
| 29 | } |
| 30 | end |
| 31 | |
| 32 | return function() |
| 33 | return join { git_diff(), diagnostics(), "%m", "%#TabLineSel# %l:%c %*" } |
| 34 | end |