Added more function comments and renamed all instances of 'brighten' to 'lighten'
This commit is contained in:
parent
8d0c589f5c
commit
5666f56a6a
@ -4,9 +4,9 @@
|
||||
"
|
||||
" Regex pattern for a hex color.
|
||||
"
|
||||
" Examples:
|
||||
" Example matches:
|
||||
" - '#123ABC'
|
||||
" - '#FFFFFF'
|
||||
" - '#ffffff'
|
||||
" - '#000000'
|
||||
"
|
||||
let s:hex_color_pattern = '#[0-9A-Fa-f]\{6\}'
|
||||
@ -40,6 +40,8 @@ function! color_helper#hex_to_dec(arg)
|
||||
return (a:arg =~? '^0x') ? a:arg + 0 : ('0x'.a:arg) + 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
" Converts a given hex color string into an rgb list (eg. [red, green, blue]).
|
||||
"
|
||||
" Example: color_helper#hex_color_to_rgb('#0088FF')
|
||||
" Returns: [0, 136, 255]
|
||||
@ -57,6 +59,8 @@ function! color_helper#hex_color_to_rgb(hex_color)
|
||||
return l:rgb
|
||||
endfunction
|
||||
|
||||
"
|
||||
" Converts a given rgb list (eg. [red, green, blue]) into a hex color string.
|
||||
"
|
||||
" Example: color_helper#rgb_color_to_hex([0, 136, 255])
|
||||
" Returns: '#0088FF'
|
||||
@ -71,20 +75,26 @@ function! color_helper#rgb_color_to_hex(rgb_color)
|
||||
endfunction
|
||||
|
||||
"
|
||||
" Example: color_helper#hex_color_brighten('#000000', 0.10)
|
||||
" Returns a ligtened color using the given color and the percent to lighten it
|
||||
" by.
|
||||
"
|
||||
" Example: color_helper#hex_color_lighten('#000000', 0.10)
|
||||
" Returns: '#191919'
|
||||
"
|
||||
function! color_helper#hex_color_brighten(color, percent)
|
||||
function! color_helper#hex_color_lighten(color, percent)
|
||||
let l:rgb = color_helper#hex_color_to_rgb(a:color)
|
||||
let l:rgb_brightened = []
|
||||
let l:rgb_lightened = []
|
||||
|
||||
for decimal in l:rgb
|
||||
call add(l:rgb_brightened, float2nr(decimal * (a:percent + 1)))
|
||||
call add(l:rgb_lightened, float2nr(decimal * (a:percent + 1)))
|
||||
endfor
|
||||
|
||||
return color_helper#rgb_color_to_hex(l:rgb_brightened)
|
||||
return color_helper#rgb_color_to_hex(l:rgb_lightened)
|
||||
endfunction
|
||||
|
||||
"
|
||||
" Returns a darkened color using the given color and the percent to darken it
|
||||
" by.
|
||||
"
|
||||
" Example: color_helper#hex_color_darken('#FFFFFF', 0.10)
|
||||
" Returns: '#E5E5E5'
|
||||
|
@ -2,7 +2,7 @@
|
||||
" Homepage: http://github.com/nathanaelkane/vim-indent-guides
|
||||
|
||||
"
|
||||
"
|
||||
" Toggles the indent guides on and off for all buffers.
|
||||
"
|
||||
function! indent_guides#toggle()
|
||||
let g:indent_guides_matches =
|
||||
@ -16,7 +16,7 @@ function! indent_guides#toggle()
|
||||
endfunction
|
||||
|
||||
"
|
||||
"
|
||||
" Enables the indent guides for all buffers.
|
||||
"
|
||||
function! indent_guides#enable()
|
||||
call indent_guides#disable()
|
||||
@ -44,7 +44,7 @@ function! indent_guides#enable()
|
||||
endfunction
|
||||
|
||||
"
|
||||
"
|
||||
" Disables the indent guides for all buffers.
|
||||
"
|
||||
function! indent_guides#disable()
|
||||
if !empty(g:indent_guides_matches)
|
||||
@ -58,7 +58,7 @@ function! indent_guides#disable()
|
||||
endfunction
|
||||
|
||||
"
|
||||
"
|
||||
" Automagically calculates and defines the indent highlight colors.
|
||||
"
|
||||
function! indent_guides#highlight_colors()
|
||||
if g:indent_guides_auto_colors
|
||||
@ -67,8 +67,8 @@ function! indent_guides#highlight_colors()
|
||||
let hi_normal_guibg = matchstr(hi_normal, 'guibg=\zs#[0-9A-Fa-f]\{6\}\ze')
|
||||
|
||||
" calculate the highlight background colors
|
||||
let hi_odd_bg = indent_guides#brighten_or_darken_color(hi_normal_guibg)
|
||||
let hi_even_bg = indent_guides#brighten_or_darken_color(hi_odd_bg)
|
||||
let hi_odd_bg = indent_guides#lighten_or_darken_color(hi_normal_guibg)
|
||||
let hi_even_bg = indent_guides#lighten_or_darken_color(hi_odd_bg)
|
||||
|
||||
" define the new highlights
|
||||
exe "hi IndentGuidesOdd guibg=" . hi_odd_bg
|
||||
@ -77,14 +77,14 @@ function! indent_guides#highlight_colors()
|
||||
endfunction
|
||||
|
||||
"
|
||||
" Takes a color and darkens or brightens it depending on whether a dark or
|
||||
" light colorscheme is being used
|
||||
" Takes a color and darkens or lightens it depending on whether a dark or
|
||||
" light colorscheme is being used.
|
||||
"
|
||||
function! indent_guides#brighten_or_darken_color(color)
|
||||
function! indent_guides#lighten_or_darken_color(color)
|
||||
let percent = g:indent_guides_auto_colors_change_percent
|
||||
|
||||
let new_color = (&g:background == 'dark') ?
|
||||
\ color_helper#hex_color_brighten(a:color, percent) :
|
||||
\ color_helper#hex_color_lighten(a:color, percent) :
|
||||
\ color_helper#hex_color_darken (a:color, percent)
|
||||
|
||||
return new_color
|
||||
|
Loading…
Reference in New Issue
Block a user