Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " This script allows for a colour scheme to specify colours as #RRGGBB
- " and have them mapped to the nearest colours in the Xterm-style cube.
- " Xterms of 8, 16, 88, and 256 colours are supported.
- if &t_Co == 256
- function! High#Map(r, g, b)
- if (a:r == a:g) && (a:g == a:b)
- if (a:r >= 250)
- return 231
- else
- return 232 + (10 * a:r) / 104
- endif
- else
- return 16 + 36 * (a:r / 43) + 6 * (a:g / 43) + (a:b / 43)
- endif
- endfunction
- elseif &t_Co == 88
- function! High#Map(r, g, b)
- if (a:r == a:g) && (a:g == a:b)
- if (a:r >= 250)
- return 79
- else
- return 80 + a:r / 32
- endif
- else
- return 16 + 16 * (a:r / 77) + 4 * (a:g / 77) + (a:b / 77)
- endif
- endfunction
- else
- function! High#Map(r, g, b)
- if (a:r == a:g) && (a:g == a:b)
- let n = a:r / 16
- let s = "088888888888777F"
- else
- let n = 16 * (a:r / 77) + 4 * (a:g / 77) + (a:b / 77)
- let s = "044C266E266EAEEE155D384C326EBAEE155D315D337CBBAE9DDDB9DDBB9DBBBF"
- endif
- let c = str2nr(strpart(s, n, 1), 16)
- if &t_Co < 16
- let c = c % 8
- endif
- return c
- endfunction
- endif
- function! High#Color(c)
- if a:c !~ "^#"
- if a:c == "bg"
- return "none"
- else
- return a:c
- endif
- endif
- let r = str2nr(strpart(a:c, 1, 2), 16)
- let g = str2nr(strpart(a:c, 3, 2), 16)
- let b = str2nr(strpart(a:c, 5, 2), 16)
- return High#Map(r, g, b)
- endfunction
- function! High#GuiColor(c, d)
- if a:c !~ "^#"
- if a:c == "none"
- return a:d
- else
- return a:c
- endif
- endif
- return a:c
- endfunction
- function! High#Light(what, how, bg, fg)
- let cbg = High#Color(a:bg)
- let cfg = High#Color(a:fg)
- let gbg = High#GuiColor(a:bg, "bg")
- let gfg = High#GuiColor(a:fg, "fg")
- execute "highlight " . a:what . " cterm=" . a:how
- execute "highlight " . a:what . " ctermbg=" . cbg
- execute "highlight " . a:what . " ctermfg=" . cfg
- execute "highlight " . a:what . " gui=" . a:how
- execute "highlight " . a:what . " guibg=" . gbg
- execute "highlight " . a:what . " guifg=" . gfg
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment