On Sun, Nov 11, 2007 at 01:24:11PM +0100, Bram Moolenaar wrote:
> 
> Interesting idea.  It's certainly more convenient to use the #rrggbb
> value than looking up the number.  Especially since the number depends
> on the terminal, 88 or 256 colors.
> 
> Taking this a step further: We could also make it work for 8 and 16
> color terminals.  Instead of "blue" you would use #0000ff.  Not sure how
> complicated this will get though.  And for an 8 color terminal one would
> still need to tune the colors.

That's a bit tough, since we would need to either be able to query the
current value of each of the &t_Co colors from the terminal emulator
(which AFAIK isn't portable across all TE's; see below) or make an
assumption about what each of those colors are (which is a bad idea,
since everyone I know who spends significant time in the terminal has
tweaked those 16 colors to be good for his own eyes; not to mention
that most TE's use different defaults, especially between those that
default to a light background vs those that default to a dark one).

Another hurdle with supporting this for 16 color terminals is that
there are really *very* few colors available.  Any colorscheme that
tries to subtly vary colors, for instance using many shades of red,
would just look awful when there are only 2 reds to choose from.
Also, we already support color names for 8 and 16 color terminals.

My humble opinion is that it is too much work with too many hurdles to
bother implementing for 16 color terminals, especially since we can
already use names rather than numbers.

> Do all the terminals supporting 88 and 256 colors really use the same
> color values?

Well...  As far as I can tell, they seem to _default_ to the same
values.  In the interest of researching this properly, I've
source-dived a few to be sure.

GNOME Terminal: same palette as xterm-256color (vte.c:2399)
PuTTY (pterm):  same palette as xterm-256color (gtkwin.c:1432)
Mrxvt:          same palette as xterm-256color (init.c:110)

Rxvt-unicode:   88 colour palette (init.C:74).

A quick scan through the Konsole sources didn't turn up the spot where
they set up the default sources, but there is a note in
README.moreColors saying "There is a predefined 256 color space
compatible with his xterm sister", which I read as saying that colors
16 through 255 are compatible with those in xterm.

Are there any other terminals supporting more than 16 colors that
I should check out?


Now, the patch I submitted used the simplifying assumption that the
user did not _change_ the colors in the cube or greyscale ramp (which
is possible in xterm through resources or control sequences, urxvt
using at least control sequences, and through some means in konsole,
I believe).

I agree that it would be better if we could query for the current
values, and work with those rather than the defaults.  That's possible
for xterm and urxvt, at least, using ESC ] 4;17;? BEL.  It's slightly
more complicated when running inside gnu screen, though, since you
have to tell screen to output that sequence to the TE that it's
running in directly, without interpreting it itself, using
ESC P ESC ] 4;17;? BEL ESC \.  So, then, the issue is..  How do we
know when we can query, and what sequence to use to do it?  Is there
a standard idiom for this?  As far as I know, this is still a very
hairy issue, since we can't trust terminfo/termcap, and exported
environment variables only get you so far...

Also, perhaps more importantly, even if we can check, when should we
do it?  It doesn't seem that we can reasonably handle it if, for
instance, the user enters Vim, suspends it, changes a color, and then
foregrounds Vim again.  Should we only check when Vim is started?
If we decide that checking the current colors is reasonable, I would
venture that the most reasonable time to check is on each :highlight
command, since in the event that the user does something like changing
a color while Vim is still running, it could be fixed by just redoing
the :colorscheme command.  Would checking once per :highlight be too
expensive, though?


And, while it's in my head: one *very* cool (albeit tangential)
feature would be the ability to dynamically change the xterm colors to
match the requested ones.  This, however, would be pretty tough to do
consistently: we would need to save the values when we start and
restore them whenever we get a signal, or whenever we execute
a command with :! when using an xterm with altscreen support, and it
would need to be controlled by an option, since it would affect, for
instance, all screens in gnu screen, not just the current one.  Off
topic at the moment, but it might be worth some more consideration in
the future, especially since it would mean that we could even make
very pretty colorschemes in 16 color terminals that support
dynamically changing those colors.

> > +   This works by attempting to gracefully degrade the specified color to
> > +   a similar available color.  In practice, you will likely not get
> > +   exactly the color you ask for; you will get the closest color that
> > +   your terminal emulator supports.  If your terminal emulator does not
> > +   report supporting at least 88 colors, this will fail.  If you are
> > +   certain that your terminal emulator does support 88 or more colors,
> > +   a possible workaround might be to set t_Co in your .vimrc, for
> > +   instance: >
> > +       if $TERM =~ 'xterm'
> > +           set t_Co=256
> > +       endif
> 
> If the xterm was compiled properly Vim can request it to send the number
> of colors being used.  See ":help xterm-codes".  Unfortunately
> termcap/terminfo are totally useless for these things.

Yes.. But it doesn't help for xterm -> screen -> vim, with the same
problem as above.  I don't know that it's sufficiently generic, and
a pointer in the help seems like a better idea...

> The stuff to haneld grey and non-grey colors looks like a bit of a hack.
> Isn't there a more consistent solution?

I'm open to suggestions.  A better solution might be to figure out if
the author probably wanted a grey, by saying for instance,
abs(r-b) < 16 && abs(b-g) < 16 && abs(g-r) < 16 and then filtering for
lowest Euclidean distance in rgb space, excluding greys if necessary.

Either way, it's not worth focusing on if we plan to support
customized, as opposed to default, palettes.  The algorithm will need
complete retooling; the current algorithm does revolve quite tightly
around the standard values.

> > +   if (hex[i] >= '0' && hex[i] <= '9')
> > +       *(rgb+i/2) += (hex[i] - '0') * order;
> > +   else if (hex[i] >= 'A' && hex[i] <= 'F')
> > +       *(rgb+i/2) += (hex[i] - 'A' + 10) * order;
> > +   else if (hex[i] >= 'a' && hex[i] <= 'f')
> > +       *(rgb+i/2) += (hex[i] - 'a' + 10) * order;
> 
> You can use hexhex2nr() here.

I figured there was a utility function around for this and I just
couldn't find it.

Looking at the #if defined()'s around hexhex2nr, what #defines are
paired with this cterm[fb]g=#rrggbb feature?  Is it just
#ifndef ALWAYS_USE_GUI, or is there something else that needs to be
considered?  Is this useful in windows builds, for instance?

> I would appreciate some people trying this on various terminals to check
> that it really works.  Perhaps you can write a color scheme that uses
> the RGB values for people to try out?

Absolutely.  I've attached copies of my two favorite colorschemes,
brookstream for dark terminals and autumnleaf for light terminals,
each modified to work with cterm[fb]g=#rrggbb values.  They'll work in
a patched vim, in both an 88 or 256 color terminal or in gvim, but
they won't work in an 8 or 16 color terminal.

~Matt

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

" Vim color file
" Maintainer: Anders Korte
" Last Change: 17 Oct 2004

" AutumnLeaf color scheme 1.0

set background=light

hi clear

if exists("syntax_on")
    syntax reset
endif

let colors_name="autumnleaf-rgb"

" Colors for the User Interface.

hi Cursor       ctermbg=#aa7733 guibg=#aa7733   ctermfg=#ffeebb guifg=#ffeebb   
cterm=bold gui=bold
hi Normal       ctermbg=#fffdfa guibg=#fffdfa   ctermfg=black guifg=black       
cterm=none gui=none
hi NonText      ctermbg=#eafaea guibg=#eafaea   ctermfg=#000099 guifg=#000099   
cterm=bold gui=bold
hi Visual       ctermbg=#fff8cc guibg=#fff8cc   ctermfg=black guifg=black       
cterm=none gui=none
" hi VisualNOS

hi Linenr       ctermbg=bg guibg=bg     ctermfg=#999999 guifg=#999999 
cterm=none gui=none

" Uncomment these if you use Diff...??
" hi DiffText   ctermbg=#cc0000 guibg=#cc0000   ctermfg=white guifg=white 
cterm=none gui=none
" hi DiffAdd    ctermbg=#0000cc guibg=#0000cc   ctermfg=white guifg=white 
cterm=none gui=none
" hi DiffChange ctermbg=#990099 guibg=#990099   ctermfg=white guifg=white 
cterm=none gui=none
" hi DiffDelete ctermbg=#888888 guibg=#888888   ctermfg=#333333 guifg=#333333 
cterm=none gui=none

hi Directory    ctermbg=bg guibg=bg     ctermfg=#337700 guifg=#337700   
cterm=none gui=none

hi IncSearch    ctermbg=#c8e8ff guibg=#c8e8ff   ctermfg=black guifg=black       
cterm=none gui=none
hi Search       ctermbg=#c8e8ff guibg=#c8e8ff   ctermfg=black guifg=black       
cterm=none gui=none
hi SpecialKey   ctermbg=bg guibg=bg     ctermfg=fg guifg=fg     cterm=none 
gui=none
hi Titled       ctermbg=bg guibg=bg     ctermfg=fg guifg=fg     cterm=none 
gui=none

hi ErrorMsg         ctermbg=bg guibg=bg ctermfg=#cc0000 guifg=#cc0000   
cterm=bold gui=bold
hi ModeMsg          ctermbg=bg guibg=bg ctermfg=#003399 guifg=#003399   
cterm=none gui=none
hi link MoreMsg     ModeMsg
hi link Question    ModeMsg
hi WarningMsg       ctermbg=bg guibg=bg ctermfg=#cc0000 guifg=#cc0000   
cterm=bold gui=bold

hi StatusLine   ctermbg=#ffeebb guibg=#ffeebb   ctermfg=black guifg=black       
cterm=bold gui=bold
hi StatusLineNC ctermbg=#aa8866 guibg=#aa8866   ctermfg=#f8e8cc guifg=#f8e8cc   
cterm=none gui=none
hi VertSplit    ctermbg=#aa8866 guibg=#aa8866   ctermfg=#ffe0bb guifg=#ffe0bb   
cterm=none gui=none

" hi Folded
" hi FoldColumn
" hi SignColumn


" Colors for Syntax Highlighting.

hi Comment ctermbg=#ddeedd guibg=#ddeedd ctermfg=#002200 guifg=#002200 
cterm=none gui=none

hi Constant     ctermbg=bg guibg=bg    ctermfg=#003399 guifg=#003399 cterm=bold 
gui=bold
hi String       ctermbg=bg guibg=bg    ctermfg=#003399 guifg=#003399 
cterm=italic gui=italic
hi Character    ctermbg=bg guibg=bg    ctermfg=#003399 guifg=#003399 
cterm=italic gui=italic
hi Number       ctermbg=bg guibg=bg    ctermfg=#003399 guifg=#003399 cterm=bold 
gui=bold
hi Boolean      ctermbg=bg guibg=bg    ctermfg=#003399 guifg=#003399 cterm=bold 
gui=bold
hi Float        ctermbg=bg guibg=bg    ctermfg=#003399 guifg=#003399 cterm=bold 
gui=bold

hi Identifier   ctermbg=bg guibg=bg    ctermfg=#003399 guifg=#003399 cterm=none 
gui=none
hi Function     ctermbg=bg guibg=bg    ctermfg=#0055aa guifg=#0055aa cterm=bold 
gui=bold
hi Statement    ctermbg=bg guibg=bg    ctermfg=#003399 guifg=#003399 cterm=none 
gui=none

hi Conditional  ctermbg=bg guibg=bg    ctermfg=#aa7733 guifg=#aa7733 cterm=bold 
gui=bold
hi Repeat       ctermbg=bg guibg=bg    ctermfg=#aa5544 guifg=#aa5544 cterm=bold 
gui=bold
hi link Label   Conditional
hi Operator     ctermbg=bg guibg=bg    ctermfg=#aa7733 guifg=#aa7733 cterm=bold 
gui=bold
hi link Keyword Statement
hi Exception    ctermbg=bg guibg=bg    ctermfg=#228877 guifg=#228877 cterm=bold 
gui=bold

hi PreProc          ctermbg=bg guibg=bg ctermfg=#aa7733 guifg=#aa7733 
cterm=bold gui=bold
hi Include          ctermbg=bg guibg=bg ctermfg=#558811 guifg=#558811 
cterm=bold gui=bold
hi link Define      Include
hi link Macro       Include
hi link PreCondit   Include

hi Type                 ctermbg=bg guibg=bg    ctermfg=#007700 guifg=#007700 
cterm=bold gui=bold
hi link StorageClass    Type
hi link Structure       Type
hi Typedef              ctermbg=bg guibg=bg    ctermfg=#009900 guifg=#009900 
cterm=italic gui=italic

hi Special          ctermbg=bg guibg=bg     ctermfg=fg guifg=fg     cterm=none 
gui=none
hi SpecialChar      ctermbg=bg guibg=bg     ctermfg=fg guifg=fg     cterm=bold 
gui=bold
hi Tag              ctermbg=bg guibg=bg     ctermfg=#003399 guifg=#003399   
cterm=bold gui=bold
hi link Delimiter   Special
hi SpecialComment   ctermbg=#dddddd guibg=#dddddd   ctermfg=#aa0000 
guifg=#aa0000   cterm=none gui=none
hi link Debug       Special

hi Underlined ctermbg=bg guibg=bg ctermfg=blue guifg=blue cterm=underline 
gui=underline

hi Title    ctermbg=bg guibg=bg ctermfg=fg guifg=fg     cterm=bold gui=bold
hi Ignore   ctermbg=bg guibg=bg ctermfg=#999999 guifg=#999999   cterm=none 
gui=none
hi Error    ctermbg=red guibg=red       ctermfg=white guifg=white       
cterm=none gui=none
hi Todo     ctermbg=bg guibg=bg ctermfg=#aa0000 guifg=#aa0000   cterm=none 
gui=none
"--------------------------------------------------------------------
" Name Of File: brookstream.vim.
" Description: Gvim colorscheme, works best with version 6.1   cterm .
" Maintainer: Peter B�ckstr�m.
" Creator: Peter B�ckstr�m.
" URL: http://www.brookstream.org (Swedish).
" Credits: Inspiration from the darkdot scheme.
" Last Change: Friday, April 13, 2003.
" Installation: Drop this file in your $VIMRUNTIME/colors/ directory.
"--------------------------------------------------------------------

set background=dark
hi clear
if exists("syntax_on")
    syntax reset
endif
let g:colors_name="brookstream-rgb"

"--------------------------------------------------------------------

hi Normal           gui=none  cterm=none  ctermbg=#000000 guibg=#000000  
ctermfg=#bbbbbb guifg=#bbbbbb
hi Cursor                                 ctermbg=#44ff44 guibg=#44ff44  
ctermfg=#000000 guifg=#000000
hi Directory                                                             
ctermfg=#44ffff guifg=#44ffff
hi DiffAdd                                ctermbg=#080808 guibg=#080808  
ctermfg=#ffff00 guifg=#ffff00
hi DiffDelete                             ctermbg=#080808 guibg=#080808  
ctermfg=#444444 guifg=#444444
hi DiffChange                             ctermbg=#080808 guibg=#080808  
ctermfg=#ffffff guifg=#ffffff
hi DiffText                               ctermbg=#080808 guibg=#080808  
ctermfg=#bb0000 guifg=#bb0000
hi ErrorMsg                               ctermbg=#880000 guibg=#880000  
ctermfg=#ffffff guifg=#ffffff
hi Folded                                                                
ctermfg=#000088 guifg=#000088
hi IncSearch                              ctermbg=#000000 guibg=#000000  
ctermfg=#bbcccc guifg=#bbcccc
hi LineNr                                 ctermbg=#050505 guibg=#050505  
ctermfg=#4682b4 guifg=#4682b4
hi ModeMsg                                                               
ctermfg=#ffffff guifg=#ffffff
hi MoreMsg                                                               
ctermfg=#44ff44 guifg=#44ff44
hi NonText                                                               
ctermfg=#4444ff guifg=#4444ff
hi Question                                                              
ctermfg=#ffff00 guifg=#ffff00
hi SpecialKey                                                            
ctermfg=#4444ff guifg=#4444ff
hi StatusLine       gui=none  cterm=none  ctermbg=#2f4f4f guibg=#2f4f4f  
ctermfg=#ffffff guifg=#ffffff
hi StatusLineNC     gui=none  cterm=none  ctermbg=#bbbbbb guibg=#bbbbbb  
ctermfg=#000000 guifg=#000000
hi Title                                                                 
ctermfg=#ffffff guifg=#ffffff
hi Visual           gui=none  cterm=none  ctermbg=#bbbbbb guibg=#bbbbbb  
ctermfg=#000000 guifg=#000000
hi WarningMsg                                                            
ctermfg=#ffff00 guifg=#ffff00

" syntax highlighting groups ----------------------------------------

hi Comment                                                               
ctermfg=#696969 guifg=#696969
hi Constant                                                              
ctermfg=#00aaaa guifg=#00aaaa
hi Identifier                                                            
ctermfg=#00e5ee guifg=#00e5ee
hi Statement                                                             
ctermfg=#00ffff guifg=#00ffff
hi PreProc                                                               
ctermfg=#8470ff guifg=#8470ff
hi Type                                                                  
ctermfg=#ffffff guifg=#ffffff
hi Special          gui=none  cterm=none                                 
ctermfg=#87cefa guifg=#87cefa
hi Underlined       gui=bold  cterm=bold                                 
ctermfg=#4444ff guifg=#4444ff
hi Ignore                                                                
ctermfg=#444444 guifg=#444444
hi Error                                  ctermbg=#000000 guibg=#000000  
ctermfg=#bb0000 guifg=#bb0000
hi Todo                                   ctermbg=#aa0006 guibg=#aa0006  
ctermfg=#fff300 guifg=#fff300
hi Operator         gui=none  cterm=none                                 
ctermfg=#00bfff guifg=#00bfff
hi Function                                                              
ctermfg=#1e90ff guifg=#1e90ff
hi String           gui=none  cterm=none                                 
ctermfg=#4682b4 guifg=#4682b4
hi Boolean                                                               
ctermfg=#9bcd9b guifg=#9bcd9b

Raspunde prin e-mail lui