Incorporate the new way of computing Xterm colors
This commit is contained in:
+79
-32
@@ -35,12 +35,10 @@ endif
|
|||||||
|
|
||||||
let g:colors_name = 'odyssey'
|
let g:colors_name = 'odyssey'
|
||||||
|
|
||||||
let s:colors = {}
|
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
" Utilities {{{
|
" Color Utilities {{{
|
||||||
|
|
||||||
function! s:hsv2hex(hue, saturation, value)
|
function! s:hsv2rgb(hue, saturation, value)
|
||||||
let l:s = a:saturation / 100.0
|
let l:s = a:saturation / 100.0
|
||||||
let l:v = a:value / 100.0
|
let l:v = a:value / 100.0
|
||||||
|
|
||||||
@@ -69,27 +67,52 @@ function! s:hsv2hex(hue, saturation, value)
|
|||||||
let l:l = [round(l:l[0]), round(l:l[1]), round(l:l[2])]
|
let l:l = [round(l:l[0]), round(l:l[1]), round(l:l[2])]
|
||||||
let l:l = [float2nr(l:l[0]), float2nr(l:l[1]), float2nr(l:l[2])]
|
let l:l = [float2nr(l:l[0]), float2nr(l:l[1]), float2nr(l:l[2])]
|
||||||
|
|
||||||
let l:f = "%02x"
|
return l:l
|
||||||
return printf(l:f, l:l[0]) . printf(l:f, l:l[1]) . printf(l:f, l:l[2])
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:HL(group, bg, ...)
|
function! s:rgb2hex(rgb)
|
||||||
let histring = 'highlight ' . a:group . ' '
|
let l:f = "%02x"
|
||||||
let cbg = get(s:colors, a:bg)
|
return printf(l:f, a:rgb[0]) . printf(l:f, a:rgb[1]) . printf(l:f, a:rgb[2])
|
||||||
let histring .= 'guibg=#'. cbg['gui'] . ' ' . 'ctermbg=' . cbg['term']
|
endfunction
|
||||||
|
|
||||||
if a:0 > 0
|
function! s:rgb2short(rgb)
|
||||||
let cfg = get(s:colors, a:1)
|
" 216 colors + 24 greys = 240 total ( - 16 because ignoring system color )
|
||||||
let histring .= ' guifg=#'. cfg['gui'] . ' ' . 'ctermfg=' . cfg['term']
|
function! s:xterm2rgb(key, val)
|
||||||
endif
|
let l:incs = [0, 95, 135, 175, 215, 255]
|
||||||
|
|
||||||
if a:0 > 1
|
if a:val < 216
|
||||||
let histring .= ' cterm=' . a:2
|
return [l:incs[a:val / 36], l:incs[(a:val % 36) / 6], l:incs[a:val % 6]]
|
||||||
else
|
else
|
||||||
let histring .= ' cterm=none'
|
let l:coordinate = a:val * 10 - 2152
|
||||||
endif
|
return [l:coordinate, l:coordinate, l:coordinate]
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
execute histring
|
function! s:distance(lhs, rhs)
|
||||||
|
return abs(a:lhs[0] - a:rhs[0])
|
||||||
|
\ + abs(a:lhs[1] - a:rhs[1])
|
||||||
|
\ + abs(a:lhs[2] - a:rhs[2])
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let l:xterm = range(0, 239)
|
||||||
|
let l:xterm = map(l:xterm, function('s:xterm2rgb'))
|
||||||
|
|
||||||
|
let l:distances = []
|
||||||
|
for l:value in l:xterm
|
||||||
|
let l:distances += [s:distance(l:value, a:rgb)]
|
||||||
|
endfor
|
||||||
|
|
||||||
|
let l:index = index(l:distances, min(l:distances)) + 16
|
||||||
|
|
||||||
|
return printf("%s", l:index)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:colorize(hue, saturation, value)
|
||||||
|
let l:rgb = s:hsv2rgb(a:hue, a:saturation, a:value)
|
||||||
|
let l:gui = s:rgb2hex(l:rgb)
|
||||||
|
let l:cterm = s:rgb2short(l:rgb)
|
||||||
|
let l:res = {'gui': l:gui, 'cterm': l:cterm}
|
||||||
|
return l:res
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
@@ -102,19 +125,43 @@ endfunction
|
|||||||
"
|
"
|
||||||
" The s:colors dictionary is initialized in the Bootstrap section.
|
" The s:colors dictionary is initialized in the Bootstrap section.
|
||||||
|
|
||||||
let s:colors.beyondback = {'gui': s:hsv2hex(177, 20, 6), 'term': '233'}
|
let s:colors = {}
|
||||||
let s:colors.background = {'gui': s:hsv2hex(177, 20, 11), 'term': '234'}
|
|
||||||
let s:colors.cursorline = {'gui': s:hsv2hex(177, 25, 16), 'term': '235'}
|
|
||||||
let s:colors.foldedline = {'gui': s:hsv2hex(177, 25, 21), 'term': '236'}
|
|
||||||
let s:colors.linenumber = {'gui': s:hsv2hex(177, 9, 55), 'term': '245'}
|
|
||||||
let s:colors.foreground = {'gui': s:hsv2hex(177, 11, 75), 'term': '250'}
|
|
||||||
|
|
||||||
let s:colors.keyword = {'gui': s:hsv2hex(170, 45, 70), 'term': '73'}
|
let s:colors.beyondback = s:colorize(177, 20, 6)
|
||||||
let s:colors.error = {'gui': s:hsv2hex( 0, 45, 70), 'term': '131'}
|
let s:colors.background = s:colorize(177, 20, 11)
|
||||||
let s:colors.warning = {'gui': s:hsv2hex( 30, 45, 70), 'term': '137'}
|
let s:colors.cursorline = s:colorize(177, 25, 16)
|
||||||
let s:colors.procedure = {'gui': s:hsv2hex(140, 45, 70), 'term': '72'}
|
let s:colors.foldedline = s:colorize(177, 25, 21)
|
||||||
let s:colors.type = {'gui': s:hsv2hex(200, 45, 70), 'term': '67'}
|
let s:colors.linenumber = s:colorize(177, 9, 55)
|
||||||
let s:colors.constant = {'gui': s:hsv2hex(230, 45, 70), 'term': '61'}
|
let s:colors.foreground = s:colorize(177, 11, 75)
|
||||||
|
|
||||||
|
let s:colors.keyword = s:colorize(170, 45, 70)
|
||||||
|
let s:colors.error = s:colorize( 0, 45, 70)
|
||||||
|
let s:colors.warning = s:colorize( 30, 45, 70)
|
||||||
|
let s:colors.procedure = s:colorize(140, 45, 70)
|
||||||
|
let s:colors.type = s:colorize(200, 45, 70)
|
||||||
|
let s:colors.constant = s:colorize(230, 45, 70)
|
||||||
|
|
||||||
|
" }}}
|
||||||
|
" Highlight Utilities {{{
|
||||||
|
|
||||||
|
function! s:HL(group, bg, ...)
|
||||||
|
let histring = 'highlight ' . a:group . ' '
|
||||||
|
let cbg = get(s:colors, a:bg)
|
||||||
|
let histring .= 'guibg=#'. cbg['gui'] . ' ' . 'ctermbg=' . cbg['cterm']
|
||||||
|
|
||||||
|
if a:0 > 0
|
||||||
|
let cfg = get(s:colors, a:1)
|
||||||
|
let histring .= ' guifg=#'. cfg['gui'] . ' ' . 'ctermfg=' . cfg['cterm']
|
||||||
|
endif
|
||||||
|
|
||||||
|
if a:0 > 1
|
||||||
|
let histring .= ' cterm=' . a:2
|
||||||
|
else
|
||||||
|
let histring .= ' cterm=none'
|
||||||
|
endif
|
||||||
|
|
||||||
|
execute histring
|
||||||
|
endfunction
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
" Default Highlights {{{
|
" Default Highlights {{{
|
||||||
|
|||||||
Reference in New Issue
Block a user