From 43fa75f427dd941c01df0e5ad0bd4881a4bfd15d Mon Sep 17 00:00:00 2001 From: Ludovic Koenig Date: Wed, 6 Mar 2019 20:02:47 +0100 Subject: [PATCH 1/3] Separate the Utility in two The are now two Utility sections: - Color Utility: Part of the script that helps defining colors. - Highlight Utility: Part of the script that helps defining highlights. --- colors/odyssey.vim | 47 ++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/colors/odyssey.vim b/colors/odyssey.vim index 062d89f..4968eef 100644 --- a/colors/odyssey.vim +++ b/colors/odyssey.vim @@ -35,10 +35,10 @@ endif let g:colors_name = 'odyssey' -let s:colors = {} - " }}} -" Utilities {{{ +" Color Utilities {{{ + +let s:colors = {} function! s:hsv2hex(hue, saturation, value) let l:s = a:saturation / 100.0 @@ -73,25 +73,6 @@ function! s:hsv2hex(hue, saturation, value) return printf(l:f, l:l[0]) . printf(l:f, l:l[1]) . printf(l:f, l:l[2]) endfunction -function! s:HL(group, bg, ...) - let histring = 'highlight ' . a:group . ' ' - let cbg = get(s:colors, a:bg) - let histring .= 'guibg=#'. cbg['gui'] . ' ' . 'ctermbg=' . cbg['term'] - - if a:0 > 0 - let cfg = get(s:colors, a:1) - let histring .= ' guifg=#'. cfg['gui'] . ' ' . 'ctermfg=' . cfg['term'] - endif - - if a:0 > 1 - let histring .= ' cterm=' . a:2 - else - let histring .= ' cterm=none' - endif - - execute histring -endfunction - " }}} " Colors {{{ " @@ -116,6 +97,28 @@ let s:colors.procedure = {'gui': s:hsv2hex(140, 45, 70), 'term': '72'} let s:colors.type = {'gui': s:hsv2hex(200, 45, 70), 'term': '67'} let s:colors.constant = {'gui': s:hsv2hex(230, 45, 70), 'term': '61'} +" }}} +" 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['term'] + + if a:0 > 0 + let cfg = get(s:colors, a:1) + let histring .= ' guifg=#'. cfg['gui'] . ' ' . 'ctermfg=' . cfg['term'] + endif + + if a:0 > 1 + let histring .= ' cterm=' . a:2 + else + let histring .= ' cterm=none' + endif + + execute histring +endfunction + " }}} " Default Highlights {{{ " From 3fc792934e6f6cb96bad307ddd6ea423b32d3cc8 Mon Sep 17 00:00:00 2001 From: Ludovic Koenig Date: Wed, 6 Mar 2019 20:24:11 +0100 Subject: [PATCH 2/3] Modify the color utilities The function named s:hsv2hex has been separated into two functions named respectively s:hsv2rgb and s:rgb2hex. The function that helps now populating the s:color array is named s:colorize. --- colors/odyssey.vim | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/colors/odyssey.vim b/colors/odyssey.vim index 4968eef..1948d61 100644 --- a/colors/odyssey.vim +++ b/colors/odyssey.vim @@ -40,7 +40,7 @@ let g:colors_name = 'odyssey' let s:colors = {} -function! s:hsv2hex(hue, saturation, value) +function! s:hsv2rgb(hue, saturation, value) let l:s = a:saturation / 100.0 let l:v = a:value / 100.0 @@ -69,8 +69,16 @@ function! s:hsv2hex(hue, saturation, value) 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])] + return l:l +endfunction + +function! s:rgb2hex(rgb) let l:f = "%02x" - return printf(l:f, l:l[0]) . printf(l:f, l:l[1]) . printf(l:f, l:l[2]) + return printf(l:f, a:rgb[0]) . printf(l:f, a:rgb[1]) . printf(l:f, a:rgb[2]) +endfunction + +function! s:colorize(hue, saturation, value) + return s:rgb2hex(s:hsv2rgb(a:hue, a:saturation, a:value)) endfunction " }}} @@ -83,19 +91,19 @@ endfunction " " 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.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.beyondback = {'gui': s:colorize(177, 20, 6), 'term': '233'} +let s:colors.background = {'gui': s:colorize(177, 20, 11), 'term': '234'} +let s:colors.cursorline = {'gui': s:colorize(177, 25, 16), 'term': '235'} +let s:colors.foldedline = {'gui': s:colorize(177, 25, 21), 'term': '236'} +let s:colors.linenumber = {'gui': s:colorize(177, 9, 55), 'term': '245'} +let s:colors.foreground = {'gui': s:colorize(177, 11, 75), 'term': '250'} -let s:colors.keyword = {'gui': s:hsv2hex(170, 45, 70), 'term': '73'} -let s:colors.error = {'gui': s:hsv2hex( 0, 45, 70), 'term': '131'} -let s:colors.warning = {'gui': s:hsv2hex( 30, 45, 70), 'term': '137'} -let s:colors.procedure = {'gui': s:hsv2hex(140, 45, 70), 'term': '72'} -let s:colors.type = {'gui': s:hsv2hex(200, 45, 70), 'term': '67'} -let s:colors.constant = {'gui': s:hsv2hex(230, 45, 70), 'term': '61'} +let s:colors.keyword = {'gui': s:colorize(170, 45, 70), 'term': '73'} +let s:colors.error = {'gui': s:colorize( 0, 45, 70), 'term': '131'} +let s:colors.warning = {'gui': s:colorize( 30, 45, 70), 'term': '137'} +let s:colors.procedure = {'gui': s:colorize(140, 45, 70), 'term': '72'} +let s:colors.type = {'gui': s:colorize(200, 45, 70), 'term': '67'} +let s:colors.constant = {'gui': s:colorize(230, 45, 70), 'term': '61'} " }}} " Highlight Utilities {{{ From e89d998525c70cd10c75cc269408de14d0ba689b Mon Sep 17 00:00:00 2001 From: Ludovic Koenig Date: Thu, 7 Mar 2019 13:16:43 +0100 Subject: [PATCH 3/3] Compute the cterm colors given the true colors The RGB values of the GUI colors are now taken in input to compute the value of the Xterm colors by using an approximation. Now, in order to chose colors for the GUI or the TERM, it is enough to only provide the HSB triplet. --- colors/odyssey.vim | 70 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/colors/odyssey.vim b/colors/odyssey.vim index 1948d61..c396a24 100644 --- a/colors/odyssey.vim +++ b/colors/odyssey.vim @@ -38,8 +38,6 @@ let g:colors_name = 'odyssey' " }}} " Color Utilities {{{ -let s:colors = {} - function! s:hsv2rgb(hue, saturation, value) let l:s = a:saturation / 100.0 let l:v = a:value / 100.0 @@ -77,8 +75,44 @@ function! s:rgb2hex(rgb) return printf(l:f, a:rgb[0]) . printf(l:f, a:rgb[1]) . printf(l:f, a:rgb[2]) endfunction +function! s:rgb2short(rgb) + " 216 colors + 24 greys = 240 total ( - 16 because ignoring system color ) + function! s:xterm2rgb(key, val) + let l:incs = [0, 95, 135, 175, 215, 255] + + if a:val < 216 + return [l:incs[a:val / 36], l:incs[(a:val % 36) / 6], l:incs[a:val % 6]] + else + let l:coordinate = a:val * 10 - 2152 + return [l:coordinate, l:coordinate, l:coordinate] + endif + endfunction + + 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) - return s:rgb2hex(s:hsv2rgb(a:hue, a:saturation, a: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 " }}} @@ -91,19 +125,21 @@ endfunction " " The s:colors dictionary is initialized in the Bootstrap section. -let s:colors.beyondback = {'gui': s:colorize(177, 20, 6), 'term': '233'} -let s:colors.background = {'gui': s:colorize(177, 20, 11), 'term': '234'} -let s:colors.cursorline = {'gui': s:colorize(177, 25, 16), 'term': '235'} -let s:colors.foldedline = {'gui': s:colorize(177, 25, 21), 'term': '236'} -let s:colors.linenumber = {'gui': s:colorize(177, 9, 55), 'term': '245'} -let s:colors.foreground = {'gui': s:colorize(177, 11, 75), 'term': '250'} +let s:colors = {} -let s:colors.keyword = {'gui': s:colorize(170, 45, 70), 'term': '73'} -let s:colors.error = {'gui': s:colorize( 0, 45, 70), 'term': '131'} -let s:colors.warning = {'gui': s:colorize( 30, 45, 70), 'term': '137'} -let s:colors.procedure = {'gui': s:colorize(140, 45, 70), 'term': '72'} -let s:colors.type = {'gui': s:colorize(200, 45, 70), 'term': '67'} -let s:colors.constant = {'gui': s:colorize(230, 45, 70), 'term': '61'} +let s:colors.beyondback = s:colorize(177, 20, 6) +let s:colors.background = s:colorize(177, 20, 11) +let s:colors.cursorline = s:colorize(177, 25, 16) +let s:colors.foldedline = s:colorize(177, 25, 21) +let s:colors.linenumber = s:colorize(177, 9, 55) +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 {{{ @@ -111,11 +147,11 @@ let s:colors.constant = {'gui': s:colorize(230, 45, 70), 'term': '61'} function! s:HL(group, bg, ...) let histring = 'highlight ' . a:group . ' ' let cbg = get(s:colors, a:bg) - let histring .= 'guibg=#'. cbg['gui'] . ' ' . 'ctermbg=' . cbg['term'] + 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['term'] + let histring .= ' guifg=#'. cfg['gui'] . ' ' . 'ctermfg=' . cfg['cterm'] endif if a:0 > 1