From 8bca81886ab94963531b77b96b37c9f1fea20583 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Mon, 30 Aug 2021 18:17:16 +0200 Subject: vim: add colors to statusline --- .vim/init.lua | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to '.vim/init.lua') 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 -- cgit 1.4.1