desert256.vim 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. " Vim color file
  2. " Maintainer: Henry So, Jr. <henryso@panix.com>
  3. " These are the colors of the "desert" theme by Hans Fugal with a few small
  4. " modifications (namely that I lowered the intensity of the normal white and
  5. " made the normal and nontext backgrounds black), modified to work with 88-
  6. " and 256-color xterms.
  7. "
  8. " The original "desert" theme is available as part of the vim distribution or
  9. " at http://hans.fugal.net/vim/colors/.
  10. "
  11. " The real feature of this color scheme, with a wink to the "inkpot" theme, is
  12. " the programmatic approximation of the gui colors to the palettes of 88- and
  13. " 256- color xterms. The functions that do this (folded away, for
  14. " readability) are calibrated to the colors used for Thomas E. Dickey's xterm
  15. " (version 200), which is available at http://dickey.his.com/xterm/xterm.html.
  16. "
  17. " I struggled with trying to parse the rgb.txt file to avoid the necessity of
  18. " converting color names to #rrggbb form, but decided it was just not worth
  19. " the effort. Maybe someone seeing this may decide otherwise...
  20. set background=dark
  21. if version > 580
  22. " no guarantees for version 5.8 and below, but this makes it stop
  23. " complaining
  24. hi clear
  25. if exists("syntax_on")
  26. syntax reset
  27. endif
  28. endif
  29. let g:colors_name="desert256"
  30. if has("gui_running") || &t_Co == 88 || &t_Co == 256
  31. " functions {{{
  32. " returns an approximate grey index for the given grey level
  33. fun <SID>grey_number(x)
  34. if &t_Co == 88
  35. if a:x < 23
  36. return 0
  37. elseif a:x < 69
  38. return 1
  39. elseif a:x < 103
  40. return 2
  41. elseif a:x < 127
  42. return 3
  43. elseif a:x < 150
  44. return 4
  45. elseif a:x < 173
  46. return 5
  47. elseif a:x < 196
  48. return 6
  49. elseif a:x < 219
  50. return 7
  51. elseif a:x < 243
  52. return 8
  53. else
  54. return 9
  55. endif
  56. else
  57. if a:x < 14
  58. return 0
  59. else
  60. let l:n = (a:x - 8) / 10
  61. let l:m = (a:x - 8) % 10
  62. if l:m < 5
  63. return l:n
  64. else
  65. return l:n + 1
  66. endif
  67. endif
  68. endif
  69. endfun
  70. " returns the actual grey level represented by the grey index
  71. fun <SID>grey_level(n)
  72. if &t_Co == 88
  73. if a:n == 0
  74. return 0
  75. elseif a:n == 1
  76. return 46
  77. elseif a:n == 2
  78. return 92
  79. elseif a:n == 3
  80. return 115
  81. elseif a:n == 4
  82. return 139
  83. elseif a:n == 5
  84. return 162
  85. elseif a:n == 6
  86. return 185
  87. elseif a:n == 7
  88. return 208
  89. elseif a:n == 8
  90. return 231
  91. else
  92. return 255
  93. endif
  94. else
  95. if a:n == 0
  96. return 0
  97. else
  98. return 8 + (a:n * 10)
  99. endif
  100. endif
  101. endfun
  102. " returns the palette index for the given grey index
  103. fun <SID>grey_color(n)
  104. if &t_Co == 88
  105. if a:n == 0
  106. return 16
  107. elseif a:n == 9
  108. return 79
  109. else
  110. return 79 + a:n
  111. endif
  112. else
  113. if a:n == 0
  114. return 16
  115. elseif a:n == 25
  116. return 231
  117. else
  118. return 231 + a:n
  119. endif
  120. endif
  121. endfun
  122. " returns an approximate color index for the given color level
  123. fun <SID>rgb_number(x)
  124. if &t_Co == 88
  125. if a:x < 69
  126. return 0
  127. elseif a:x < 172
  128. return 1
  129. elseif a:x < 230
  130. return 2
  131. else
  132. return 3
  133. endif
  134. else
  135. if a:x < 75
  136. return 0
  137. else
  138. let l:n = (a:x - 55) / 40
  139. let l:m = (a:x - 55) % 40
  140. if l:m < 20
  141. return l:n
  142. else
  143. return l:n + 1
  144. endif
  145. endif
  146. endif
  147. endfun
  148. " returns the actual color level for the given color index
  149. fun <SID>rgb_level(n)
  150. if &t_Co == 88
  151. if a:n == 0
  152. return 0
  153. elseif a:n == 1
  154. return 139
  155. elseif a:n == 2
  156. return 205
  157. else
  158. return 255
  159. endif
  160. else
  161. if a:n == 0
  162. return 0
  163. else
  164. return 55 + (a:n * 40)
  165. endif
  166. endif
  167. endfun
  168. " returns the palette index for the given R/G/B color indices
  169. fun <SID>rgb_color(x, y, z)
  170. if &t_Co == 88
  171. return 16 + (a:x * 16) + (a:y * 4) + a:z
  172. else
  173. return 16 + (a:x * 36) + (a:y * 6) + a:z
  174. endif
  175. endfun
  176. " returns the palette index to approximate the given R/G/B color levels
  177. fun <SID>color(r, g, b)
  178. " get the closest grey
  179. let l:gx = <SID>grey_number(a:r)
  180. let l:gy = <SID>grey_number(a:g)
  181. let l:gz = <SID>grey_number(a:b)
  182. " get the closest color
  183. let l:x = <SID>rgb_number(a:r)
  184. let l:y = <SID>rgb_number(a:g)
  185. let l:z = <SID>rgb_number(a:b)
  186. if l:gx == l:gy && l:gy == l:gz
  187. " there are two possibilities
  188. let l:dgr = <SID>grey_level(l:gx) - a:r
  189. let l:dgg = <SID>grey_level(l:gy) - a:g
  190. let l:dgb = <SID>grey_level(l:gz) - a:b
  191. let l:dgrey = (l:dgr * l:dgr) + (l:dgg * l:dgg) + (l:dgb * l:dgb)
  192. let l:dr = <SID>rgb_level(l:gx) - a:r
  193. let l:dg = <SID>rgb_level(l:gy) - a:g
  194. let l:db = <SID>rgb_level(l:gz) - a:b
  195. let l:drgb = (l:dr * l:dr) + (l:dg * l:dg) + (l:db * l:db)
  196. if l:dgrey < l:drgb
  197. " use the grey
  198. return <SID>grey_color(l:gx)
  199. else
  200. " use the color
  201. return <SID>rgb_color(l:x, l:y, l:z)
  202. endif
  203. else
  204. " only one possibility
  205. return <SID>rgb_color(l:x, l:y, l:z)
  206. endif
  207. endfun
  208. " returns the palette index to approximate the 'rrggbb' hex string
  209. fun <SID>rgb(rgb)
  210. let l:r = ("0x" . strpart(a:rgb, 0, 2)) + 0
  211. let l:g = ("0x" . strpart(a:rgb, 2, 2)) + 0
  212. let l:b = ("0x" . strpart(a:rgb, 4, 2)) + 0
  213. return <SID>color(l:r, l:g, l:b)
  214. endfun
  215. " sets the highlighting for the given group
  216. fun <SID>X(group, fg, bg, attr)
  217. if a:fg != ""
  218. exec "hi " . a:group . " guifg=#" . a:fg . " ctermfg=" . <SID>rgb(a:fg)
  219. endif
  220. if a:bg != ""
  221. exec "hi " . a:group . " guibg=#" . a:bg . " ctermbg=" . <SID>rgb(a:bg)
  222. endif
  223. if a:attr != ""
  224. exec "hi " . a:group . " gui=" . a:attr . " cterm=" . a:attr
  225. endif
  226. endfun
  227. " }}}
  228. call <SID>X("Normal", "cccccc", "000000", "")
  229. " highlight groups
  230. call <SID>X("Cursor", "708090", "f0e68c", "")
  231. "CursorIM
  232. "Directory
  233. "DiffAdd
  234. "DiffChange
  235. "DiffDelete
  236. "DiffText
  237. "ErrorMsg
  238. call <SID>X("VertSplit", "c2bfa5", "7f7f7f", "reverse")
  239. call <SID>X("Folded", "ffd700", "4d4d4d", "")
  240. call <SID>X("FoldColumn", "d2b48c", "4d4d4d", "")
  241. call <SID>X("IncSearch", "708090", "f0e68c", "")
  242. "LineNr
  243. call <SID>X("ModeMsg", "daa520", "", "")
  244. call <SID>X("MoreMsg", "2e8b57", "", "")
  245. call <SID>X("NonText", "addbe7", "000000", "bold")
  246. call <SID>X("Question", "00ff7f", "", "")
  247. call <SID>X("Search", "f5deb3", "cd853f", "")
  248. call <SID>X("SpecialKey", "9acd32", "", "")
  249. call <SID>X("StatusLine", "c2bfa5", "000000", "reverse")
  250. call <SID>X("StatusLineNC", "c2bfa5", "7f7f7f", "reverse")
  251. call <SID>X("Title", "cd5c5c", "", "")
  252. call <SID>X("Visual", "6b8e23", "f0e68c", "reverse")
  253. "VisualNOS
  254. call <SID>X("WarningMsg", "fa8072", "", "")
  255. "WildMenu
  256. "Menu
  257. "Scrollbar
  258. "Tooltip
  259. " syntax highlighting groups
  260. call <SID>X("Comment", "87ceeb", "", "")
  261. call <SID>X("Constant", "ffa0a0", "", "")
  262. call <SID>X("Identifier", "98fb98", "", "none")
  263. call <SID>X("Statement", "f0e68c", "", "bold")
  264. call <SID>X("PreProc", "cd5c5c", "", "")
  265. call <SID>X("Type", "bdb76b", "", "bold")
  266. call <SID>X("Special", "ffdead", "", "")
  267. "Underlined
  268. call <SID>X("Ignore", "666666", "", "")
  269. "Error
  270. call <SID>X("Todo", "ff4500", "eeee00", "")
  271. " delete functions {{{
  272. delf <SID>X
  273. delf <SID>rgb
  274. delf <SID>color
  275. delf <SID>rgb_color
  276. delf <SID>rgb_level
  277. delf <SID>rgb_number
  278. delf <SID>grey_color
  279. delf <SID>grey_level
  280. delf <SID>grey_number
  281. " }}}
  282. else
  283. " color terminal definitions
  284. hi SpecialKey ctermfg=darkgreen
  285. hi NonText cterm=bold ctermfg=darkblue
  286. hi Directory ctermfg=darkcyan
  287. hi ErrorMsg cterm=bold ctermfg=7 ctermbg=1
  288. hi IncSearch cterm=NONE ctermfg=yellow ctermbg=green
  289. hi Search cterm=NONE ctermfg=grey ctermbg=blue
  290. hi MoreMsg ctermfg=darkgreen
  291. hi ModeMsg cterm=NONE ctermfg=brown
  292. hi LineNr ctermfg=3
  293. hi Question ctermfg=green
  294. hi StatusLine cterm=bold,reverse
  295. hi StatusLineNC cterm=reverse
  296. hi VertSplit cterm=reverse
  297. hi Title ctermfg=5
  298. hi Visual cterm=reverse
  299. hi VisualNOS cterm=bold,underline
  300. hi WarningMsg ctermfg=1
  301. hi WildMenu ctermfg=0 ctermbg=3
  302. hi Folded ctermfg=darkgrey ctermbg=NONE
  303. hi FoldColumn ctermfg=darkgrey ctermbg=NONE
  304. hi DiffAdd ctermbg=4
  305. hi DiffChange ctermbg=5
  306. hi DiffDelete cterm=bold ctermfg=4 ctermbg=6
  307. hi DiffText cterm=bold ctermbg=1
  308. hi Comment ctermfg=darkcyan
  309. hi Constant ctermfg=brown
  310. hi Special ctermfg=5
  311. hi Identifier ctermfg=6
  312. hi Statement ctermfg=3
  313. hi PreProc ctermfg=5
  314. hi Type ctermfg=2
  315. hi Underlined cterm=underline ctermfg=5
  316. hi Ignore ctermfg=darkgrey
  317. hi Error cterm=bold ctermfg=7 ctermbg=1
  318. endif
  319. " vim: set fdl=0 fdm=marker: