Skip to content

Commit

Permalink
[nvim] add rainbow indents as an option
Browse files Browse the repository at this point in the history
as requested by @lexisother
  • Loading branch information
dmitmel committed Oct 20, 2021
1 parent 654433d commit 785cb1b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
9 changes: 6 additions & 3 deletions colorschemes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,15 @@ def file_name(self) -> str:

def generate(self, theme: Theme, output: TextIO) -> None:
namespace = "dotfiles_colorscheme_"
output.write("let {}name = '{}'\n".format(namespace, theme.name))
output.write("let {}base16_name = '{}'\n".format(namespace, theme.base16_name))
output.write("let {}name = {}\n".format(namespace, json.dumps(theme.name)))
output.write("let {}base16_name = {}\n".format(namespace, json.dumps(theme.base16_name)))
output.write("let {}is_dark = {}\n".format(namespace, int(theme.is_dark)))
output.write("let {}base16_colors = [\n".format(namespace))
for gui_color, cterm_color in zip(theme.base16_colors, ANSI_TO_BASE16_MAPPING):
output.write(
"\\ {{'gui': '{}', 'cterm': '{:02}'}},\n".format(gui_color.css_hex, cterm_color),
"\\ {{'gui': '{}', 'cterm': {:2}, 'r': 0x{:02x}, 'g': 0x{:02x}, 'b': 0x{:02x}}},\n".format(
gui_color.css_hex, cterm_color, gui_color.r, gui_color.g, gui_color.b
),
)
output.write("\\ ]\n")

Expand Down
37 changes: 19 additions & 18 deletions colorschemes/out/vim.vim

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions nvim/colors/dotfiles.vim
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@
\ 'gui='.(attr) 'cterm='.(attr)
\ 'guisp='.get(sp, 'gui', 'NONE')
endfunction

function! s:hi_raw(group, defs) abort
exec 'hi' a:group
\ 'guifg='.get(a:defs, 'guifg', 'NONE') 'ctermfg='.get(a:defs, 'ctermfg', 'NONE')
\ 'guibg='.get(a:defs, 'guibg', 'NONE') 'ctermbg='.get(a:defs, 'ctermbg', 'NONE')
\ 'gui='.get(a:defs, 'gui', 'NONE') 'cterm='.get(a:defs, 'cterm', 'NONE')
\ 'guisp='.get(a:defs, 'gui', 'NONE')
endfunction

function! s:mix_colors(color1, color2, factor) abort
return {
\ 'r': float2nr(round(a:color1.r * (1 - a:factor) + a:color2.r * a:factor)),
\ 'g': float2nr(round(a:color1.g * (1 - a:factor) + a:color2.g * a:factor)),
\ 'b': float2nr(round(a:color1.b * (1 - a:factor) + a:color2.b * a:factor)),
\ }
endfunction

function! s:color_to_css_hex(color) abort
return printf('#%02x%02x%02x',
\ min([max([a:color.r, 0]), 0xff]),
\ min([max([a:color.g, 0]), 0xff]),
\ min([max([a:color.b, 0]), 0xff]))
endfunction
" }}}

" General syntax highlighting {{{
Expand All @@ -74,6 +97,19 @@
hi! link IndentBlanklineSpaceCharBlankline Whitespace
hi! link IndentBlanklineContextChar Label

if get(g:, 'dotfiles_rainbow_indent_opacity', 0) !=# 0
let g:indent_blankline_char_highlight_list = []
for s:color in range(7)
call add(g:indent_blankline_char_highlight_list, 'IndentLineRainbow' . s:color)
call s:hi_raw('IndentLineRainbow' . s:color, {
\ 'ctermfg': s:colors[0x2].cterm,
\ 'guifg': s:color_to_css_hex(s:mix_colors(s:colors[0x0], s:colors[8 + s:color], g:dotfiles_rainbow_indent_opacity)),
\ 'cterm': 'nocombine',
\ 'gui': 'nocombine',
\ })
endfor | unlet s:color
endif

call s:hi('Keyword', 0xE, '', '', '')
hi! link Statement Keyword
hi! link Repeat Keyword
Expand Down

0 comments on commit 785cb1b

Please sign in to comment.