diff --git a/nvim/.config/nvim/lua/DarthMooMancer/ui.lua b/nvim/.config/nvim/lua/DarthMooMancer/ui.lua index 66a2cc4..51ae6f7 100644 --- a/nvim/.config/nvim/lua/DarthMooMancer/ui.lua +++ b/nvim/.config/nvim/lua/DarthMooMancer/ui.lua @@ -63,10 +63,10 @@ local mode_map = { i = ' INS ', v = ' VIS ', V = ' V-LINE ', - ['^V'] = ' V-BLK ', + ['\22'] = ' V-BLK ', + ['\19'] = ' V-BLK ', s = ' VIS ', S = ' V-LINE ', - ['^S'] = ' V-BLK ', R = ' REPL ', c = ' CMD ', r = ' PROMPT ', @@ -122,9 +122,9 @@ end --- LSP: one icon, three states. local lsp_icon = { - none = ' ', - working = ' ', - ready = ' ', + none = '  ', + working = ' 󰄬 ', + ready = ' 󰄭 ', } local lsp_hl = { none = 'StatusLspNone', @@ -145,10 +145,10 @@ local function refresh_lsp(buf) break end end - vim.b[buf].lsp_icon = lsp_icon[state] - vim.b[buf].lsp_hl = lsp_hl[state] - refresh_status(buf) end + vim.b[buf].lsp_icon = lsp_icon[state] + vim.b[buf].lsp_hl = lsp_hl[state] + refresh_status(buf) end vim.api.nvim_create_autocmd({ 'LspAttach', 'LspDetach' }, { @@ -180,7 +180,7 @@ local function refresh_branch(buf) vim.system( { 'git', 'branch', '--show-current' }, { text = true }, - function(out) + vim.schedule_wrap(function(out) if not vim.api.nvim_buf_is_valid(buf) then return end @@ -189,7 +189,7 @@ local function refresh_branch(buf) '' ) refresh_status(buf) - end + end) ) end @@ -201,7 +201,7 @@ local function refresh_diff(buf) vim.system( { 'git', 'diff', '--numstat', 'HEAD', '--', file }, { text = true }, - function(out) + vim.schedule_wrap(function(out) if not vim.api.nvim_buf_is_valid(buf) then return end @@ -215,10 +215,33 @@ local function refresh_diff(buf) } end refresh_status(buf) - end + end) ) end +local function refresh_diag(buf) + local count = vim.diagnostic.count(buf) + local sev = vim.diagnostic.severity + local parts = {} + if (count[sev.ERROR] or 0) > 0 then + parts[#parts + 1] = '%#StatusDiagError# E' .. count[sev.ERROR] .. ' %*' + end + if (count[sev.WARN] or 0) > 0 then + parts[#parts + 1] = '%#StatusDiagWarn# W' .. count[sev.WARN] .. ' %*' + end + if (count[sev.HINT] or 0) > 0 then + parts[#parts + 1] = '%#StatusDiagHint# H' .. count[sev.HINT] .. ' %*' + end + vim.b[buf].diag_str = #parts > 0 and table.concat(parts) or '' + refresh_status(buf) +end + +vim.api.nvim_create_autocmd('DiagnosticChanged', { + callback = function(ev) + refresh_diag(ev.buf) + end, +}) + vim.api.nvim_create_autocmd({ 'BufEnter', 'BufNewFile' }, { callback = function(ev) if vim.bo[ev.buf].buftype == '' then @@ -243,29 +266,6 @@ vim.api.nvim_create_autocmd('BufWritePost', { end, }) ---- Diagnostics: counted on change, never during a redraw. -local function refresh_diag(buf) - local count = vim.diagnostic.count(buf) - local parts = {} - if count.error > 0 then - parts[#parts + 1] = '%#StatusDiagError# E' .. count.error .. ' %*' - end - if count.warn > 0 then - parts[#parts + 1] = '%#StatusDiagWarn# W' .. count.warn .. ' %*' - end - if count.hint > 0 then - parts[#parts + 1] = '%#StatusDiagHint# H' .. count.hint .. ' %*' - end - vim.b[buf].diag_str = #parts > 0 and table.concat(parts) or '' - refresh_status(buf) -end - -vim.api.nvim_create_autocmd('DiagnosticChanged', { - callback = function(ev) - refresh_diag(ev.buf) - end, -}) - --- Macro: read once when recording starts, not on every redraw. vim.api.nvim_create_autocmd('RecordingEnter', { pattern = '*', @@ -284,10 +284,8 @@ vim.api.nvim_create_autocmd('RecordingLeave', { }) function _G.__statusline() - local key = vim.fn.mode():sub(1, 2) - if key ~= '^V' and key ~= '^S' then - key = key:sub(1, 1) - end + local m = vim.fn.mode() + local key = (m == '\22' or m == '\19') and m or m:sub(1, 1) local hl = mode_hl_map[key] or 'StatusModeNormal' local b = vim.b return table.concat({