|
| 1 | +" Copyright (c) 2012, Matthew J. Wozniski |
| 2 | +" All rights reserved. |
| 3 | +" |
| 4 | +" Redistribution and use in source and binary forms, with or without |
| 5 | +" modification, are permitted provided that the following conditions are met: |
| 6 | +" * Redistributions of source code must retain the above copyright |
| 7 | +" notice, this list of conditions and the following disclaimer. |
| 8 | +" * Redistributions in binary form must reproduce the above copyright |
| 9 | +" notice, this list of conditions and the following disclaimer in the |
| 10 | +" documentation and/or other materials provided with the distribution. |
| 11 | +" * The names of the contributors may not be used to endorse or promote |
| 12 | +" products derived from this software without specific prior written |
| 13 | +" permission. |
| 14 | +" |
| 15 | +" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY |
| 16 | +" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 17 | +" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 18 | +" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY |
| 19 | +" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 20 | +" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 21 | +" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 22 | +" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | +" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 24 | +" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | + |
| 26 | +let s:xterm_colors = [ 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF ] |
| 27 | +let s:eterm_colors = [ 0x00, 0x2A, 0x55, 0x7F, 0xAA, 0xD4 ] |
| 28 | +let s:konsole_colors = [ 0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF ] |
| 29 | +let s:xterm_greys = [ 0x08, 0x12, 0x1C, 0x26, 0x30, 0x3A, |
| 30 | + \ 0x44, 0x4E, 0x58, 0x62, 0x6C, 0x76, |
| 31 | + \ 0x80, 0x8A, 0x94, 0x9E, 0xA8, 0xB2, |
| 32 | + \ 0xBC, 0xC6, 0xD0, 0xDA, 0xE4, 0xEE ] |
| 33 | + |
| 34 | +let s:urxvt_colors = [ 0x00, 0x8B, 0xCD, 0xFF ] |
| 35 | +let s:urxvt_greys = [ 0x2E, 0x5C, 0x73, 0x8B, |
| 36 | + \ 0xA2, 0xB9, 0xD0, 0xE7 ] |
| 37 | + |
| 38 | +" Uses &term to determine which cube should be use. If &term is set to |
| 39 | +" "xterm" or begins with "screen", the variables g:CSApprox_eterm and |
| 40 | +" g:CSApprox_konsole can be used to select a different palette. |
| 41 | +function! csapprox#common#PaletteType() |
| 42 | + if &t_Co == 88 |
| 43 | + let type = 'urxvt' |
| 44 | + elseif &term ==# 'xterm' || &term =~# '^screen' || &term==# 'builtin_gui' |
| 45 | + if exists('g:CSApprox_konsole') && g:CSApprox_konsole |
| 46 | + let type = 'konsole' |
| 47 | + elseif exists('g:CSApprox_eterm') && g:CSApprox_eterm |
| 48 | + let type = 'eterm' |
| 49 | + else |
| 50 | + let type = 'xterm' |
| 51 | + endif |
| 52 | + elseif &term =~? '^konsole' |
| 53 | + " Konsole only used its own palette up til KDE 4.2.0 |
| 54 | + if executable('kde4-config') && system('kde4-config --kde-version') =~ '^4\.[10]\.' |
| 55 | + let type = 'konsole' |
| 56 | + elseif executable('kde-config') && system('kde-config --version') =~# 'KDE: 3\.' |
| 57 | + let type = 'konsole' |
| 58 | + else |
| 59 | + let type = 'xterm' |
| 60 | + endif |
| 61 | + elseif &term =~? '^eterm' |
| 62 | + let type = 'eterm' |
| 63 | + else |
| 64 | + let type = 'xterm' |
| 65 | + endif |
| 66 | + |
| 67 | + return type |
| 68 | +endfunction |
| 69 | + |
| 70 | +" Retrieve the list of greyscale ramp colors for the current palette |
| 71 | +function! csapprox#common#Greys() |
| 72 | + return (&t_Co == 88 ? s:urxvt_greys : s:xterm_greys) |
| 73 | +endfunction |
| 74 | + |
| 75 | +" Retrieve the list of non-greyscale ramp colors for the current palette |
| 76 | +function! csapprox#common#Colors() |
| 77 | + return s:{csapprox#common#PaletteType()}_colors |
| 78 | +endfunction |
0 commit comments