vim: factor out highlight function into fs.util

This commit is contained in:
Fernando Schauenburg 2022-02-14 00:11:31 +01:00
parent c79b16f79a
commit 1529b88178
5 changed files with 51 additions and 31 deletions

View file

@ -1,11 +1,14 @@
local nmap = require'fs.util'.nmap
local util = require'fs.util'
local nmap = util.nmap
local colors = util.colors()
local highlight = util.highlight
local config = function()
vim.g.indent_blankline_enabled = false
require'indent_blankline'.setup()
vim.cmd [[highlight IndentBlanklineChar ctermfg=10]]
highlight('IndentBlanklineChar') { fg = colors.base01 }
nmap { '<leader>si', '<cmd>:IndentBlanklineToggle<cr>' }
end

View file

@ -1,5 +1,7 @@
local nmap = require'fs.util'.nmap
local colors = require'fs.util'.colors()
local util = require'fs.util'
local nmap = util.nmap
local colors = util.colors()
local highlight = util.highlight
-- helper to set vim.g options that will be moved to setup() later
local function set_globals(tbl)
@ -9,14 +11,6 @@ local function set_globals(tbl)
end
end
local function highlight(group, color)
if vim.opt.termguicolors:get() then
vim.cmd(vim.fn.printf('highlight %s guifg=%s', group, color))
else
vim.cmd(vim.fn.printf('highlight %s ctermfg=%d', group, color))
end
end
local global_opts ={
add_trailing = 1, -- add trailing / to folders
group_empty = 1, -- folders that contain only one folder are grouped
@ -24,7 +18,7 @@ local global_opts ={
git_hl = 1, -- enable highlight based on git attributes
icons = {
default = '', -- defailt icon for files
default = '', -- default icon for files
symlink = '', -- default icon for symlinks
},
}
@ -49,14 +43,14 @@ local nvim_tree_config = {
local config = function()
require'nvim-tree'.setup(nvim_tree_config)
highlight('NvimTreeSpecialFile' , colors.base2 )
highlight('NvimTreeIndentMarker' , colors.base01 )
highlight('NvimTreeGitStaged' , colors.green )
highlight('NvimTreeGitRenamed' , colors.yellow )
highlight('NvimTreeGitNew' , colors.yellow )
highlight('NvimTreeGitDirty' , colors.yellow )
highlight('NvimTreeGitDeleted' , colors.orange )
highlight('NvimTreeGitMerge' , colors.red )
highlight('NvimTreeSpecialFile') { fg = colors.base2 }
highlight('NvimTreeIndentMarker') { fg = colors.base01 }
highlight('NvimTreeGitStaged') { fg = colors.green }
highlight('NvimTreeGitRenamed') { fg = colors.yellow }
highlight('NvimTreeGitNew') { fg = colors.yellow }
highlight('NvimTreeGitDirty') { fg = colors.yellow }
highlight('NvimTreeGitDeleted') { fg = colors.orange }
highlight('NvimTreeGitMerge') { fg = colors.red }
nmap { '<c-n>', '<cmd>NvimTreeToggle<cr>' }
nmap { '<leader>n', '<cmd>NvimTreeFindFileToggle<cr>' }

View file

@ -1,12 +1,16 @@
local util = require'fs.util'
local C = util.colors()
local highlight = util.highlight
local config = function()
vim.cmd [[
silent! colorscheme solarized
highlight Normal ctermbg=NONE " transparent background
highlight NonText cterm=NONE ctermfg=10 " subtle EOL symbols
highlight Whitespace cterm=NONE ctermfg=9 " orange listchars
highlight SpellBad ctermfg=3 " yellow spelling mistakes
highlight QuickFixLine ctermfg=3 ctermbg=0 " yellow selected quickfix item
]]
vim.cmd [[silent! colorscheme solarized]]
highlight('Normal') { bg = 'NONE' } -- transparent background
highlight('NonText') { fg = C.base02, attrs = 'NONE' } -- subtle EOL symbols
highlight('Whitespace') { fg = C.orange } -- listchars
highlight('SpellBad') { fg = C.yellow }
highlight('QuickFixLine') { fg = C.yellow, bg = C.base02 } -- selected quickfix item
highlight('CursorLineNr') { fg = C.yellow, attrs = 'NONE' } -- current line number
end
return { config = config }

View file

@ -1,4 +1,7 @@
local nmap = require'fs.util'.nmap
local util = require'fs.util'
local nmap = util.nmap
local colors = util.colors()
local highlight = util.highlight
local toggle = function()
if vim.o.colorcolumn == '' then
@ -11,7 +14,7 @@ end
local config = function()
require'virt-column'.setup { char = '' }
vim.cmd [[highlight VirtColumn cterm=NONE ctermfg=0]]
highlight('VirtColumn') { fg = colors.base02, attrs = 'NONE' }
nmap { '<leader>sc', '<cmd>lua require"fs.config.virt-column".toggle()<cr>' }
end

View file

@ -57,5 +57,21 @@ M.colors = function(gui)
}
end
-- Usage example:
-- highlight('Test2') { fg = C.yellow, bg = C.base02 }
M.highlight = function(name)
return function(tbl)
local kind = vim.opt.termguicolors:get() and 'gui' or 'cterm'
local parts = {}
for k, v in pairs(tbl) do
if k == 'attrs' then k = '' end
table.insert(parts, kind .. k .. '=' .. v)
end
vim.cmd('highlight ' .. name .. ' ' .. vim.fn.join(parts, ' '))
end
end
return M