From 7171f7976c298f7ea1955990ce05c4db35e3dc7d Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Sat, 28 Mar 2009 02:20:27 -0400 Subject: [PATCH] Default to using builtin rgb.txt maps Provide a variable to override this behavior and use showrgb instead. This sacrifices a tiny bit of accuracy in favor of a large speed boost. --- doc/CSApprox.txt | 8 ++++++++ plugin/CSApprox.vim | 10 +++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/doc/CSApprox.txt b/doc/CSApprox.txt index e2a30c2..65d79de 100644 --- a/doc/CSApprox.txt +++ b/doc/CSApprox.txt @@ -300,6 +300,14 @@ g:CSApprox_hook_{scheme}_post *csapprox-hooks* colorscheme named "123 foo_bar-baz456.vim", the hook searched for will be, eg, g:CSApprox_hook_foo_barbaz456_post +g:CSApprox_use_showrgb *g:CSApprox_use_showrgb* + By default, CSApprox will use a built in mapping of color names to values. + This optimization greatly helps speed, but means that colors addressed by + name might not match up perfectly between gvim (which uses the system's + real rgb database) and CSApprox (which uses the builtin database). To + force CSApprox to try the systemwide database first, and only fall back on + the builtin database if it isn't available, set this variable non-zero. + g:CSApprox_approximator_function *g:CSApprox_approximator_function* If the default approximation function doesn't work well enough, the user (or another author wishing to extend this plugin) can write another diff --git a/plugin/CSApprox.vim b/plugin/CSApprox.vim index 1bb96f7..a02986e 100644 --- a/plugin/CSApprox.vim +++ b/plugin/CSApprox.vim @@ -294,6 +294,10 @@ let s:rgb_defaults = { "lightred" : "#FFBBBB", " color values (as '#rrggbb'). function! s:UpdateRgbHash() try + if !exists("g:CSApprox_use_showrgb") || !g:CSApprox_use_showrgb + throw "Not using showrgb" + endif + " We want to use the 'showrgb' program, if it's around let lines = split(system('showrgb'), '\n') @@ -496,9 +500,9 @@ function! s:SetCtermFromGui(hl) let hl.cterm[which] = val elseif val =~ '^#\=\x\{6}$' let val = substitute(val, '^#', '', '') - let r = str2nr(val[0] . val[1], 16) - let g = str2nr(val[2] . val[3], 16) - let b = str2nr(val[4] . val[5], 16) + let r = str2nr(val[0:1], 16) + let g = str2nr(val[2:3], 16) + let b = str2nr(val[4:5], 16) let hl.cterm[which] = g:CSApprox_approximator_function(r, g, b) exe 'hi ' . hl.name . ' cterm' . which . '=' . hl.cterm[which] else