simple256.vim 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. " Vim color file
  2. " Maintainer: Alexander Rodin <rodin.alexander@gmail.com>
  3. "
  4. " This theme is based on "desert256" theme by Henry So, Jr.
  5. "
  6. " I struggled with trying to parse the rgb.txt file to avoid the necessity of
  7. " converting color names to #rrggbb form, but decided it was just not worth
  8. " the effort. Maybe someone seeing this may decide otherwise...
  9. set background=light
  10. if version > 580
  11. " no guarantees for version 5.8 and below, but this makes it stop
  12. " complaining
  13. hi clear
  14. if exists("syntax_on")
  15. syntax reset
  16. endif
  17. endif
  18. let g:colors_name="desert256"
  19. if has("gui_running") || &t_Co == 88 || &t_Co == 256
  20. " functions {{{
  21. " returns an approximate grey index for the given grey level
  22. fun <SID>grey_number(x)
  23. if &t_Co == 88
  24. if a:x < 23
  25. return 0
  26. elseif a:x < 69
  27. return 1
  28. elseif a:x < 103
  29. return 2
  30. elseif a:x < 127
  31. return 3
  32. elseif a:x < 150
  33. return 4
  34. elseif a:x < 173
  35. return 5
  36. elseif a:x < 196
  37. return 6
  38. elseif a:x < 219
  39. return 7
  40. elseif a:x < 243
  41. return 8
  42. else
  43. return 9
  44. endif
  45. else
  46. if a:x < 14
  47. return 0
  48. else
  49. let l:n = (a:x - 8) / 10
  50. let l:m = (a:x - 8) % 10
  51. if l:m < 5
  52. return l:n
  53. else
  54. return l:n + 1
  55. endif
  56. endif
  57. endif
  58. endfun
  59. " returns the actual grey level represented by the grey index
  60. fun <SID>grey_level(n)
  61. if &t_Co == 88
  62. if a:n == 0
  63. return 0
  64. elseif a:n == 1
  65. return 46
  66. elseif a:n == 2
  67. return 92
  68. elseif a:n == 3
  69. return 115
  70. elseif a:n == 4
  71. return 139
  72. elseif a:n == 5
  73. return 162
  74. elseif a:n == 6
  75. return 185
  76. elseif a:n == 7
  77. return 208
  78. elseif a:n == 8
  79. return 231
  80. else
  81. return 255
  82. endif
  83. else
  84. if a:n == 0
  85. return 0
  86. else
  87. return 8 + (a:n * 10)
  88. endif
  89. endif
  90. endfun
  91. " returns the palette index for the given grey index
  92. fun <SID>grey_color(n)
  93. if &t_Co == 88
  94. if a:n == 0
  95. return 16
  96. elseif a:n == 9
  97. return 79
  98. else
  99. return 79 + a:n
  100. endif
  101. else
  102. if a:n == 0
  103. return 16
  104. elseif a:n == 25
  105. return 231
  106. else
  107. return 231 + a:n
  108. endif
  109. endif
  110. endfun
  111. " returns an approximate color index for the given color level
  112. fun <SID>rgb_number(x)
  113. if &t_Co == 88
  114. if a:x < 69
  115. return 0
  116. elseif a:x < 172
  117. return 1
  118. elseif a:x < 230
  119. return 2
  120. else
  121. return 3
  122. endif
  123. else
  124. if a:x < 75
  125. return 0
  126. else
  127. let l:n = (a:x - 55) / 40
  128. let l:m = (a:x - 55) % 40
  129. if l:m < 20
  130. return l:n
  131. else
  132. return l:n + 1
  133. endif
  134. endif
  135. endif
  136. endfun
  137. " returns the actual color level for the given color index
  138. fun <SID>rgb_level(n)
  139. if &t_Co == 88
  140. if a:n == 0
  141. return 0
  142. elseif a:n == 1
  143. return 139
  144. elseif a:n == 2
  145. return 205
  146. else
  147. return 255
  148. endif
  149. else
  150. if a:n == 0
  151. return 0
  152. else
  153. return 55 + (a:n * 40)
  154. endif
  155. endif
  156. endfun
  157. " returns the palette index for the given R/G/B color indices
  158. fun <SID>rgb_color(x, y, z)
  159. if &t_Co == 88
  160. return 16 + (a:x * 16) + (a:y * 4) + a:z
  161. else
  162. return 16 + (a:x * 36) + (a:y * 6) + a:z
  163. endif
  164. endfun
  165. " returns the palette index to approximate the given R/G/B color levels
  166. fun <SID>color(r, g, b)
  167. " get the closest grey
  168. let l:gx = <SID>grey_number(a:r)
  169. let l:gy = <SID>grey_number(a:g)
  170. let l:gz = <SID>grey_number(a:b)
  171. " get the closest color
  172. let l:x = <SID>rgb_number(a:r)
  173. let l:y = <SID>rgb_number(a:g)
  174. let l:z = <SID>rgb_number(a:b)
  175. if l:gx == l:gy && l:gy == l:gz
  176. " there are two possibilities
  177. let l:dgr = <SID>grey_level(l:gx) - a:r
  178. let l:dgg = <SID>grey_level(l:gy) - a:g
  179. let l:dgb = <SID>grey_level(l:gz) - a:b
  180. let l:dgrey = (l:dgr * l:dgr) + (l:dgg * l:dgg) + (l:dgb * l:dgb)
  181. let l:dr = <SID>rgb_level(l:gx) - a:r
  182. let l:dg = <SID>rgb_level(l:gy) - a:g
  183. let l:db = <SID>rgb_level(l:gz) - a:b
  184. let l:drgb = (l:dr * l:dr) + (l:dg * l:dg) + (l:db * l:db)
  185. if l:dgrey < l:drgb
  186. " use the grey
  187. return <SID>grey_color(l:gx)
  188. else
  189. " use the color
  190. return <SID>rgb_color(l:x, l:y, l:z)
  191. endif
  192. else
  193. " only one possibility
  194. return <SID>rgb_color(l:x, l:y, l:z)
  195. endif
  196. endfun
  197. " returns the palette index to approximate the 'rrggbb' hex string
  198. fun <SID>rgb(rgb)
  199. let l:r = ("0x" . strpart(a:rgb, 0, 2)) + 0
  200. let l:g = ("0x" . strpart(a:rgb, 2, 2)) + 0
  201. let l:b = ("0x" . strpart(a:rgb, 4, 2)) + 0
  202. return <SID>color(l:r, l:g, l:b)
  203. endfun
  204. " sets the highlighting for the given group
  205. fun <SID>X(group, fg, bg, attr)
  206. if a:fg != ""
  207. exec "hi " . a:group . " guifg=#" . a:fg . " ctermfg=" . <SID>rgb(a:fg)
  208. endif
  209. if a:bg != ""
  210. exec "hi " . a:group . " guibg=#" . a:bg . " ctermbg=" . <SID>rgb(a:bg)
  211. endif
  212. if a:attr != ""
  213. exec "hi " . a:group . " gui=" . a:attr . " cterm=" . a:attr
  214. endif
  215. endfun
  216. " }}}
  217. call <SID>X("VertSplit", "c2bfa5", "7f7f7f", "reverse")
  218. call <SID>X("Folded", "9999cc", "f4f4f4", "")
  219. call <SID>X("IncSearch", "708090", "f0e68c", "")
  220. call <SID>X("Visual", "3888ff", "ffffff", "reverse")
  221. " call <SID>X("Comment", "1C9518", "", "")
  222. call <SID>X("Comment", "20AD1B", "", "")
  223. call <SID>X("Constant", "5500ff", "", "")
  224. call <SID>X("String", "ff7777", "", "")
  225. call <SID>X("Float", "ff7777", "", "")
  226. call <SID>X("Boolean", "000080", "", "bold")
  227. " call <SID>X("Identifier", "98fb98", "", "none")
  228. call <SID>X("Statement", "000080", "", "bold")
  229. call <SID>X("PreProc", "20b5ff", "", "")
  230. call <SID>X("Type", "000080", "", "bold")
  231. call <SID>X("Special", "CDAB00", "", "")
  232. call <SID>X("Underlined", "0000cc", "", "")
  233. call <SID>X("Todo", "ff4500", "eeee00", "")
  234. " delete functions {{{
  235. delf <SID>X
  236. delf <SID>rgb
  237. delf <SID>color
  238. delf <SID>rgb_color
  239. delf <SID>rgb_level
  240. delf <SID>rgb_number
  241. delf <SID>grey_color
  242. delf <SID>grey_level
  243. delf <SID>grey_number
  244. " }}}
  245. else
  246. " color terminal definitions
  247. hi VertSplit ctermfg=lightgray ctermbg=gray cterm=reverse
  248. hi Folded ctermfg=blue ctermbg=lightcyan
  249. hi IncSearch ctermfg=lightgray ctermbg=yellow
  250. hi Visual ctermfg=blue ctermbg=white cterm=reverse
  251. hi Comment ctermfg=green
  252. hi Constant ctermfg=blue
  253. hi String ctermfg=red
  254. hi Float ctermfg=red
  255. hi Boolean ctermfg=darkblue cterm=bold
  256. hi Statement ctermfg=darkblue cterm=bold
  257. hi PreProc ctermfg=cyan
  258. hi Type ctermfg=darkblue cterm=bold
  259. hi Special ctermfg=brown
  260. hi Underlined ctermfg=blue
  261. hi Todo ctermfg=red ctermbg=yellow
  262. endif
  263. " vim: set fdl=0 fdm=marker: