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 | |
| parent | b3fe31ba9fadba18538b4dfff8afcc83d049ff27 (diff) | |
vim: add colors to statusline
| -rw-r--r-- | .vim/init.lua | 29 | ||||
| -rw-r--r-- | .vim/lua/colors.lua | 5 | ||||
| -rw-r--r-- | .vim/lua/lsp.lua | 10 |
3 files changed, 30 insertions, 14 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 diff --git a/.vim/lua/colors.lua b/.vim/lua/colors.lua index 32af6b2..f955ae1 100644 --- a/.vim/lua/colors.lua +++ b/.vim/lua/colors.lua @@ -283,9 +283,12 @@ return lush(function() -- Plugin configs END }}} -- Config specific + StatusLineIcon { fg = hsl(p.bright.magenta) }, StatusLineInsert { StatusLine }, StatusLineCommand { StatusLine }, StatusLineVisual { Visual }, - StatusLineReplace { StatusLine }, + StatusLineReplace { fg = hsl(p.bright.white), bg = hsl(p.bright.red) }, + StatusLineJobs { LspDiagnosticsHint }, + StatusLineDiagnostics { StatusLine }, } end) diff --git a/.vim/lua/lsp.lua b/.vim/lua/lsp.lua index 059579a..51c1a51 100644 --- a/.vim/lua/lsp.lua +++ b/.vim/lua/lsp.lua @@ -100,10 +100,12 @@ local setup = function() end -- }}} - vim.fn.sign_define("LspDiagnosticsSignError", {text="⚡", numhl="Error"}) - vim.fn.sign_define("LspDiagnosticsSignWarning", {text="⯈", numhl="Warning"}) - vim.fn.sign_define("LspDiagnosticsSignInformation", {text="ℹ"}) - vim.fn.sign_define("LspDiagnosticsSignHint", {text="🞶"}) + vim.fn.sign_define({ + {name='LspDiagnosticsSignError', text='⚡', numhl='Error'}, + {name='LspDiagnosticsSignWarning', text='⯈', numhl='Warning'}, + {name='LspDiagnosticsSignInformation', text='ℹ'}, + {name='LspDiagnosticsSignHint', text='🞶'} + }) -- lsp.ccls.setup { -- on_attach = my_attach, |