CHORE: Fixed bugs in statusbar
This commit is contained in:
@@ -63,10 +63,10 @@ local mode_map = {
|
|||||||
i = ' INS ',
|
i = ' INS ',
|
||||||
v = ' VIS ',
|
v = ' VIS ',
|
||||||
V = ' V-LINE ',
|
V = ' V-LINE ',
|
||||||
['^V'] = ' V-BLK ',
|
['\22'] = ' V-BLK ',
|
||||||
|
['\19'] = ' V-BLK ',
|
||||||
s = ' VIS ',
|
s = ' VIS ',
|
||||||
S = ' V-LINE ',
|
S = ' V-LINE ',
|
||||||
['^S'] = ' V-BLK ',
|
|
||||||
R = ' REPL ',
|
R = ' REPL ',
|
||||||
c = ' CMD ',
|
c = ' CMD ',
|
||||||
r = ' PROMPT ',
|
r = ' PROMPT ',
|
||||||
@@ -122,9 +122,9 @@ end
|
|||||||
|
|
||||||
--- LSP: one icon, three states.
|
--- LSP: one icon, three states.
|
||||||
local lsp_icon = {
|
local lsp_icon = {
|
||||||
none = ' <U+F0374> ',
|
none = ' ',
|
||||||
working = ' <U+F012C> ',
|
working = ' ',
|
||||||
ready = ' <U+F012D> ',
|
ready = ' ',
|
||||||
}
|
}
|
||||||
local lsp_hl = {
|
local lsp_hl = {
|
||||||
none = 'StatusLspNone',
|
none = 'StatusLspNone',
|
||||||
@@ -145,10 +145,10 @@ local function refresh_lsp(buf)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
vim.b[buf].lsp_icon = lsp_icon[state]
|
|
||||||
vim.b[buf].lsp_hl = lsp_hl[state]
|
|
||||||
refresh_status(buf)
|
|
||||||
end
|
end
|
||||||
|
vim.b[buf].lsp_icon = lsp_icon[state]
|
||||||
|
vim.b[buf].lsp_hl = lsp_hl[state]
|
||||||
|
refresh_status(buf)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd({ 'LspAttach', 'LspDetach' }, {
|
vim.api.nvim_create_autocmd({ 'LspAttach', 'LspDetach' }, {
|
||||||
@@ -180,7 +180,7 @@ local function refresh_branch(buf)
|
|||||||
vim.system(
|
vim.system(
|
||||||
{ 'git', 'branch', '--show-current' },
|
{ 'git', 'branch', '--show-current' },
|
||||||
{ text = true },
|
{ text = true },
|
||||||
function(out)
|
vim.schedule_wrap(function(out)
|
||||||
if not vim.api.nvim_buf_is_valid(buf) then
|
if not vim.api.nvim_buf_is_valid(buf) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -189,7 +189,7 @@ local function refresh_branch(buf)
|
|||||||
''
|
''
|
||||||
)
|
)
|
||||||
refresh_status(buf)
|
refresh_status(buf)
|
||||||
end
|
end)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ local function refresh_diff(buf)
|
|||||||
vim.system(
|
vim.system(
|
||||||
{ 'git', 'diff', '--numstat', 'HEAD', '--', file },
|
{ 'git', 'diff', '--numstat', 'HEAD', '--', file },
|
||||||
{ text = true },
|
{ text = true },
|
||||||
function(out)
|
vim.schedule_wrap(function(out)
|
||||||
if not vim.api.nvim_buf_is_valid(buf) then
|
if not vim.api.nvim_buf_is_valid(buf) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -215,10 +215,33 @@ local function refresh_diff(buf)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
refresh_status(buf)
|
refresh_status(buf)
|
||||||
end
|
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' }, {
|
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufNewFile' }, {
|
||||||
callback = function(ev)
|
callback = function(ev)
|
||||||
if vim.bo[ev.buf].buftype == '' then
|
if vim.bo[ev.buf].buftype == '' then
|
||||||
@@ -243,29 +266,6 @@ vim.api.nvim_create_autocmd('BufWritePost', {
|
|||||||
end,
|
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.
|
--- Macro: read once when recording starts, not on every redraw.
|
||||||
vim.api.nvim_create_autocmd('RecordingEnter', {
|
vim.api.nvim_create_autocmd('RecordingEnter', {
|
||||||
pattern = '*',
|
pattern = '*',
|
||||||
@@ -284,10 +284,8 @@ vim.api.nvim_create_autocmd('RecordingLeave', {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function _G.__statusline()
|
function _G.__statusline()
|
||||||
local key = vim.fn.mode():sub(1, 2)
|
local m = vim.fn.mode()
|
||||||
if key ~= '^V' and key ~= '^S' then
|
local key = (m == '\22' or m == '\19') and m or m:sub(1, 1)
|
||||||
key = key:sub(1, 1)
|
|
||||||
end
|
|
||||||
local hl = mode_hl_map[key] or 'StatusModeNormal'
|
local hl = mode_hl_map[key] or 'StatusModeNormal'
|
||||||
local b = vim.b
|
local b = vim.b
|
||||||
return table.concat({
|
return table.concat({
|
||||||
|
|||||||
Reference in New Issue
Block a user