diff options
-rw-r--r-- | autoload/spectral.py | 15 | ||||
-rw-r--r-- | autoload/spectral.vim | 56 | ||||
-rw-r--r-- | autoload/spectral/highlight.vim | 33 | ||||
-rw-r--r-- | plugin/spectral.vim | 9 |
4 files changed, 109 insertions, 4 deletions
diff --git a/autoload/spectral.py b/autoload/spectral.py index 9afcf6b..975c070 100644 --- a/autoload/spectral.py +++ b/autoload/spectral.py @@ -423,17 +423,26 @@ def spectral_start(outfile): spectral_ctx = Vivid(outfile) spectral_ctx.start() +def get_saturation(color): + if isinstance(color, str): + color = sRGBColor.new_from_rgb_hex(color) + + color_hsv = convert_color(color, HSVColor) + (h, s, v) = color_hsv.get_value_tuple() + return s + +def spectral_get_saturation(color): + c = get_saturation(color) + vim.command('let g:return=%s' % c) + def set_saturation(color, amnt): if isinstance(color, str): color = sRGBColor.new_from_rgb_hex(color) - print("Color " + str(color) + " " + get_rgb_hex(color)) color_hsv = convert_color(color, HSVColor) (h, s, v) = color_hsv.get_value_tuple() - print("HSVPre " + str(color_hsv)) color_hsv = HSVColor(h, amnt, v) - print("HSVPost " + str(color_hsv)) return convert_color(color_hsv, sRGBColor) def spectral_set_saturation(color, amnt): diff --git a/autoload/spectral.vim b/autoload/spectral.vim index fe70131..d7e3110 100644 --- a/autoload/spectral.vim +++ b/autoload/spectral.vim @@ -50,7 +50,28 @@ function! spectral#desaturate(color, amount) return spectral#toColor(nr, ng, nb) endfunction -function! spectral#set_saturation(color, amount) +function! spectral#getSaturation(color) + let saved = 0 + if exists('g:return') + let old_return = g:return + let saved = 1 + endif + + call s:loadPythonScript() + exec printf('python3 spectral_get_saturation("%s")', a:color) + + let ret = g:return + + if saved + let g:return = old_return + else + unlet g:return + endif + + return ret +endfunction + +function! spectral#setSaturation(color, amount) let saved = 0 if exists('g:return') let old_return = g:return @@ -233,6 +254,9 @@ function! spectral#Hi(bang, fn, name, ...) let bg = "None" let sp = "None" let extra = [] + else + echoerr printf("Incorrect number of arguments for highlight [%s]", a:name) + return endif if extra == [] @@ -307,3 +331,33 @@ function! spectral#useDefaultTerminalColors() abort let g:terminal_color_9="#b30005" endif endfunction + +function! spectral#brightenWord(amnt) abort + let color = expand('<cword>') + + if !(color =~ '^#[A-F-a-f0-9]\{6}') + echo "Not a color" + return + endif + + let new_color = spectral#brighter(color, a:amnt) + exec "norm ciw" . new_color . "" +endfunction + +function! spectral#saturate(color, amnt) abort + let cur_sat = spectral#getSaturation(a:color) + return spectral#setSaturation(a:color, cur_sat * a:amnt) +endfunction + +function! spectral#saturateWord(amnt) abort + let color = expand('<cword>') + + if !(color =~ '^#[A-F-a-f0-9]\{6}') + echo "Not a color" + return + endif + + let cur_sat = spectral#getSaturation(color) + let new_color = spectral#setSaturation(color, cur_sat * a:amnt) + exec "norm ciw" . new_color . "" +endfunction diff --git a/autoload/spectral/highlight.vim b/autoload/spectral/highlight.vim new file mode 100644 index 0000000..6bbde34 --- /dev/null +++ b/autoload/spectral/highlight.vim @@ -0,0 +1,33 @@ +let s:done = {} + +function! spectral#highlight#highlight() abort + %s/#[a-fA-F0-9]\{6}/\=spectral#highlight#highlightOne(submatch(0))/g +endfunction + +function! spectral#highlight#highlightLine() abort + let curpos = getcurpos() + silent! '[,']s/#[a-fA-F0-9]\{6}/\=spectral#highlight#highlightOne(submatch(0))/g + call cursor(curpos[1:]) +endfunction + +function! spectral#highlight#highlightOne(match) abort + let match = a:match + let nohash = match[1:] + + if has_key(s:done, match) + return a:match + else + let s:done[match] = 1 + endif + + exec printf("syn match %s +%s+ containedIn=vimComment,vim9Comment,vimString,vimIsCommand,vimHiGuiRgb", nohash, match) + exec printf("hi %s guifg=#000000 guibg=%s", nohash, match) + + " Return exactly what was put in. We only care about the side effets. + return a:match +endfunction + +function! spectral#highlight#clearCache() abort + let s:done = {} + call spectral#highlight#highlight() +endfunction diff --git a/plugin/spectral.vim b/plugin/spectral.vim new file mode 100644 index 0000000..7690b25 --- /dev/null +++ b/plugin/spectral.vim @@ -0,0 +1,9 @@ +augroup SpectralHighlight + au! + au TextChanged */spectral.vim/colors/*.vim call spectral#highlight#highlightLine() + au InsertLeave */spectral.vim/colors/*.vim call spectral#highlight#highlightLine() + au BufRead */spectral.vim/colors/*.vim call spectral#highlight#clearCache() + au BufRead */spectral.vim/colors/*.vim call spectral#highlight#highlight() + au ColorScheme */spectral.vim/colors/*.vim call spectral#highlight#clearCache() + au Syntax */spectral.vim/colors/*.vim call spectral#highlight#clearCache() +augroup END |