Added more function comments and renamed all instances of 'brighten' to 'lighten'

This commit is contained in:
Nate Kane 2010-12-07 22:51:31 +10:00
parent 8d0c589f5c
commit 5666f56a6a
2 changed files with 27 additions and 17 deletions

View File

@ -4,9 +4,9 @@
" "
" Regex pattern for a hex color. " Regex pattern for a hex color.
" "
" Examples: " Example matches:
" - '#123ABC' " - '#123ABC'
" - '#FFFFFF' " - '#ffffff'
" - '#000000' " - '#000000'
" "
let s:hex_color_pattern = '#[0-9A-Fa-f]\{6\}' 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 return (a:arg =~? '^0x') ? a:arg + 0 : ('0x'.a:arg) + 0
endfunction endfunction
"
" Converts a given hex color string into an rgb list (eg. [red, green, blue]).
" "
" Example: color_helper#hex_color_to_rgb('#0088FF') " Example: color_helper#hex_color_to_rgb('#0088FF')
" Returns: [0, 136, 255] " Returns: [0, 136, 255]
@ -57,6 +59,8 @@ function! color_helper#hex_color_to_rgb(hex_color)
return l:rgb return l:rgb
endfunction 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]) " Example: color_helper#rgb_color_to_hex([0, 136, 255])
" Returns: '#0088FF' " Returns: '#0088FF'
@ -71,20 +75,26 @@ function! color_helper#rgb_color_to_hex(rgb_color)
endfunction 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' " 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 = color_helper#hex_color_to_rgb(a:color)
let l:rgb_brightened = [] let l:rgb_lightened = []
for decimal in l:rgb 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 endfor
return color_helper#rgb_color_to_hex(l:rgb_brightened) return color_helper#rgb_color_to_hex(l:rgb_lightened)
endfunction 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) " Example: color_helper#hex_color_darken('#FFFFFF', 0.10)
" Returns: '#E5E5E5' " Returns: '#E5E5E5'

View File

@ -2,7 +2,7 @@
" Homepage: http://github.com/nathanaelkane/vim-indent-guides " Homepage: http://github.com/nathanaelkane/vim-indent-guides
" "
" " Toggles the indent guides on and off for all buffers.
" "
function! indent_guides#toggle() function! indent_guides#toggle()
let g:indent_guides_matches = let g:indent_guides_matches =
@ -16,7 +16,7 @@ function! indent_guides#toggle()
endfunction endfunction
" "
" " Enables the indent guides for all buffers.
" "
function! indent_guides#enable() function! indent_guides#enable()
call indent_guides#disable() call indent_guides#disable()
@ -44,7 +44,7 @@ function! indent_guides#enable()
endfunction endfunction
" "
" " Disables the indent guides for all buffers.
" "
function! indent_guides#disable() function! indent_guides#disable()
if !empty(g:indent_guides_matches) if !empty(g:indent_guides_matches)
@ -58,7 +58,7 @@ function! indent_guides#disable()
endfunction endfunction
" "
" " Automagically calculates and defines the indent highlight colors.
" "
function! indent_guides#highlight_colors() function! indent_guides#highlight_colors()
if g:indent_guides_auto_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') let hi_normal_guibg = matchstr(hi_normal, 'guibg=\zs#[0-9A-Fa-f]\{6\}\ze')
" calculate the highlight background colors " calculate the highlight background colors
let hi_odd_bg = indent_guides#brighten_or_darken_color(hi_normal_guibg) let hi_odd_bg = indent_guides#lighten_or_darken_color(hi_normal_guibg)
let hi_even_bg = indent_guides#brighten_or_darken_color(hi_odd_bg) let hi_even_bg = indent_guides#lighten_or_darken_color(hi_odd_bg)
" define the new highlights " define the new highlights
exe "hi IndentGuidesOdd guibg=" . hi_odd_bg exe "hi IndentGuidesOdd guibg=" . hi_odd_bg
@ -77,14 +77,14 @@ function! indent_guides#highlight_colors()
endfunction endfunction
" "
" Takes a color and darkens or brightens it depending on whether a dark or " Takes a color and darkens or lightens it depending on whether a dark or
" light colorscheme is being used " 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 percent = g:indent_guides_auto_colors_change_percent
let new_color = (&g:background == 'dark') ? 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) \ color_helper#hex_color_darken (a:color, percent)
return new_color return new_color