From 768a475add3bb151d31ca39b2089d1544840203d Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Wed, 27 Jan 2016 20:06:22 +0100 Subject: [PATCH] Better algorightm, to get msdos colors currently, full 255 colors were returned, while in fact msdos console only supports 16 colors. So fix this. --- autoload/airline/highlighter.vim | 7 ++-- autoload/airline/msdos.vim | 57 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 autoload/airline/msdos.vim diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index 26cdb9f..70beb62 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -9,12 +9,11 @@ let s:accents = {} function! s:gui2cui(rgb, fallback) if a:rgb == '' return a:fallback - elseif match(a:rgb, 'NONE\|[fb]g') + elseif match(a:rgb, '^\%(NONE\|[fb]g\)$') > -1 return a:rgb endif - let rgb = map(matchlist(a:rgb, '#\(..\)\(..\)\(..\)')[1:3], '0 + ("0x".v:val)') - let rgb = [rgb[0] > 127 ? 4 : 0, rgb[1] > 127 ? 2 : 0, rgb[2] > 127 ? 1 : 0] - return rgb[0]+rgb[1]+rgb[2] + let rgb = map(split(a:rgb[1:], '..\zs'), '0 + ("0x".v:val)') + return airline#msdos#round_msdos_colors(rgb) endfunction function! s:get_syn(group, what) diff --git a/autoload/airline/msdos.vim b/autoload/airline/msdos.vim new file mode 100644 index 0000000..92e9bb5 --- /dev/null +++ b/autoload/airline/msdos.vim @@ -0,0 +1,57 @@ +" MIT License. Copyright (c) 2013-2016 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 + +" basic 16 msdos from MSDOS +" see output of color, should be +" 0 Black +" 1 DarkBlue +" 2 DarkGreen +" 3 DarkCyan +" 4 DarkRed +" 5 DarkMagenta +" 6 Brown +" 7 LightGray +" 8 DarkGray +" 9 Blue +" 10 Green +" 11 Cyan +" 12 Red +" 13 Magenta +" 14 Yellow +" 15 White + +let s:basic16 = [ + \ [ 0x00, 0x00, 0x00 ], + \ [ 0x00, 0x00, 0x80 ], + \ [ 0x00, 0x80, 0x00 ], + \ [ 0x00, 0x80, 0x80 ], + \ [ 0x80, 0x00, 0x00 ], + \ [ 0x80, 0x00, 0x80 ], + \ [ 0x80, 0x80, 0x00 ], + \ [ 0xC0, 0xC0, 0xC0 ], + \ [ 0x80, 0x80, 0x80 ], + \ [ 0x00, 0x00, 0xFF ], + \ [ 0x00, 0xFF, 0x00 ], + \ [ 0x00, 0xFF, 0xFF ], + \ [ 0xFF, 0x00, 0x00 ], + \ [ 0xFF, 0x00, 0xFF ], + \ [ 0xFF, 0xFF, 0x00 ], + \ [ 0xFF, 0xFF, 0xFF ] + \ ] + +function! airline#msdos#round_msdos_colors(rgblist) + " Check for values from MSDOS 16 color terminal + let best = [] + let min = 100000 + let list = s:basic16 + for value in list + let t = abs(value[0] - a:rgblist[0]) + + \ abs(value[1] - a:rgblist[1]) + + \ abs(value[2] - a:rgblist[2]) + if min > t + let min = t + let best = value + endif + endfor + return index(s:basic16, best) +endfunction