local api = vim.api Statusline = { active = '', inactive = '', } -- highlight groups local colors = { active = '%#StatusLine#', inactive = '%#StatuslineNC#', mode = '%#Mode#', mode_alt = '%#ModeAlt#', git = '%#Git#', git_alt = '%#GitAlt#', filetype = '%#Filetype#', filetype_alt = '%#FiletypeAlt#', line_col = '%#LineCol#', line_col_alt = '%#LineColAlt#', } Statusline.get_filetype = function() local filetype = vim.bo.filetype if filetype == '' then return '' end return string.format('%s', filetype):lower() end local add_active = function(text) Statusline.active = Statusline.active .. text end local add_inactive = function(text) Statusline.inactive = Statusline.inactive .. text end local addl_active = function(func) Statusline.active = Statusline.active .. '%{v:lua.' .. func .. '}' end local addl_inactive = function(func) Statusline.inactive = Statusline.inactive .. '%{v:lua.' .. func .. '}' end add_active('[') addl_active('vim.api.nvim_get_mode().mode') add_active(']') add_active(' ') add_active('%<%f') add_active(' ') add_active('%m%r%q') add_active(' ') addl_active('Statusline.get_filetype()') add_active('%=') addl_active('require("nvim-navic").get_location()') add_active(' ') add_active('%l:%c') add_active(' ') add_inactive(colors.inactive .. '%F') local augroup = api.nvim_create_augroup('Statusline', { clear = true}) api.nvim_create_autocmd({"WinEnter", "BufEnter"}, { callback = function() vim.wo.statusline = Statusline.active end, group = augroup }) api.nvim_create_autocmd({"WinLeave", "BufLeave"}, { callback = function() vim.wo.statusline = Statusline.inactive end, group = augroup }) ----[[ -- NOTE: I don't use this since the statusline already has -- so much stuff going on. Feel free to use it! -- credit: https://github.com/nvim-lua/lsp-status.nvim -- -- I now use `tabline` to display these errors, go to `_bufferline.lua` if you -- want to check that out ----]] -- Statusline.get_lsp_diagnostic = function(self) -- local result = {} -- local levels = { -- errors = 'Error', -- warnings = 'Warning', -- info = 'Information', -- hints = 'Hint' -- } -- for k, level in pairs(levels) do -- result[k] = vim.lsp.diagnostic.get_count(0, level) -- end -- if self:is_truncated(120) then -- return '' -- else -- return string.format( -- "| :%s :%s :%s :%s ", -- result['errors'] or 0, result['warnings'] or 0, -- result['info'] or 0, result['hints'] or 0 -- ) -- end -- end -- --local get_git_status = function() ---- use fallback because it doesn't set this variable on the initial `BufEnter` --local signs = vim.b.gitsigns_status_dict or {head = '', added = 0, changed = 0, removed = 0} --local is_head_empty = signs.head ~= '' -- --if is_truncated(trunc_width.git_status) then --return is_head_empty and string.format('  %s ', signs.head or '') or '' --end -- --return is_head_empty and string.format( --' +%s ~%s -%s |  %s ', --signs.added, signs.changed, signs.removed, signs.head --) or '' --end