diff options
| author | Robert Günzler <r@gnzler.io> | 2021-08-30 18:17:16 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2021-08-31 12:41:19 +0200 |
| commit | 8bca81886ab94963531b77b96b37c9f1fea20583 (patch) | |
| tree | 390bf7a88ef6ae2da4d20c4c37504949daa5953a /.vim/init.lua | |
| parent | b3fe31ba9fadba18538b4dfff8afcc83d049ff27 (diff) | |
vim: add colors to statusline
Diffstat (limited to '.vim/init.lua')
| -rw-r--r-- | .vim/init.lua | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/.vim/init.lua b/.vim/init.lua index 9016baf..ac7eb9e 100644 --- a/.vim/init.lua +++ b/.vim/init.lua @@ -117,28 +117,37 @@ require('spinner').setup { spinner = {'⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'}, interval = 120, -- spinner frame rate in ms } -statusline = function() +function _G.statusline() + local hi = statusline_color(vim.fn.mode()) + local sl = '' -- left - sl = sl .. statusline_color(vim.fn.mode()) - sl = sl .. [[ ⢷ %<%F %-m %-r ]] + sl = sl .. hi + sl = sl .. statusline_hi(' ⢷', '%#StatusLineIcon#', hi) + sl = sl .. [[ %<%F %-m %-r ]] -- right sl = sl .. [[ %= ]] -- spacer local lsp_spinner = require('spinner').status(vim.fn.bufnr()) local lsp_diagnostics = statusline_lsp_diagnostics(vim.fn.bufnr()) - sl = sl .. lsp_spinner .. ' ' - sl = sl .. lsp_diagnostics + sl = sl .. statusline_hi(lsp_spinner, '%#StatusLineJobs#', hi) + sl = sl .. ' ' + sl = sl .. statusline_hi(lsp_diagnostics, '%#StatusLineDiagnostics#', hi) sl = sl .. [[ %l:%v %y ]] return sl end -statusline_color = function(mode) +function _G.statusline_hi(element, hi, default) + if not element or element == '' then return '' end + if not (default == '%*') then hi = '' end + return hi .. element .. default +end +function _G.statusline_color(mode) local hi = '%*' if mode == 'i' then - hi = '%#StatusLineInsert#' + -- hi = '%#StatusLineInsert#' elseif mode == 'c' then - hi = '%#StatusLineCommand#' + -- hi = '%#StatusLineCommand#' elseif mode == 'v' or mode == 'V' or mode == '' then hi = '%#StatusLineVisual#' elseif mode == 'R' or mode == 'Rv' then @@ -147,16 +156,18 @@ statusline_color = function(mode) -- return '%{g:actual_curwin==win_getid()?'.. hi ..':%#StatusLineNC#}' return hi end -statusline_lsp_diagnostics = function(bufnr) +function _G.statusline_lsp_diagnostics(bufnr) -- Error, Warning, Information, Hint local error_num = vim.lsp.diagnostic.get_count(bufnr, 'Error') local warn_num = vim.lsp.diagnostic.get_count(bufnr, 'Warning') local s = '' if error_num > 0 then + s = s .. '%#LspDiagnosticsError#' s = s .. vim.fn.sign_getdefined('LspDiagnosticsSignError')[1].text .. error_num end if warn_num > 0 then + s = s .. '%#LspDiagnosticsWarning#' s = s .. vim.fn.sign_getdefined('LspDiagnosticsSignWarning')[1].text .. warn_num end return s |