Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for 8 and 16 color terminals.

Works with non-unicode characters sets (there is some degradation).
  • Loading branch information...
commit c0b29160a1cac0df4f94b9bd9e67f961c6ea3abe 1 parent 42edec9
megaannum authored
View
49 README.md
@@ -222,7 +222,8 @@ The Forms library ought to work on any platform where Vim has 256 colors
(or full RGB as with GVim) and a fixed width UTF-8 font which implements
the box drawing and block characters in a reasonable manner.
-## Linux Xterm & Vim
+## Linux Vim
+### Xterm
Forms was developed and extensively tested on a Linux Xterm platform.
As long as the Xterm is using the correct font, such as
@@ -236,45 +237,59 @@ works to launch an Xterm appropriately configured:
/usr/bin/xterm -g 80x30 -bg lightgrey -sl 1000 +si -fn \
'-misc-fixed-medium-r-normal-*-20-*-*-*-*-*-iso10646-*'
-The Xterm must also have 256 color support and such support is
-declared in the .vimrc file with:
+If with say, the font 10x20, then you may not be able to render all of
+the unicode characters, but it ought to still work.
- set t_Co=256
+There is support for 256, 88, 16 and 8 color Xterms though
+the 256 looks best. In your .vimrc file add one of:
-then, there ought not be a problem.
+ if ($TERM == 'xterm')
+ let &t_Co=256
+or
+ let &t_Co=88
+or
+ let &t_Co=16
+or
+ let &t_Co=8
+ endif
-## Linux urxvt256c & Vim
+if you need help in getting the correct number of colors in Vim.
+
+
+### urxvt256c
Forms simply works on the version of rxvt that supports Unicode and 256
-colors, urxvt256c. Add to .vimrc file:
+colors, urxvt256c.
+Vim knows that &t_Co == 256.
- set t_Co=256
+### urxvt
-## Linux urxvt & Vim
+Forms works with 88 color verion of rxvt that supports Unicode, urxvt.
+Vim knows that &t_Co == 88.
-Forms works with 88 colore rxvt that supports Unicode urxvt.
-Add to .vimrc file:
+### rxvt
- set t_Co=88
+Forms works with non-Unicode, 8 color rxvt.
+Vim knows that &t_Co == 8.
-## Linux Konsole & Vim
+### Konsole
Forms works kconsole (though kconsole's UTF-8 9608 2588 FULL BLOCK
does not render correctly).
Add to .vimrc file:
- set t_Co=256
+ let &t_Co=256
let g:FORMS_COLOR_TERM_KONSOLE = 1
-## Linux Eterm & Vim
+### Eterm
Forms works eterm (well, I hope it works, no access to ETerm so could not test).
Add to .vimrc file:
- set t_Co=256
+ let &t_Co=256
let g:FORMS_COLOR_TERM_ETERM = 1
-## Linux GVim
+### GVim
Some testing has been done on the Linux GVim platform and all of the
demonstration forms seem to work as expected.
View
73 autoload/forms.vim
@@ -5,8 +5,8 @@
" File: forms.vim
" Summary: Vim Form Library
" Author: Richard Emberson <richard.n.embersonATgmailDOTcom>
-" Last Modified: 08/30/2012
-" Version: 1.5
+" Last Modified: 06/30/2012
+" Version: 1.6
" Modifications:
" 1.0 : initial public release.
"
@@ -383,24 +383,13 @@ else
execute "hi BackgroundHi cterm=NONE ctermbg=" . backgroundNumber
-"let g:forms_log_enabled = g:self#IS_TRUE
-"call forms#log("FRAME")
-"call forms#log("backgroundNumber=".backgroundNumber)
let framefgNumber = forms#color#term#ConvertRGBTxt_2_Int(framefgColor)
-"call forms#log("framefgNumber=".framefgNumber)
let framebgNumber = forms#color#term#ConvertRGBTxt_2_Int(framebgColor)
-"call forms#log("framebgNumber=".framebgNumber)
execute "hi FrameHi cterm=NONE ctermfg=".framefgNumber." ctermbg=" . framebgNumber
-"let g:forms_log_enabled = g:self#IS_FALSE
-"let g:forms_log_enabled = g:self#IS_TRUE
-"call forms#log("DROPSHADOW")
-"call forms#log("backgroundNumber=".backgroundNumber)
let dropshadowfgNumber = forms#color#term#ConvertRGBTxt_2_Int(dropshadowfgColor)
let dropshadowbgNumber = forms#color#term#ConvertRGBTxt_2_Int(dropshadowbgColor)
-"call forms#log("dropshadowfgNumber=".dropshadowfgNumber)
execute "hi DropShadowHi cterm=NONE ctermbg=".dropshadowbgNumber." ctermfg=" . dropshadowfgNumber
-"let g:forms_log_enabled = g:self#IS_FALSE
let disableNumber = forms#color#term#ConvertRGBTxt_2_Int(disableColor)
@@ -6030,12 +6019,15 @@ function! forms#loadSliderPrototype()
endif
endif
- if self.__resolution < 0
+ if self.__resolution < 1
throw "Slider: resolution must 1, 2, 3 or 4: " . self.__resolution
endif
if self.__resolution > 4
throw "Slider: resolution must 1, 2, 3 or 4: " . self.__resolution
endif
+if &encoding != 'utf-8'
+let self.__resolution = 1
+endif
return self
endfunction
@@ -6400,7 +6392,11 @@ function! forms#loadHSliderPrototype()
let size = self.__size
let resolution = self.__resolution
- let full = b:forms_FullB
+ if &encoding == 'utf-8'
+ let full = b:forms_FullB
+ else
+ let full = 'X'
+ endif
" call forms#log("g:forms#HSlider.draw resolution=" . resolution)
" nos possible positions = resolution * (size-1) + 1
@@ -6412,9 +6408,9 @@ function! forms#loadHSliderPrototype()
call forms#SetHCharsAt(' ', (size-1), line, column)
call forms#SetCharAt(full, line, column+size-1)
else
- call forms#SetHCharsAt(' ', (pos-1), line, column)
+ call forms#SetHCharsAt(' ', pos, line, column)
call forms#SetCharAt(full, line, column+pos)
- call forms#SetHCharsAt(' ', (size-pos=1), line, column+pos+1)
+ call forms#SetHCharsAt(' ', (size-pos-1), line, column+pos+1)
endif
elseif resolution == 2
@@ -6425,27 +6421,18 @@ function! forms#loadHSliderPrototype()
let offset = value * nosoffsets/(upper-lower+1)
let p = (offset/el_per_cell) * el_per_cell
let i = offset - p
-" call forms#log("g:forms#HSlider.draw nosoffsets=" . nosoffsets)
-" call forms#log("g:forms#HSlider.draw value=" . value)
-" call forms#log("g:forms#HSlider.draw offset=" . offset)
-" call forms#log("g:forms#HSlider.draw p=" . p)
-" call forms#log("g:forms#HSlider.draw i=" . i)
let pp = p / el_per_cell
-" call forms#log("g:forms#HSlider.draw pp=" . pp)
if i == 0
if pp == 0
-" call forms#log("g:forms#HSlider.draw A")
call forms#SetCharAt(full, line, column)
call forms#SetHCharsAt(' ', (size-1), line, column+1)
elseif pp == size-1
-" call forms#log("g:forms#HSlider.draw B")
call forms#SetHCharsAt(' ', (size-1), line, column)
call forms#SetCharAt(full, line, column+size-1)
else
-" call forms#log("g:forms#HSlider.draw C")
call forms#SetHCharsAt(' ', (pp), line, column)
" call forms#SetCharAt(' ', line, column+pp-1)
call forms#SetCharAt(full, line, column+pp)
@@ -6454,7 +6441,6 @@ function! forms#loadHSliderPrototype()
endif
else
-" call forms#log("g:forms#HSlider.draw D")
if pp > 0
call forms#SetHCharsAt(' ', (pp), line, column)
endif
@@ -6744,7 +6730,11 @@ function! forms#loadVSliderPrototype()
let size = self.__size
let resolution = self.__resolution
- let full = b:forms_FullB
+ if &encoding == 'utf-8'
+ let full = b:forms_FullB
+ else
+ let full = 'X'
+ endif
" call forms#log("g:forms#VSlider.draw resolution=" . resolution)
" nos possible positions = resolution * (size-1) + 1
@@ -6756,9 +6746,9 @@ function! forms#loadVSliderPrototype()
call forms#SetVCharsAt(' ', (size-1), line, column)
call forms#SetCharAt(full, line+size-1, column)
else
- call forms#SetVCharsAt(' ', (pos-1), line, column)
+ call forms#SetVCharsAt(' ', pos, line, column)
call forms#SetCharAt(full, line+pos, column)
- call forms#SetVCharsAt(' ', (size-pos=1), line+pos+1, column)
+ call forms#SetVCharsAt(' ', (size-pos-1), line+pos+1, column)
endif
elseif resolution == 2
@@ -7164,7 +7154,6 @@ function! forms#loadBoxPrototype()
if self.__status != g:IS_INVISIBLE
let m = 1
-
call forms#DrawBox(self.__mode, a.line, a.column, a.width, a.height)
" call forms#log("g:forms#Box.draw calling body")
@@ -7402,7 +7391,9 @@ function! forms#loadDropShadowPrototype()
let hi = self.__highlight
+if &encoding == 'utf-8'
call forms#DrawDropShadow(c, line, column, width-1, height-1)
+endif
if c == 'ul'
call GlyphHilight(self, hi, {
@@ -7585,7 +7576,9 @@ function! forms#loadFramePrototype()
let hi = self.__highlight
"call forms#log("g:forms#Frame.draw c=".c)
+if &encoding == 'utf-8'
call forms#DrawFrame(c, line, column, width, height)
+endif
call GlyphHilight(self, hi, {
\ 'line': line,
@@ -14616,15 +14609,19 @@ function! forms#addBoxDrawingCharacterSet(name, dr, uh, dl, rv, ul, lh, ur, lv,)
endfunction
function! forms#LookupBoxDrawingCharacterSet(name)
- if has_key(s:boxDrawingCharacterSets, a:name)
- return s:boxDrawingCharacterSets[a:name]
- else
- call forms#log("LookupBoxDrawingCharacterSet: unknown box drawing character set: " . a:name)
- if &encoding == 'utf-8'
- return s:boxDrawingCharacterSets['light']
+ if &encoding == 'utf-8'
+ if has_key(s:boxDrawingCharacterSets, a:name)
+ return s:boxDrawingCharacterSets[a:name]
else
- return s:boxDrawingCharacterSets['default']
+ call forms#log("LookupBoxDrawingCharacterSet: unknown box drawing character set: " . a:name)
+ if &encoding == 'utf-8'
+ return s:boxDrawingCharacterSets['light']
+ else
+ return s:boxDrawingCharacterSets['default']
+ endif
endif
+ else
+ return s:boxDrawingCharacterSets['default']
endif
endfunction
View
2  autoload/forms/color/eterm.vim
@@ -298,7 +298,7 @@ endwhile
" 6 intensity RGB
" intensities = [0, 42, 85, 127, 170, 212]
" intensities = (0x00, 0x2a, 0x55, 0x7f, 0xaa, 0xd4)
-let forms#color#eterm#intensities256 = [
+let s:intensities = [
\ str2nr("0x00",16),
\ str2nr("0x2a",16),
\ str2nr("0x55",16),
View
4 autoload/forms/color/konsole.vim
@@ -298,7 +298,7 @@ endwhile
" 6 intensity RGB
" intensities = [0, 51, 102, 153, 204, 255]
" intensities = (0x00, 0x33, 0x66, 0x99, 0xcc, 0xff )
-let forms#color#konsole#intensities256 = [
+let s:intensities = [
\ str2nr("0x00",16),
\ str2nr("0x33",16),
\ str2nr("0x66",16),
@@ -316,7 +316,7 @@ let forms#color#konsole#intensities256 = [
" rgb : Parameters accepted by ParseRGB
" ------------------------------------------------------------
-" binary search over possible intensities256
+" binary search over possible intensities
function! s:GetPartial_Int256(n)
" intensities = [0, 51, 102, 153, 204, 255]
" intensities = (0x00, 0x33, 0x66, 0x99, 0xcc, 0xff )
View
175 autoload/forms/color/rxvt.vim
@@ -0,0 +1,175 @@
+" ============================================================================
+" rxvt.vim
+"
+" File: rxvt.vim
+" Summary: Rxvt 8 colors (part of Forms Library)
+" Author: Richard Emberson <richard.n.embersonATgmailDOTcom>
+" ============================================================================
+
+" ------------------------------------------------------------
+" Define Int_2_Name Dictionary: {{{2
+" Refs:
+" rxvt-unicode-9.1.5 src/init.C
+" ------------------------------------------------------------
+let s:Int_2_Name = {
+ \ '0': 'black',
+ \ '1': 'red3',
+ \ '2': 'green3',
+ \ '3': 'yellow3',
+ \ '4': 'blue3',
+ \ '5': 'magenta3',
+ \ '6': 'cyan3',
+ \ '7': 'AntiqueWhite'
+ \ }
+
+" ------------------------------------------------------------
+" Define Int_2_RGB Dictionary: {{{2
+" Refs:
+" rxvt-9.1.5 src/init.C
+" ------------------------------------------------------------
+let s:Int_2_RGB = {
+ \ '0': '000000',
+ \ '1': 'cd0000',
+ \ '2': '00cd00',
+ \ '3': 'cdcd00',
+ \ '4': '0000cd',
+ \ '5': 'cd00cd',
+ \ '6': '00cdcd',
+ \ '7': 'faebd7'
+ \ }
+
+" ------------------------------------------------------------
+" Generate RGB_2_Int Dictionary: {{{2
+" WHAT A HACK!!!
+" ------------------------------------------------------------
+let s:RGB_2_Int = {}
+for key in sort(keys(s:Int_2_RGB))
+ let s:RGB_2_Int[s:Int_2_RGB[key]] = key
+endfor
+let s:RGB_2_Int['cdcdcd'] = '7'
+
+let s:RGB_2_Int['cdcdd7'] = '7'
+let s:RGB_2_Int['cdebcd'] = '7'
+let s:RGB_2_Int['facdcd'] = '7'
+
+let s:RGB_2_Int['cdebd7'] = '7'
+let s:RGB_2_Int['facdd7'] = '7'
+let s:RGB_2_Int['faebcd'] = '7'
+
+let s:RGB_2_Int['fa0000'] = '1'
+let s:RGB_2_Int['00eb00'] = '2'
+let s:RGB_2_Int['0000d7'] = '4'
+
+let s:RGB_2_Int['faeb00'] = '3'
+let s:RGB_2_Int['cdeb00'] = '3'
+let s:RGB_2_Int['facd00'] = '3'
+
+let s:RGB_2_Int['fa00cd'] = '5'
+let s:RGB_2_Int['fa00d7'] = '5'
+let s:RGB_2_Int['cd00d7'] = '5'
+
+let s:RGB_2_Int['00ebd7'] = '6'
+let s:RGB_2_Int['00cdd7'] = '6'
+let s:RGB_2_Int['00ebcd'] = '6'
+
+
+" rxvt number to rgb string
+let s:ColorTable= []
+" TODO make into list of [r,g,b] values
+let cnt = 0
+while cnt < 8
+ let rgb = s:Int_2_RGB[cnt]
+ let r = rgb[0:1]
+ let g = rgb[2:3]
+ let b = rgb[4:5]
+ let rn = str2nr(r, 16)
+ let gn = str2nr(g, 16)
+ let bn = str2nr(b, 16)
+ call add(s:ColorTable, [rn,gn,bn])
+
+ let cnt += 1
+endwhile
+
+if 0
+" intensities=[0, 139, 205, 255]
+" intensities = (0x00, 0x8b, 0xcd, 0xff)
+let s:intensities = [
+ \ str2nr("0x00",16),
+ \ str2nr("0x8b",16),
+ \ str2nr("0xcd",16),
+ \ str2nr("0xff",16)
+ \ ]
+endif
+
+
+" ------------------------------------------------------------
+" ConvertRGB_2_Int: {{{2
+" Converts an rgb String to a rxvt 8 Number
+" Tried to make this fast.
+" Returns the rxvt 8 Number
+" parameters:
+" rgb : Parameters accepted by ParseRGB
+" ------------------------------------------------------------
+function! forms#color#rxvt#ConvertRGB_2_Int(rn, gn, bn)
+"let start = reltime()
+ let rn = a:rn
+ let gn = a:gn
+ let bn = a:bn
+
+" call forms#log("ConvertRGB_2_Int: in rn=". rn)
+" call forms#log("ConvertRGB_2_Int: in gn=". gn)
+" call forms#log("ConvertRGB_2_Int: in bn=". bn)
+
+ " red
+ if rn <= 205
+ let rnx = ((rn+rn) <= 205) ? 0 : 205
+ else
+ let rnx = ((rn+rn) <= 455) ? 205 : 250
+ endif
+
+ " green
+ if gn <= 205
+ let gnx = ((gn+gn) <= 205) ? 0 : 205
+ else
+ let gnx = ((gn+gn) <= 440) ? 205 : 235
+ endif
+ if bn <= 205
+ let bnx = ((bn+bn) <= 205) ? 0 : 205
+ else
+ let bnx = ((bn+bn) <= 420) ? 205 : 215
+ endif
+
+" call forms#log("ConvertRGB_2_Int: outjrnx=". rnx)
+" call forms#log("ConvertRGB_2_Int: outjgnx=". gnx)
+" call forms#log("ConvertRGB_2_Int: outjbnx=". bnx)
+
+ let rgbtxt = printf('%02x%02x%02x',rnx,gnx,bnx)
+" call forms#log("ConvertRGB_2_Int: rgbtxt=". rgbtxt)
+ let n = s:RGB_2_Int[rgbtxt]
+"call forms#log("ConvertRGB_2_Int: time=". reltimestr(reltime(start)))
+" call forms#log("ConvertRGB_2_Int: n=". n)
+ return n
+endfunction
+
+" ------------------------------------------------------------
+" ConvertInt_2_RGB: {{{2
+" Converts an 8 String or Number to an rgb String
+" Returns the rgb String
+" parameters:
+" nr : String or Number or rxvt 8 value
+" value must be 0 <= value <= 8
+" ------------------------------------------------------------
+function! forms#color#rxvt#ConvertInt_2_RGB(nr)
+ if (type(a:nr) == g:self#NUMBER_TYPE)
+ return s:Int_2_RGB[a:nr]
+ elseif (type(a:nr) == g:self#STRING_TYPE)
+ return s:Int_2_RGB[a:nr]
+ else
+ throw "FORMS_COLOR_UTIL_ConvertInt_2_RGB: Bad number: " . string(a:nsstr)
+ endif
+endfunction
+
+" ================
+" Modelines: {{{1
+" ================
+" vim: ts=4 fdm=marker
View
107 autoload/forms/color/term.vim
@@ -8,6 +8,40 @@
" http://vim.wikia.com/wiki/256_colors_setup_for_console_Vim
+
+
+
+" ------------------------------------------------------------
+" eterm types:
+" eterm No Color
+" eterm-color (8color)
+" Eterm types:
+" Eterm (8color)
+" Eterm-color (8color)
+" Eterm-88color
+" Eterm-256color
+" Konsole types:
+" * konsole (8color)
+" konsole-256color
+" Rxvt types:
+" rxvt (8color)
+" * rxvt-color (8color)
+" * rxvt-16color note: map to xterm 16
+" rxvt-88color
+" * rxvt-unicode (88color)
+" rxvt-unicode-256color
+" * rxvt-256color
+" XTerm types:
+" * xterm-color (8color0
+" * xterm-16color
+" * xterm-88color
+" * xterm-256color
+"
+" and there are others
+" Refs:
+" /usr/share/terminfo/*
+" ------------------------------------------------------------
+
" ------------------------------------------------------------
" Define konsole and eterm variables: {{{2
" Refs:
@@ -21,14 +55,20 @@ endif
" ------------------------------------------------------------
" Set current session Term functions: {{{2
+" There are two independent variables involved, encoding and
+" number of colors.
+" The encoding can be: 'utf-8' or not 'utf-8'.
+" The colors count can be: 256, 88, 16 or 8 (where gui == 256).
+" This code ONLY deals with the number of colors.
" Refs:
" ------------------------------------------------------------
if has("gui_running")
" Want to support Forms in GVim, so must still set term functions
" Use Xterm
let g:FORMS_COLOR_TERM_TYPE = 'gui'
- let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#xterm#ConvertRGB_2_Int")
- let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#xterm#ConvertInt_2_RGB")
+ let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#xterm256#ConvertRGB_2_Int")
+ let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#xterm256#ConvertInt_2_RGB")
+ let g:FORMS_COLOR_TERM_NUMBER_COLORS = 256
elseif &t_Co == 256
@@ -36,45 +76,86 @@ elseif &t_Co == 256
let g:FORMS_COLOR_TERM_TYPE = 'konsole'
let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#konsole#ConvertRGB_2_Int")
let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#konsole#ConvertInt256_2_RGB")
+ let g:FORMS_COLOR_TERM_NUMBER_COLORS = 256
elseif &term =~? '^eterm' || g:FORMS_COLOR_TERM_ETERM
let g:FORMS_COLOR_TERM_TYPE = 'eterm'
let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#eterm#ConvertRGB_2_Int")
let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#eterm#ConvertInt256_2_RGB")
+ let g:FORMS_COLOR_TERM_NUMBER_COLORS = 256
elseif &term =~? '^rxvt'
" Use Xterm functions for rxvt-unicode-256color
" rxvt-unicode-256color
let g:FORMS_COLOR_TERM_TYPE = 'urxvt256'
- let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#xterm#ConvertRGB_2_Int")
- let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#xterm#ConvertInt_2_RGB")
+ let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#xterm256#ConvertRGB_2_Int")
+ let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#xterm256#ConvertInt_2_RGB")
+ let g:FORMS_COLOR_TERM_NUMBER_COLORS = 256
+
else
" xterm
let g:FORMS_COLOR_TERM_TYPE = 'xterm'
- let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#xterm#ConvertRGB_2_Int")
- let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#xterm#ConvertInt_2_RGB")
+ let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#xterm256#ConvertRGB_2_Int")
+ let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#xterm256#ConvertInt_2_RGB")
+ let g:FORMS_COLOR_TERM_NUMBER_COLORS = 256
endif
elseif &t_Co == 88
- " rxvt-unicode
- let g:FORMS_COLOR_TERM_TYPE = 'urxvt'
- let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#urxvt#ConvertRGB_2_Int")
- let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#urxvt#ConvertInt_2_RGB")
+ if &term =~? '^rxvt'
+ " rxvt-unicode
+ let g:FORMS_COLOR_TERM_TYPE = 'urxvt'
+ let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#urxvt#ConvertRGB_2_Int")
+ let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#urxvt#ConvertInt_2_RGB")
+ let g:FORMS_COLOR_TERM_NUMBER_COLORS = 88
+
+ else
+ let g:FORMS_COLOR_TERM_TYPE = 'xterm'
+ let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#xterm88#ConvertRGB_2_Int")
+ let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#xterm88#ConvertInt_2_RGB")
+ let g:FORMS_COLOR_TERM_NUMBER_COLORS = 88
+
+ endif
+
+elseif &t_Co == 16
+ let g:FORMS_COLOR_TERM_TYPE = 'xterm'
+ let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#xterm16#ConvertRGB_2_Int")
+ let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#xterm16#ConvertInt_2_RGB")
+ let g:FORMS_COLOR_TERM_NUMBER_COLORS = 16
+
+elseif &t_Co == 8
+ if &term =~? '^rxvt'
+ let g:FORMS_COLOR_TERM_TYPE = 'rxvt'
+ let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#rxvt#ConvertRGB_2_Int")
+ let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#rxvt#ConvertInt_2_RGB")
+ let g:FORMS_COLOR_TERM_NUMBER_COLORS = 8
+
+ else
+ " Punt: for now use rxvt code
+ let g:FORMS_COLOR_TERM_TYPE = 'xterm'
+ let g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT = function("forms#color#xterm8#ConvertRGB_2_Int")
+ let g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB = function("forms#color#xterm8#ConvertInt_2_RGB")
+ let g:FORMS_COLOR_TERM_NUMBER_COLORS = 8
+
+ endif
endif
-function forms#color#term#ConvertRGBTxt_2_Int(rgbtxt)
+function! forms#color#term#ConvertRGBTxt_2_Int(rgbtxt)
let [r,g,b] = forms#color#util#ParseRGB(a:rgbtxt)
return g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT(r, g, b)
endfunction
-function forms#color#term#ConvertRGB_2_Int(rn, gn, bn)
+function! forms#color#term#ConvertRGB_2_Int(rn, gn, bn)
return g:FORMS_COLOR_TERM_CONVERT_RGB_2_INT(a:rn, a:gn, a:bn)
endfunction
-function forms#color#term#ConvertInt_2_RGB(n)
+function! forms#color#term#ConvertInt_2_RGB(n)
return g:FORMS_COLOR_TERM_CONVERT_INT_2_RGB(a:n)
endfunction
+function! forms#color#term#NumberColors()
+ return g:FORMS_COLOR_TERM_NUMBER_COLORS
+endfunction
+
" ================
" Modelines: {{{1
" ================
View
107 autoload/forms/color/urxvt.vim
@@ -7,11 +7,35 @@
" ============================================================================
" ------------------------------------------------------------
-" Define Int88_2_RGB Dictionary: {{{2
+" Define Int_2_Name Dictionary: {{{2
" Refs:
" rxvt-unicode-9.1.5 src/init.C
" ------------------------------------------------------------
-let s:Int88_2_RGB = {
+let s:Int_2_Name = {
+ \ '0': 'black',
+ \ '1': 'red3',
+ \ '2': 'green3',
+ \ '3': 'yellow3',
+ \ '4': 'blue3',
+ \ '5': 'magenta3',
+ \ '6': 'cyan3',
+ \ '7': 'AntiqueWhite',
+ \ '8': 'gray25',
+ \ '9': 'red',
+ \ '10': 'green',
+ \ '11': 'yellow',
+ \ '12': 'SteelBlue1',
+ \ '13': 'magenta',
+ \ '14': 'cyan',
+ \ '15': 'white'
+ \ }
+
+" ------------------------------------------------------------
+" Define Int_2_RGB Dictionary: {{{2
+" Refs:
+" rxvt-unicode-9.1.5 src/init.C
+" ------------------------------------------------------------
+let s:Int_2_RGB = {
\ '0': '000000',
\ '1': 'cd0000',
\ '2': '00cd00',
@@ -103,33 +127,33 @@ let s:Int88_2_RGB = {
\ }
" ------------------------------------------------------------
-" Generate RGB_2_Int88 Dictionary: {{{2
+" Generate RGB_2_Int Dictionary: {{{2
" ------------------------------------------------------------
-let s:RGB_2_Int88 = {}
-for key in sort(keys(s:Int88_2_RGB))
- let s:RGB_2_Int88[s:Int88_2_RGB[key]] = key
+let s:RGB_2_Int = {}
+for key in sort(keys(s:Int_2_RGB))
+ let s:RGB_2_Int[s:Int_2_RGB[key]] = key
endfor
" xterm number to rgb string
-let s:ColorTable88= []
+let s:ColorTable= []
" TODO make into list of [r,g,b] values
let cnt = 0
while cnt < 88
- let rgb = s:Int88_2_RGB[cnt]
+ let rgb = s:Int_2_RGB[cnt]
let r = rgb[0:1]
let g = rgb[2:3]
let b = rgb[4:5]
let rn = str2nr(r, 16)
let gn = str2nr(g, 16)
let bn = str2nr(b, 16)
- call add(s:ColorTable88, [rn,gn,bn])
+ call add(s:ColorTable, [rn,gn,bn])
let cnt += 1
endwhile
-" intensities88=[0, 139, 205, 255]
-" intensities88 = (0x00, 0x8b, 0xcd, 0xff)
-let forms#color#urxvt#intensities88 = [
+" intensities=[0, 139, 205, 255]
+" intensities = (0x00, 0x8b, 0xcd, 0xff)
+let s:intensities = [
\ str2nr("0x00",16),
\ str2nr("0x8b",16),
\ str2nr("0xcd",16),
@@ -146,10 +170,10 @@ let forms#color#urxvt#intensities88 = [
" rgb : Parameters accepted by ParseRGB
" ------------------------------------------------------------
-" binary search over possible intensities88
-function! s:GetPartial_Int88(n)
- " intensities88=[0, 139, 205, 255]
- " intensities88 = (0x00, 0x8b, 0xcd, 0xff)
+" binary search over possible intensities
+function! s:GetPartial_Int(n)
+ " intensities=[0, 139, 205, 255]
+ " intensities = (0x00, 0x8b, 0xcd, 0xff)
let n = a:n
let n2 = n+n
@@ -168,28 +192,37 @@ function! forms#color#urxvt#ConvertRGB_2_Int(rn, gn, bn)
let gn = a:gn
let bn = a:bn
-"call forms#log("ConvertRGB_2_Int88: in rn=". rn)
-"call forms#log("ConvertRGB_2_Int88: in gn=". gn)
-"call forms#log("ConvertRGB_2_Int88: in bn=". bn)
+"call forms#log("ConvertRGB_2_Int: in rn=". rn)
+"call forms#log("ConvertRGB_2_Int: in gn=". gn)
+"call forms#log("ConvertRGB_2_Int: in bn=". bn)
- let rnx = s:GetPartial_Int88(rn)
- let gnx = s:GetPartial_Int88(gn)
- let bnx = s:GetPartial_Int88(bn)
-"call forms#log("ConvertRGB_2_Int88: outjrnx=". rnx)
-"call forms#log("ConvertRGB_2_Int88: outjgnx=". gnx)
-"call forms#log("ConvertRGB_2_Int88: outjbnx=". bnx)
+ " special case
+ " '7': 'faebd7'
+ " '8': '404040',
+ if (rn == 250) && (gn == 235) && (bn == 215)
+ return 7
+ elseif (rn == 64) && (gn == 64) && (bn == 64)
+ return 8
+ endif
+
+ let rnx = s:GetPartial_Int(rn)
+ let gnx = s:GetPartial_Int(gn)
+ let bnx = s:GetPartial_Int(bn)
+"call forms#log("ConvertRGB_2_Int: outjrnx=". rnx)
+"call forms#log("ConvertRGB_2_Int: outjgnx=". gnx)
+"call forms#log("ConvertRGB_2_Int: outjbnx=". bnx)
" must check grey levels which can be a closer match
" TODO how to tell if we are near a grey level and
" only do the following if we are near?
let diff = abs(rnx-rn) + abs(gnx-gn) + abs(bnx-bn)
-"call forms#log("ConvertRGB_2_Int88: diff=". diff)
+"call forms#log("ConvertRGB_2_Int: diff=". diff)
let best_match = -1
let cnt = 80
while cnt < 88
- let [rx,gx,bx] = s:ColorTable88[cnt]
+ let [rx,gx,bx] = s:ColorTable[cnt]
let d = abs(rx-rn) + abs(gx-gn) + abs(bx-bn)
-"call forms#log("ConvertRGB_2_Int88: d=". d)
+"call forms#log("ConvertRGB_2_Int: d=". d)
" on equals, prefer gray to color
if d <= diff
@@ -201,20 +234,20 @@ function! forms#color#urxvt#ConvertRGB_2_Int(rn, gn, bn)
endwhile
if best_match != -1
-"call forms#log("ConvertRGB_2_Int88: best_match=". best_match)
+"call forms#log("ConvertRGB_2_Int: best_match=". best_match)
let n = best_match
else
let rgbtxt = printf('%02x%02x%02x',rnx,gnx,bnx)
-"call forms#log("ConvertRGB_2_Int88: rgbtxt=". rgbtxt)
- let n = s:RGB_2_Int88[rgbtxt]
+"call forms#log("ConvertRGB_2_Int: rgbtxt=". rgbtxt)
+ let n = s:RGB_2_Int[rgbtxt]
endif
-"call forms#log("ConvertRGB_2_Int88: time=". reltimestr(reltime(start)))
-"call forms#log("ConvertRGB_2_Int88: n=". n)
+"call forms#log("ConvertRGB_2_Int: time=". reltimestr(reltime(start)))
+"call forms#log("ConvertRGB_2_Int: n=". n)
return n
endfunction
" ------------------------------------------------------------
-" ConvertInt88_2_RGB: {{{2
+" ConvertInt_2_RGB: {{{2
" Converts an 88 String or Number to an rgb String
" Returns the rgb String
" parameters:
@@ -223,11 +256,11 @@ endfunction
" ------------------------------------------------------------
function! forms#color#urxvt#ConvertInt_2_RGB(nr)
if (type(a:nr) == g:self#NUMBER_TYPE)
- return s:Int88_2_RGB[a:nr]
+ return s:Int_2_RGB[a:nr]
elseif (type(a:nr) == g:self#STRING_TYPE)
- return s:Int88_2_RGB[a:nr]
+ return s:Int_2_RGB[a:nr]
else
- throw "FORMS_COLOR_UTIL_ConvertInt88_2_RGB: Bad number: " . string(a:nsstr)
+ throw "FORMS_COLOR_UTIL_ConvertInt_2_RGB: Bad number: " . string(a:nsstr)
endif
endfunction
View
172 autoload/forms/color/xterm16.vim
@@ -0,0 +1,172 @@
+" ============================================================================
+" xterm16.vim
+"
+" File: xterm16.vim
+" Summary: XTerm 16 (part of Forms Library)
+" Author: Richard Emberson <richard.n.embersonATgmailDOTcom>
+" ============================================================================
+
+" ------------------------------------------------------------
+" Define Int_2_Name Dictionary: {{{2
+" Refs:
+" Vim syntax doc
+" 0 Black 0 0 0
+" 1 DarkRed 139 0 0
+" 2 DarkGreen 0 100 0
+" 3 DarkYellow 139 139 0 (yellow4)
+" 4 DarkBlue 0 0 139
+" 5 DarkMagenta 139 0 139
+" 6 DarkCyan 0 139 139
+" 7 Gray, Grey 190 190 190
+" 8 DarkGrey 169 169 169
+" 9 LightRed 255 0 0 (red1)
+" 10 LightGreen 144 238 144
+" 11 LightYellow 255 255 224
+" 12 LightBlue 173 216 230
+" 13 LightMagenta 255 0 255 (magenta1)
+" 14 LightCyan 224 255 255
+" 15 White 255 255 255
+" ------------------------------------------------------------
+
+let s:Int_2_Name = {
+ \ '0': 'black',
+ \ '1': 'DarkRed',
+ \ '2': 'DarkReen',
+ \ '3': 'yellow4',
+ \ '4': 'DarkBlue',
+ \ '5': 'DarkMagenta',
+ \ '6': 'DarkCyan',
+ \ '7': 'Grey',
+ \ '8': 'DarkGrey',
+ \ '9': 're1',
+ \ '10': 'LightGreen',
+ \ '11': 'LightYellow',
+ \ '12': 'LightBlue',
+ \ '13': 'LightMagenta',
+ \ '14': 'LightCyan',
+ \ '15': 'white'
+ \ }
+
+" ------------------------------------------------------------
+" Define Int_2_RGB Dictionary: {{{2
+" Refs:
+" Vim syntax doc
+" ------------------------------------------------------------
+let s:Int_2_RGB = {
+ \ '0': '000000',
+ \ '1': '8b0000',
+ \ '2': '006400',
+ \ '3': '8b8b00',
+ \ '4': '00008b',
+ \ '5': '8b008b',
+ \ '6': '008b8b',
+ \ '7': 'bebebe',
+ \ '8': 'a9a9a9',
+ \ '9': 'ff0000',
+ \ '10': '90ee90',
+ \ '11': 'ffffe0',
+ \ '12': 'add8e6',
+ \ '13': 'ff00ff',
+ \ '14': 'e0ffff',
+ \ '15': 'ffffff',
+ \ }
+
+" ------------------------------------------------------------
+" Generate RGB_2_Int Dictionary: {{{2
+" ------------------------------------------------------------
+let s:RGB_2_Int = {}
+for key in sort(keys(s:Int_2_RGB))
+ let s:RGB_2_Int[s:Int_2_RGB[key]] = key
+endfor
+
+" xterm number to rgb string
+let s:ColorTable = []
+" TODO make into list of [r,g,b] values
+let cnt = 0
+while cnt < 16
+ let rgb = s:Int_2_RGB[cnt]
+ let r = rgb[0:1]
+ let g = rgb[2:3]
+ let b = rgb[4:5]
+ let rn = str2nr(r, 16)
+ let gn = str2nr(g, 16)
+ let bn = str2nr(b, 16)
+ call add(s:ColorTable, [rn,gn,bn])
+
+ let cnt += 1
+endwhile
+
+if 0
+let s:intensities = [
+ \ str2nr("0x00",16),
+ \ str2nr("0x5f",16),
+ \ str2nr("0x87",16),
+ \ str2nr("0xaf",16),
+ \ str2nr("0xd7",16),
+ \ str2nr("0xff",16)
+ \ ]
+endif
+
+
+" ------------------------------------------------------------
+" ConvertRGB_2_Int: {{{2
+" Converts an rgb String to a xterm 16 Number
+" Tried to make this fast.
+" Returns the xterm 16 Number
+" parameters:
+" rgb : Parameters accepted by ParseRGB
+" ------------------------------------------------------------
+function! forms#color#xterm16#ConvertRGB_2_Int(rn, gn, bn)
+"let start = reltime()
+ let rn = a:rn
+ let gn = a:gn
+ let bn = a:bn
+
+" call forms#log("ConvertRGB_2_Int: in rn=". rn)
+" call forms#log("ConvertRGB_2_Int: in gn=". gn)
+" call forms#log("ConvertRGB_2_Int6: in bn=". bn)
+"
+ let best_match = -1
+ let diff = 1000000
+ let cnt = 0
+ while cnt < 16
+ let [rx,gx,bx] = s:ColorTable[cnt]
+ let d = abs(rx-rn) + abs(gx-gn) + abs(bx-bn)
+
+ " on equals, prefer gray to color
+ if d < diff
+ let diff = d
+ let best_match = cnt
+ endif
+
+ let cnt += 1
+ endwhile
+ let n = best_match
+
+" call forms#log("ConvertRGB_2_Int: time=". reltimestr(reltime(start)))
+"call forms#log("ConvertRGB_2_Int: n=". n)
+ return n
+endfunction
+
+" ------------------------------------------------------------
+" ConvertInt_2_RGB: {{{2
+" Converts an xterm 16 String or Number to an rgb String
+" Returns the rgb String
+" parameters:
+" nr : String or Number or xterm 16 value
+" value must be 0 <= value <= 15
+" ------------------------------------------------------------
+function! forms#color#xterm16#ConvertInt_2_RGB(nr)
+ if (type(a:nr) == g:self#NUMBER_TYPE)
+ return s:Int_2_RGB[a:nr]
+ elseif (type(a:nr) == g:self#STRING_TYPE)
+ return s:Int_2_RGB[a:nr]
+ else
+ throw "forms#color#xterm16#ConvertInt_2_RGB: Bad number: " . string(a:nsstr)
+ endif
+endfunction
+
+" ================
+" Modelines: {{{1
+" ================
+" vim: ts=4 fdm=marker
View
205 autoload/forms/color/xterm.vim → autoload/forms/color/xterm256.vim
@@ -1,24 +1,51 @@
" ============================================================================
-" xterm.vim
+" xterm256.vim
"
-" File: xterm.vim
-" Summary: XTerm (part of Forms Library)
+" File: xterm256.vim
+" Summary: XTerm 256 (part of Forms Library)
" Author: Richard Emberson <richard.n.embersonATgmailDOTcom>
" ============================================================================
" ------------------------------------------------------------
-" Define Int256_2_RGB Dictionary: {{{2
+" Define Int_2_Name Dictionary: {{{2
+" Refs:
+" http://www.opensource.apple.com/source/ncurses/ncurses-27/ncurses/test/xterm-88color.dat
+" xterm-281/xter/charproc.c
+" NOTE: color for 12 does not have name!!
+" ------------------------------------------------------------
+let s:Int_2_Name = {
+ \ '0': 'black',
+ \ '1': 'red3',
+ \ '2': 'green3',
+ \ '3': 'yellow3',
+ \ '4': 'blue2',
+ \ '5': 'magenta3',
+ \ '6': 'cyan3',
+ \ '7': 'gray90',
+ \ '8': 'gray50',
+ \ '9': 'red',
+ \ '10': 'green',
+ \ '11': 'yellow',
+ \ '12': 'UnknownBlue',
+ \ '13': 'magenta',
+ \ '14': 'cyan',
+ \ '15': 'white'
+ \ }
+
+" ------------------------------------------------------------
+" Define Int_2_RGB Dictionary: {{{2
" Refs:
" https://en.wikipedia.org/wiki/File:Xterm_color_chart.png
" rxvt-unicode-9.1.5 src/init.C
+" xterm-281/256colres.h
" TODO: should #8 be '4d4d4d' or '7f7f7f'
" ------------------------------------------------------------
-let s:Int256_2_RGB = {
+let s:Int_2_RGB = {
\ '0': '000000',
\ '1': 'cd0000',
\ '2': '00cd00',
\ '3': 'cdcd00',
- \ '4': '0000cd',
+ \ '4': '0000ee',
\ '5': 'cd00cd',
\ '6': '00cdcd',
\ '7': 'e5e5e5',
@@ -26,7 +53,7 @@ let s:Int256_2_RGB = {
\ '9': 'ff0000',
\ '10': '00ff00',
\ '11': 'ffff00',
- \ '12': '0000ff',
+ \ '12': '5c5cff',
\ '13': 'ff00ff',
\ '14': '00ffff',
\ '15': 'ffffff',
@@ -273,26 +300,26 @@ let s:Int256_2_RGB = {
\ }
" ------------------------------------------------------------
-" Generate RGB_2_Int256 Dictionary: {{{2
+" Generate RGB_2_Int Dictionary: {{{2
" ------------------------------------------------------------
-let s:RGB_2_Int256 = {}
-for key in sort(keys(s:Int256_2_RGB))
- let s:RGB_2_Int256[s:Int256_2_RGB[key]] = key
+let s:RGB_2_Int = {}
+for key in sort(keys(s:Int_2_RGB))
+ let s:RGB_2_Int[s:Int_2_RGB[key]] = key
endfor
" xterm number to rgb string
-let s:ColorTable256 = []
+let s:ColorTable = []
" TODO make into list of [r,g,b] values
let cnt = 0
while cnt < 256
- let rgb = s:Int256_2_RGB[cnt]
+ let rgb = s:Int_2_RGB[cnt]
let r = rgb[0:1]
let g = rgb[2:3]
let b = rgb[4:5]
let rn = str2nr(r, 16)
let gn = str2nr(g, 16)
let bn = str2nr(b, 16)
- call add(s:ColorTable256, [rn,gn,bn])
+ call add(s:ColorTable, [rn,gn,bn])
let cnt += 1
endwhile
@@ -302,7 +329,7 @@ endwhile
" 6 intensity RGB
" intensities=[0, 95, 135, 175, 215, 255]
" intensities = (0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff)
-let forms#color#xterm#intensities256 = [
+let s:intensities = [
\ str2nr("0x00",16),
\ str2nr("0x5f",16),
\ str2nr("0x87",16),
@@ -313,7 +340,7 @@ let forms#color#xterm#intensities256 = [
" ------------------------------------------------------------
-" ConvertRGB_2_Int256: {{{2
+" ConvertRGB_2_Int: {{{2
" Converts an rgb String to a xterm 256 Number
" Tried to make this fast.
" Returns the xterm 256 Number
@@ -322,9 +349,9 @@ let forms#color#xterm#intensities256 = [
" ------------------------------------------------------------
" binary search over possible intensities256
-function! s:GetPartial_Int256(n)
- " intensities256=[0, 95, 135, 175, 215, 255]
- " intensities256 = (0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff)
+function! s:GetPartial_Int(n)
+ " intensities=[0, 95, 135, 175, 215, 255]
+ " intensities = (0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff)
let n = a:n
let n2 = n+n
@@ -347,34 +374,64 @@ function! s:GetPartial_Int256(n)
endif
endfunction
-function! forms#color#xterm#ConvertRGB_2_Int(rn, gn, bn)
+function! forms#color#xterm256#ConvertRGB_2_Int(rn, gn, bn)
"let start = reltime()
let rn = a:rn
let gn = a:gn
let bn = a:bn
-" call forms#log("ConvertRGB_2_Int256: in rn=". rn)
-" call forms#log("ConvertRGB_2_Int256: in gn=". gn)
-" call forms#log("ConvertRGB_2_Int256: in bn=". bn)
+" call forms#log("ConvertRGB_2_Int: in rn=". rn)
+" call forms#log("ConvertRGB_2_Int: in gn=". gn)
+" call forms#log("ConvertRGB_2_Int6: in bn=". bn)
+
+ " special case
+ " '1': 'cd0000',
+ " '2': '00cd00',
+ " '3': 'cdcd00',
+ " '4': '0000ee',
+ " '5': 'cd00cd',
+ " '6': '00cdcd',
+ " '7': 'e5e5e5',
+ " '8': '4d4d4d',
+ " '12': '5c5cff',
+ if (rn == 205) && (gn == 0) && (bn == 0)
+ return 1
+ elseif (rn == 0) && (gn == 205) && (bn == 0)
+ return 2
+ elseif (rn == 205) && (gn == 205) && (bn == 0)
+ return 3
+ elseif (rn == 0) && (gn == 0) && (bn == 238)
+ return 4
+ elseif (rn == 205) && (gn == 0) && (bn == 205)
+ return 5
+ elseif (rn == 0) && (gn == 205) && (bn == 205)
+ return 6
+ elseif (rn == 229) && (gn == 229) && (bn == 229)
+ return 7
+ elseif (rn == 77) && (gn == 77) && (bn == 77)
+ return 8
+ elseif (rn == 92) && (gn == 92) && (bn == 255)
+ return 12
+ endif
- let rnx = s:GetPartial_Int256(rn)
- let gnx = s:GetPartial_Int256(gn)
- let bnx = s:GetPartial_Int256(bn)
-" call forms#log("ConvertRGB_2_Int256: outjrnx=". rnx)
-" call forms#log("ConvertRGB_2_Int256: outjgnx=". gnx)
-" call forms#log("ConvertRGB_2_Int256: outjbnx=". bnx)
+ let rnx = s:GetPartial_Int(rn)
+ let gnx = s:GetPartial_Int(gn)
+ let bnx = s:GetPartial_Int(bn)
+" call forms#log("ConvertRGB_2_Int: outjrnx=". rnx)
+" call forms#log("ConvertRGB_2_Int: outjgnx=". gnx)
+" call forms#log("ConvertRGB_2_Int: outjbnx=". bnx)
" must check grey levels which can be a closer match
" TODO how to tell if we are near a grey level and
" only do the following if we are near?
let diff = abs(rnx-rn) + abs(gnx-gn) + abs(bnx-bn)
-" call forms#log("ConvertRGB_2_Int256: diff=". diff)
+" call forms#log("ConvertRGB_2_Int: diff=". diff)
let best_match = -1
let cnt = 232
while cnt < 256
- let [rx,gx,bx] = s:ColorTable256[cnt]
+ let [rx,gx,bx] = s:ColorTable[cnt]
let d = abs(rx-rn) + abs(gx-gn) + abs(bx-bn)
-" call forms#log("ConvertRGB_2_Int256: d=". d)
+" call forms#log("ConvertRGB_2_Int: d=". d)
" on equals, prefer gray to color
if d < diff
@@ -386,20 +443,20 @@ function! forms#color#xterm#ConvertRGB_2_Int(rn, gn, bn)
endwhile
if best_match != -1
-" call forms#log("ConvertRGB_2_Int256: best_match=". best_match)
+" call forms#log("ConvertRGB_2_Int: best_match=". best_match)
let n = best_match
else
let rgbtxt = printf('%02x%02x%02x',rnx,gnx,bnx)
-" call forms#log("ConvertRGB_2_Int256: rgbtxt=". rgbtxt)
- let n = s:RGB_2_Int256[rgbtxt]
+" call forms#log("ConvertRGB_2_Int: rgbtxt=". rgbtxt)
+ let n = s:RGB_2_Int[rgbtxt]
endif
-" call forms#log("ConvertRGB_2_Int256: time=". reltimestr(reltime(start)))
-"call forms#log("ConvertRGB_2_Int256: n=". n)
+" call forms#log("ConvertRGB_2_Int: time=". reltimestr(reltime(start)))
+"call forms#log("ConvertRGB_2_Int: n=". n)
return n
endfunction
" ------------------------------------------------------------
-" ConvertRGB_2_Int256Good: {{{2
+" ConvertRGB_2_IntGood: {{{2
" Converts an rgb String to a xterm 256 Number
" Tried to make this fast.
" Returns the xterm 256 Number
@@ -407,65 +464,65 @@ endfunction
" rgb : Parameters accepted by ParseRGB
" ------------------------------------------------------------
"
-function! s:GetPartial_Int256Good(n, intensities)
+function! s:GetPartial_IntGood(n, intensities)
let n = a:n
let intensities = a:intensities
let s = intensities[0]
let b = intensities[1]
if s <= n && n <= b
-"call forms#log("ConvertRGB_2_Int256Good: 0")
+"call forms#log("ConvertRGB_2_IntGood: 0")
return (n+n <= s+b) ? s : b
endif
let s = b
let b = intensities[2]
if s <= n && n <= b
-"call forms#log("ConvertRGB_2_Int256Good: 1")
+"call forms#log("ConvertRGB_2_IntGood: 1")
return (n+n <= s+b) ? s : b
endif
let s = b
let b = intensities[3]
if s <= n && n <= b
-"call forms#log("ConvertRGB_2_Int256Good: 2")
+"call forms#log("ConvertRGB_2_IntGood: 2")
return (n+n <= s+b) ? s : b
endif
let s = b
let b = intensities[4]
if s <= n && n <= b
-"call forms#log("ConvertRGB_2_Int256Good: 3")
+"call forms#log("ConvertRGB_2_IntGood: 3")
return (n+n <= s+b) ? s : b
endif
let s = b
let b = intensities[5]
if s <= n && n <= b
-"call forms#log("ConvertRGB_2_Int256Good: 4")
+"call forms#log("ConvertRGB_2_IntGood: 4")
return (n+n <= s+b) ? s : b
endif
- throw "ConvertRGB_2_Int256Good.GetPartial_Int256Good: Bad partial color: " . string(n)
+ throw "ConvertRGB_2_IntGood.GetPartial_IntGood: Bad partial color: " . string(n)
endfunction
-function! forms#color#xterm#ConvertRGB_2_Int256Good(rn, gn, bn)
+function! forms#color#xterm256#ConvertRGB_2_IntGood(rn, gn, bn)
let rn = a:rn
let gn = a:gn
let bn = a:bn
"let start = reltime()
-"call forms#log("ConvertRGB_2_Int256Good: in rn=". rn)
-"call forms#log("ConvertRGB_2_Int256Good: in gn=". gn)
-"call forms#log("ConvertRGB_2_Int256Good: in bn=". bn)
+"call forms#log("ConvertRGB_2_IntGood: in rn=". rn)
+"call forms#log("ConvertRGB_2_IntGood: in gn=". gn)
+"call forms#log("ConvertRGB_2_IntGood: in bn=". bn)
- let rnx = s:GetPartial_Int256Good(rn, forms#color#xterm#intensities256)
- let gnx = s:GetPartial_Int256Good(gn, forms#color#xterm#intensities256)
- let bnx = s:GetPartial_Int256Good(bn, forms#color#xterm#intensities256)
-"call forms#log("ConvertRGB_2_Int256Good: rnx=". rnx)
-"call forms#log("ConvertRGB_2_Int256Good: gnx=". gnx)
-"call forms#log("ConvertRGB_2_Int256Good: bnx=". bnx)
+ let rnx = s:GetPartial_IntGood(rn, s:intensities)
+ let gnx = s:GetPartial_IntGood(gn, s:intensities)
+ let bnx = s:GetPartial_IntGood(bn, s:intensities)
+"call forms#log("ConvertRGB_2_IntGood: rnx=". rnx)
+"call forms#log("ConvertRGB_2_IntGood: gnx=". gnx)
+"call forms#log("ConvertRGB_2_IntGood: bnx=". bnx)
" must check grey levels which can be a closer match
let diff = abs(rnx-rn) + abs(gnx-gn) + abs(bnx-bn)
let best_match = -1
let cnt = 232
while cnt < 256
- let [rx,gx,bx] = s:ColorTable256[cnt]
+ let [rx,gx,bx] = s:ColorTable[cnt]
let d = abs(rx-rn) + abs(gx-gn) + abs(bx-bn)
if d <= diff
@@ -477,15 +534,15 @@ function! forms#color#xterm#ConvertRGB_2_Int256Good(rn, gn, bn)
endwhile
if best_match != -1
-"call forms#log("ConvertRGB_2_Int256Good: best_match=". best_match)
+"call forms#log("ConvertRGB_2_IntGood: best_match=". best_match)
let n = best_match
else
let rgbtxt = printf('%02x%02x%02x',rnx,gnx,bnx)
-"call forms#log("ConvertRGB_2_Int256Good: rgbtxt=". rgbtxt)
- let n = s:RGB_2_Int256[rgbtxt]
+"call forms#log("ConvertRGB_2_IntGood: rgbtxt=". rgbtxt)
+ let n = s:RGB_2_Int[rgbtxt]
endif
-"call forms#log("ConvertRGB_2_Int256Good: time=". reltimestr(reltime(start)))
-"call forms#log("ConvertRGB_2_Int256Good: n=". n)
+"call forms#log("ConvertRGB_2_IntGood: time=". reltimestr(reltime(start)))
+"call forms#log("ConvertRGB_2_IntGood: n=". n)
return n
endfunction
@@ -493,28 +550,28 @@ endfunction
" http://crunchbanglinux.org/forums/topic/20674/view-images-and-gifs-in-the-terminal/
" ------------------------------------------------------------
-" ConvertRGB_2_Int256Slow: {{{2
+" ConvertRGB_2_IntSlow: {{{2
" Converts an rgb String to a xterm 256 Number
" Tried to make this fast.
" Returns the xterm 256 Number
" parameters:
" rgb : Parameters accepted by ParseRGB
" ------------------------------------------------------------
-function! forms#color#xterm#ConvertRGB_2_Int256Slow(rn, gn, bn)
+function! forms#color#xterm256#ConvertRGB_2_IntSlow(rn, gn, bn)
let rn = a:rn
let gn = a:gn
let bn = a:bn
"let start = reltime()
-"call forms#log("ConvertRGB_2_Int256Slow: in rn=". rn)
-"call forms#log("ConvertRGB_2_Int256Slow: in gn=". gn)
-"call forms#log("ConvertRGB_2_Int256Slow: in bn=". bn)
+"call forms#log("ConvertRGB_2_IntSlow: in rn=". rn)
+"call forms#log("ConvertRGB_2_IntSlow: in gn=". gn)
+"call forms#log("ConvertRGB_2_IntSlow: in bn=". bn)
let best_match = 0
let diff = 10000000
let cnt = 16
while cnt < 256
- let [rx,gx,bx] = s:ColorTable256[cnt]
+ let [rx,gx,bx] = s:ColorTable[cnt]
let d = abs(rx-rn) + abs(gx-gn) + abs(bx-bn)
if d < diff
@@ -524,27 +581,27 @@ function! forms#color#xterm#ConvertRGB_2_Int256Slow(rn, gn, bn)
let cnt += 1
endwhile
-"call forms#log("ConvertRGB_2_Int256Slow: time=". reltimestr(reltime(start)))
-"call forms#log("ConvertRGB_2_Int256Slow: best_match=". best_match)
+"call forms#log("ConvertRGB_2_IntSlow: time=". reltimestr(reltime(start)))
+"call forms#log("ConvertRGB_2_IntSlow: best_match=". best_match)
return best_match
endfunction
" ------------------------------------------------------------
-" ConvertInt256_2_RGB: {{{2
+" ConvertInt_2_RGB: {{{2
" Converts an xterm 256 String or Number to an rgb String
" Returns the rgb String
" parameters:
" nr : String or Number or xterm 256 value
" value must be 0 <= value <= 255
" ------------------------------------------------------------
-function! forms#color#xterm#ConvertInt_2_RGB(nr)
+function! forms#color#xterm256#ConvertInt_2_RGB(nr)
if (type(a:nr) == g:self#NUMBER_TYPE)
- return s:Int256_2_RGB[a:nr]
+ return s:Int_2_RGB[a:nr]
elseif (type(a:nr) == g:self#STRING_TYPE)
- return s:Int256_2_RGB[a:nr]
+ return s:Int_2_RGB[a:nr]
else
- throw "forms#color#xterm#ConvertInt_2_RGB: Bad number: " . string(a:nsstr)
+ throw "forms#color#xterm256#ConvertInt_2_RGB: Bad number: " . string(a:nsstr)
endif
endfunction
View
149 autoload/forms/color/xterm8.vim
@@ -0,0 +1,149 @@
+" ============================================================================
+" xterm8.vim
+"
+" File: xterm8.vim
+" Summary: XTerm 8 (part of Forms Library)
+" Author: Richard Emberson <richard.n.embersonATgmailDOTcom>
+" ============================================================================
+
+" ------------------------------------------------------------
+" Define Int_2_Name Dictionary: {{{2
+" Refs:
+" Vim syntax doc
+" 0 Black 0 0 0
+" 1 DarkRed 139 0 0
+" 2 DarkGreen 0 100 0
+" 3 DarkYellow 139 139 0 (yellow4)
+" 4 DarkBlue 0 0 139
+" 5 DarkMagenta 139 0 139
+" 6 DarkCyan 0 139 139
+" 7 Gray, Grey 190 190 190
+" ------------------------------------------------------------
+
+
+let s:Int_2_Name = {
+ \ '0': 'black',
+ \ '1': 'DarkRed',
+ \ '2': 'DarkReen',
+ \ '3': 'yellow4',
+ \ '4': 'DarkBlue',
+ \ '5': 'DarkMagenta',
+ \ '6': 'DarkCyan',
+ \ '7': 'Grey'
+ \ }
+
+" ------------------------------------------------------------
+" Define Int_2_RGB Dictionary: {{{2
+" Refs:
+" Vim syntax doc
+" ------------------------------------------------------------
+let s:Int_2_RGB = {
+ \ '0': '000000',
+ \ '1': '8b0000',
+ \ '2': '006400',
+ \ '3': '8b8b00',
+ \ '4': '00008b',
+ \ '5': '8b008b',
+ \ '6': '008b8b',
+ \ '7': 'bebebe'
+ \ }
+
+" ------------------------------------------------------------
+" Generate RGB_2_Int Dictionary: {{{2
+" ------------------------------------------------------------
+let s:RGB_2_Int = {}
+for key in sort(keys(s:Int_2_RGB))
+ let s:RGB_2_Int[s:Int_2_RGB[key]] = key
+endfor
+
+" xterm number to rgb string
+let s:ColorTable = []
+" TODO make into list of [r,g,b] values
+let cnt = 0
+while cnt < 8
+ let rgb = s:Int_2_RGB[cnt]
+ let r = rgb[0:1]
+ let g = rgb[2:3]
+ let b = rgb[4:5]
+ let rn = str2nr(r, 16)
+ let gn = str2nr(g, 16)
+ let bn = str2nr(b, 16)
+ call add(s:ColorTable, [rn,gn,bn])
+
+ let cnt += 1
+endwhile
+
+if 0
+let s:intensities = [
+ \ str2nr("0x00",16),
+ \ str2nr("0x5f",16),
+ \ str2nr("0x87",16),
+ \ str2nr("0xaf",16),
+ \ str2nr("0xd7",16),
+ \ str2nr("0xff",16)
+ \ ]
+endif
+
+
+" ------------------------------------------------------------
+" ConvertRGB_2_Int: {{{2
+" Converts an rgb String to a xterm 8 Number
+" Tried to make this fast.
+" Returns the xterm 8 Number
+" parameters:
+" rgb : Parameters accepted by ParseRGB
+" ------------------------------------------------------------
+function! forms#color#xterm8#ConvertRGB_2_Int(rn, gn, bn)
+"let start = reltime()
+ let rn = a:rn
+ let gn = a:gn
+ let bn = a:bn
+
+" call forms#log("ConvertRGB_2_Int: in rn=". rn)
+" call forms#log("ConvertRGB_2_Int: in gn=". gn)
+" call forms#log("ConvertRGB_2_Int6: in bn=". bn)
+"
+ let best_match = -1
+ let diff = 1000000
+ let cnt = 0
+ while cnt < 8
+ let [rx,gx,bx] = s:ColorTable[cnt]
+ let d = abs(rx-rn) + abs(gx-gn) + abs(bx-bn)
+
+ " on equals, prefer gray to color
+ if d < diff
+ let diff = d
+ let best_match = cnt
+ endif
+
+ let cnt += 1
+ endwhile
+ let n = best_match
+
+" call forms#log("ConvertRGB_2_Int: time=". reltimestr(reltime(start)))
+"call forms#log("ConvertRGB_2_Int: n=". n)
+ return n
+endfunction
+
+" ------------------------------------------------------------
+" ConvertInt_2_RGB: {{{2
+" Converts an xterm 8 String or Number to an rgb String
+" Returns the rgb String
+" parameters:
+" nr : String or Number or xterm 8 value
+" value must be 0 <= value <= 15
+" ------------------------------------------------------------
+function! forms#color#xterm8#ConvertInt_2_RGB(nr)
+ if (type(a:nr) == g:self#NUMBER_TYPE)
+ return s:Int_2_RGB[a:nr]
+ elseif (type(a:nr) == g:self#STRING_TYPE)
+ return s:Int_2_RGB[a:nr]
+ else
+ throw "forms#color#xterm8#ConvertInt_2_RGB: Bad number: " . string(a:nsstr)
+ endif
+endfunction
+
+" ================
+" Modelines: {{{1
+" ================
+" vim: ts=4 fdm=marker
View
278 autoload/forms/color/xterm88.vim
@@ -0,0 +1,278 @@
+" ============================================================================
+" xterm88.vim
+"
+" File: xterm88.vim
+" Summary: XTerm 88 (part of Forms Library)
+" Author: Richard Emberson <richard.n.embersonATgmailDOTcom>
+" ============================================================================
+
+" ------------------------------------------------------------
+" Define Int_2_Name Dictionary: {{{2
+" Refs:
+" http://www.opensource.apple.com/source/ncurses/ncurses-27/ncurses/test/xterm-88color.dat
+" xterm-281/xter/charproc.c
+" NOTE: color for 12 does not have name!!
+" ------------------------------------------------------------
+let s:Int_2_Name = {
+ \ '0': 'black',
+ \ '1': 'red3',
+ \ '2': 'green3',
+ \ '3': 'yellow3',
+ \ '4': 'blue2',
+ \ '5': 'magenta3',
+ \ '6': 'cyan3',
+ \ '7': 'gray90',
+ \ '8': 'gray50',
+ \ '9': 'red',
+ \ '10': 'green',
+ \ '11': 'yellow',
+ \ '12': 'UnknownBlue',
+ \ '13': 'magenta',
+ \ '14': 'cyan',
+ \ '15': 'white'
+ \ }
+
+" ------------------------------------------------------------
+" Define Int_2_RGB Dictionary: {{{2
+" Refs:
+" http://www.opensource.apple.com/source/ncurses/ncurses-27/ncurses/test/xterm-88color.dat
+" xterm-281/xter/charproc.c
+" ------------------------------------------------------------
+let s:Int_2_RGB = {
+ \ '0': '000000',
+ \ '1': 'cd0000',
+ \ '2': '00cd00',
+ \ '3': 'cdcd00',
+ \ '4': '0000ee',
+ \ '5': 'cd00cd',
+ \ '6': '00cdcd',
+ \ '7': 'e5e5e5',
+ \ '8': '4d4d4d',
+ \ '9': 'ff0000',
+ \ '10': '00ff00',
+ \ '11': 'ffff00',
+ \ '12': '5c5cff',
+ \ '13': 'ff00ff',
+ \ '14': '00ffff',
+ \ '15': 'ffffff',
+ \ '16': '000000',
+ \ '17': '00008b',
+ \ '18': '0000cd',
+ \ '19': '0000ff',
+ \ '20': '008b00',
+ \ '21': '008b8b',
+ \ '22': '008bcd',
+ \ '23': '008bff',
+ \ '24': '00cd00',
+ \ '25': '00cd8b',
+ \ '26': '00cdcd',
+ \ '27': '00cdff',
+ \ '28': '00ff00',
+ \ '29': '00ff8b',
+ \ '30': '00ffcd',
+ \ '31': '00ffff',
+ \ '32': '8b0000',
+ \ '33': '8b008b',
+ \ '34': '8b00cd',
+ \ '35': '8b00ff',
+ \ '36': '8b8b00',
+ \ '37': '8b8b8b',
+ \ '38': '8b8bcd',
+ \ '39': '8b8bff',
+ \ '40': '8bcd00',
+ \ '41': '8bcd8b',
+ \ '42': '8bcdcd',
+ \ '43': '8bcdff',
+ \ '44': '8bff00',
+ \ '45': '8bff8b',
+ \ '46': '8bffcd',
+ \ '47': '8bffff',
+ \ '48': 'cd0000',
+ \ '49': 'cd008b',
+ \ '50': 'cd00cd',
+ \ '51': 'cd00ff',
+ \ '52': 'cd8b00',
+ \ '53': 'cd8b8b',
+ \ '54': 'cd8bcd',
+ \ '55': 'cd8bff',
+ \ '56': 'cdcd00',
+ \ '57': 'cdcd8b',
+ \ '58': 'cdcdcd',
+ \ '59': 'cdcdff',
+ \ '60': 'cdff00',
+ \ '61': 'cdff8b',
+ \ '62': 'cdffcd',
+ \ '63': 'cdffff',
+ \ '64': 'ff0000',
+ \ '65': 'ff008b',
+ \ '66': 'ff00cd',
+ \ '67': 'ff00ff',
+ \ '68': 'ff8b00',
+ \ '69': 'ff8b8b',
+ \ '70': 'ff8bcd',
+ \ '71': 'ff8bff',
+ \ '72': 'ffcd00',
+ \ '73': 'ffcd8b',
+ \ '74': 'ffcdcd',
+ \ '75': 'ffcdff',
+ \ '76': 'ffff00',
+ \ '77': 'ffff8b',
+ \ '78': 'ffffcd',
+ \ '79': 'ffffff',
+ \ '80': '2e2e2e',
+ \ '81': '5c5c5c',
+ \ '82': '717171',
+ \ '83': '8b8b8b',
+ \ '84': 'a2a2a2',
+ \ '85': 'b9b9b9',
+ \ '86': 'd0d0d0',
+ \ '87': 'e7e7e7'
+ \ }
+
+" ------------------------------------------------------------
+" Generate RGB_2_Int Dictionary: {{{2
+" ------------------------------------------------------------
+let s:RGB_2_Int = {}
+for key in sort(keys(s:Int_2_RGB))
+ let s:RGB_2_Int[s:Int_2_RGB[key]] = key
+endfor
+
+" xterm number to rgb string
+let s:ColorTable = []
+" TODO make into list of [r,g,b] values
+let cnt = 0
+while cnt < 88
+ let rgb = s:Int_2_RGB[cnt]
+ let r = rgb[0:1]
+ let g = rgb[2:3]
+ let b = rgb[4:5]
+ let rn = str2nr(r, 16)
+ let gn = str2nr(g, 16)
+ let bn = str2nr(b, 16)
+ call add(s:ColorTable, [rn,gn,bn])
+
+ let cnt += 1
+endwhile
+
+" intensities=[0, 139, 205, 255]
+" intensities = (0x00, 0x8b, 0xcd, 0xff)
+let s:intensities = [
+ \ str2nr("0x00",16),
+ \ str2nr("0x8b",16),
+ \ str2nr("0xcd",16),
+ \ str2nr("0xff",16)
+ \ ]
+
+" ------------------------------------------------------------
+" ConvertRGB_2_Int: {{{2
+" Converts an rgb String to a xterm 88 Number
+" Tried to make this fast.
+" Returns the xterm 88 Number
+" parameters:
+" rgb : Parameters accepted by ParseRGB
+" ------------------------------------------------------------
+
+" binary search over possible intensities
+function! s:GetPartial_Int(n)
+ " intensities=[0, 139, 205, 255]
+ " intensities = (0x00, 0x8b, 0xcd, 0xff)
+ let n = a:n
+ let n2 = n+n
+
+ if n <= 139
+ return (n2 <= 139) ? 0 : 139
+ elseif n <= 205
+ return (n2 <= 344) ? 139 : 205
+ else
+ return (n2 <= 460) ? 205 : 255
+ endif
+endfunction
+
+function! forms#color#xterm#ConvertRGB_2_Int(rn, gn, bn)
+"let start = reltime()
+ let rn = a:rn
+ let gn = a:gn
+ let bn = a:bn
+
+" call forms#log("ConvertRGB_2_Int: in rn=". rn)
+" call forms#log("ConvertRGB_2_Int: in gn=". gn)
+" call forms#log("ConvertRGB_2_Int: in bn=". bn)
+
+ " special case
+ " '4': '0000ee',
+ " '7': 'e5e5e5',
+ " '8': '4d4d4d',
+ " '12': '5c5cff',
+ if (rn == 0) && (gn == 0) && (bn == 238)
+ return 4
+ elseif (rn == 229) && (gn == 229) && (bn == 229)
+ return 7
+ elseif (rn == 77) && (gn == 77) && (bn == 77)
+ return 8
+ elseif (rn == 92) && (gn == 92) && (bn == 255)
+ return 12
+ endif
+
+ let rnx = s:GetPartial_Int(rn)
+ let gnx = s:GetPartial_Int(gn)
+ let bnx = s:GetPartial_Int(bn)
+" call forms#log("ConvertRGB_2_Int: outjrnx=". rnx)
+" call forms#log("ConvertRGB_2_Int: outjgnx=". gnx)
+" call forms#log("ConvertRGB_2_Int: outjbnx=". bnx)
+
+ " must check grey levels which can be a closer match
+ " TODO how to tell if we are near a grey level and
+ " only do the following if we are near?
+ let diff = abs(rnx-rn) + abs(gnx-gn) + abs(bnx-bn)
+" call forms#log("ConvertRGB_2_Int: diff=". diff)
+ let best_match = -1
+ let cnt = 80
+ while cnt < 88
+ let [rx,gx,bx] = s:ColorTable[cnt]
+ let d = abs(rx-rn) + abs(gx-gn) + abs(bx-bn)
+" call forms#log("ConvertRGB_2_Int: d=". d)
+
+ " on equals, prefer gray to color
+ if d < diff
+ let diff = d
+ let best_match = cnt
+ endif
+
+ let cnt += 1
+ endwhile
+
+ if best_match != -1
+" call forms#log("ConvertRGB_2_Int: best_match=". best_match)
+ let n = best_match
+ else
+ let rgbtxt = printf('%02x%02x%02x',rnx,gnx,bnx)
+" call forms#log("ConvertRGB_2_Int: rgbtxt=". rgbtxt)
+ let n = s:RGB_2_Int[rgbtxt]
+ endif
+" call forms#log("ConvertRGB_2_Int: time=". reltimestr(reltime(start)))
+"call forms#log("ConvertRGB_2_Int: n=". n)
+ return n
+endfunction
+
+" ------------------------------------------------------------
+" ConvertInt_2_RGB: {{{2
+" Converts an xterm 88 String or Number to an rgb String
+" Returns the rgb String
+" parameters:
+" nr : String or Number or xterm 88 value
+" value must be 0 <= value <= 88
+" ------------------------------------------------------------
+function! forms#color#xterm#ConvertInt_2_RGB(nr)
+ if (type(a:nr) == g:self#NUMBER_TYPE)
+ return s:Int_2_RGB[a:nr]
+ elseif (type(a:nr) == g:self#STRING_TYPE)
+ return s:Int_2_RGB[a:nr]
+ else
+ throw "forms#color#xterm#ConvertInt_2_RGB: Bad number: " . string(a:nsstr)
+ endif
+endfunction
+
+" ================
+" Modelines: {{{1
+" ================
+" vim: ts=4 fdm=marker
View
20 autoload/forms/dialog/color.vim
@@ -223,16 +223,20 @@ function! forms#dialog#color#Make(with_pallet)
"----
-if has("gui_running") || &t_Co == 256
- :hi CCRedHi cterm=NONE ctermbg=196 guibg=#ff0000
- :hi CCGreenHi cterm=NONE ctermbg=46 guibg=#00ff00
- :hi CCBlueHi cterm=NONE ctermbg=21 guibg=#0000ff
-elseif &t_Co == 88
- :hi CCRedHi cterm=NONE ctermbg=64 guibg=#ff0000
- :hi CCGreenHi cterm=NONE ctermbg=28 guibg=#00ff00
- :hi CCBlueHi cterm=NONE ctermbg=19 guibg=#0000ff
+if has("gui_running")
+ :hi CCRedHi cterm=NONE guibg=#ff0000
+ :hi CCGreenHi cterm=NONE guibg=#00ff00
+ :hi CCBlueHi cterm=NONE guibg=#0000ff
+else
+ let n = forms#color#term#ConvertRGBTxt_2_Int("ff0000")
+ execute "hi CCRedHi cterm=NONE ctermbg=" . n
+ let n = forms#color#term#ConvertRGBTxt_2_Int("00ff00")
+ execute "hi CCGreenHi cterm=NONE ctermbg=" . n
+ let n = forms#color#term#ConvertRGBTxt_2_Int("0000ff")
+ execute "hi CCBlueHi cterm=NONE ctermbg=" . n
endif
+
"----
let rhsa = forms#newAction({ 'execute': function("CCSliderAction")})
let rhsa.slider2infoa = slider2infoa
View
88 doc/forms.txt
@@ -1,7 +1,7 @@
*forms.txt* For Vim version 7.3 Last change: 2012 July 19
Author: Richard Emberson
-Version: 1.5
+Version: 1.6
Title: Forms Library
Homepage: TODO
@@ -30,14 +30,16 @@ For Vim instructions on installing this 'txt' file, enter:
6. Colors |forms-colors|
7. Highlights |forms-highlights|
8. Supported Platforms |forms-platforms|
- 8.1 Linux Xterm & Vim
- 8.2 Linux urxvt256c & Vim
- 8.3 Linux urxvt & Vim
- 8.4 Linux Konsole & Vim
- 8.5 Linux Eterm & Vim
- 8.6 Linux GVim
- 8.7 Mac GVim
- 8.8 Windows GVim
+ 8.1 Linux Vim
+ 8.1.1 xterm
+ 8.1.2 urxvt256c
+ 8.1.3 urxvt
+ 8.1.4 rxvt
+ 8.1.5 Konsole
+ 8.1.6 Eterm
+ 8.2 Linux GVim
+ 8.3 Mac GVim
+ 8.4 Windows GVim
9. Glyphs |forms-glyphs|
10. Examples |forms-examples|
11. FAQ |forms-faq|
@@ -410,9 +412,9 @@ can not be done.
The {Forms} library running in Vim is designed to use 256 or 88 colors.
In one's {.vimrc} one should have:
- set t_Co=256
+ let &t_Co=256
or
- set t_Co=88
+ let &t_Co=88
To see if your environment supports 256 colors see:
http://vim.wikia.com/wiki/256_colors_in_vim
http://vim.wikia.com/wiki/256_colors_setup_for_console_Vim
@@ -468,53 +470,76 @@ The {Forms} library ought to work on any platform where Vim has 256 colors
(or full RGB as with GVim) and a fixed width UTF-8 font which implements
the box drawing and block characters in a reasonable manner.
-8.1 Linux Xterm & Vim ~
+8.1 Linux Vim ~
+
+8.1.1 xterm ~
{Forms} was developed and extensively tested on a Linux Xterm platform.
As long as the Xterm is using the correct font, such as
-misc-fixed-medium-r-normal-*-20-*-*-*-*-*-iso10646-*
-and has 256 color support and such support is declared in the {.vimrc}
+
+If with say, the font 10x20, then you may not be able to render all of
+the unicode characters, but it ought to still work.
+
+The Xterm has 256 color support and such support is declared in the {.vimrc}
file
- set t_Co=256
-then, there ought not be a problem.
+ let &t_Co=256
+
+More generally, depending upon the type of Xterm you could have in
+your {.vimrc}:
+ if ($TERM == 'xterm')
+ let &t_Co=256
+or
+ let &t_Co=88
+or
+ let &t_Co=16
+or
+ let &t_Co=8
+ endif
-8.2 Linux urxvt256c & Vim ~
+8.1.2 urxvt256c~
{Forms} simply works on the version of rxvt that supports Unicode and 256
-colors, urxvt256c. Add to .vimrc file:
- set t_Co=256
+colors, urxvt256c.
+Vim knows that &t_Co == 256.
-8.3 Linux urxvt & Vim~
+8.1.3 urxvt~
-{Forms} works with 88 colore rxvt that supports Unicode urxvt.
-Add to .vimrc file:
- set t_Co=88
+{Forms} works with 88 color verion of rxvt that supports Unicode, urxvt.
+Vim knows that &t_Co == 88.
-8.4 Linux Konsole & Vim~
+8.1.4 rxvt~
+
+{Forms} works with the non-Unicode, 8 color rxvt.
+Vim knows that &t_Co == 88.
+
+8.1.5 Konsole~
{Forms} works kconsole (though kconsole's UTF-8 9608 2588 FULL BLOCK
does not render correctly).
-Add to .vimrc file:
- set t_Co=256
+Add to .vimrc file:
+
+ let &t_Co=256
let g:FORMS_COLOR_TERM_KONSOLE = 1
-8.5 Linux Eterm & Vim~
+8.1.6 Eterm ~
(Forms} works eterm (well, I hope it works, no access to ETerm so could not test).
Add to .vimrc file:
- set t_Co=256
+
+ let &t_Co=256
let g:FORMS_COLOR_TERM_ETERM = 1
-8.6 Linux GVim ~
+8.2 Linux GVim ~
Some testing has been done on the Linux GVim platform and all of the
demonstration forms seem to work as expected.
-8.7 Mac GVim ~
+8.3 Mac GVim ~
No testing has been done on the Mac GVim configure. Feedback is welcome.
-8.8 Windows GVim ~
+8.4 Windows GVim ~
No testing has been done on the Windows GVim configure. Feedback is welcome.
@@ -1033,6 +1058,9 @@ and popup menus. The code is located in 'autoload/forms/menu.vim'.
==============================================================================
12. Release notes *forms-release-notes*
+1.6 - Fix: ~
+ Added support for 8 and 16 color terminals.
+ Works with non-unicode characters sets (there is some degradation).
1.5 - Fix: ~
Refactored code, Color utilities and Terminal code in separate files
Refactored code, Highlighting values defined and generated
Please sign in to comment.
Something went wrong with that request. Please try again.