I am a long time Vim user, but I downloaded MacVim for the first time  
this last weekend.  One of the first things I noticed is that my color  
scheme in a syntax highlighted file did not look right.

The information in :h macvim says this about Colors.plist

"Apart from the system colors, it is also possible to use standard X11  
color names (see http://en.wikipedia.org/wiki/X11_color_names) which  
usually come in a file called "rgb.txt".  MacVim does not have such a  
file, instead it keeps these colors in a dictionary called  
"Colors.plist".  The key in this dictionary is the name of the color  
and the value is an RGB value of the form #rrggbb stored as an integer."

First, those colors are easily accessible on every Mac with X11  
installed.  Simply run "showrgb" program (/usr/X11/bin/showrgb).
The numbers seem to correspond to the Wikipedia article.

However, it turns out those integers in Colors.plist are not right.
Take, for example, the value for MediumAquamarine: 6737066.

Now take a look at the Wikipedia page.
The RGB numbers are 102 205 170, or #66CDAA
The showrgb program gives the same decimal numbers for this color.

Let's open a terminal and check the hex number in bc.

        $ bc
        ...
        obase=16
        102
        66

        205
        CD

        170
        AA
        ^D

So Wikipedia hex value is correct.
Let's now use bc to convert this hex value to an integer.

        $ bc
        ...
        ibase=16
        66CDAA
        6737322
        ^D

Ouch. 6737322 != 6737066 (value from Colors.plist)

Similarly for practically all other colors!

I don't know how these numbers have been obtained, but they are simply  
wrong.  Even a simple color, such as Blue, is wrong -- 212.
It is clear from that Wikipedia page that Blue is #FF (0 0 255).
I mean, it's the B in RGB.  :-)

Now, being someone who prefers programming to typing huge amount of  
numbers I have written the attached program to generate the *correct*  
Colors.plist using the output of "showrgb" X11 utility.

I hope it gets used in the next MacVim snapshot.

Attached is also the correct Colors.plist generated by that program.
You can run the program on your Mac and compare that it produces the  
same plist.

Best regards,

        Zvezdan

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

#!/usr/bin/env python
#
# Copyright (c) 2009 Zvezdan Petkovic <[email protected]>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
"""Convert output of X11 showrgb program to Colors.plist for MacVim.

The showrgb output format is:

    144 238 144		light green
    144 238 144		LightGreen

The Colors.plist format is:

    <key>lightgreen</key>
    <integer>9498256</integer>

The color names are converted into a single lowecase word.
The duplicates, such as light green and LightGreen, are eliminated,
resulting in only one entry.
The three numbers for RGB are converted into a proper 24-bit integer.

Usage: rgb2plist.py >Colors.plist

"""

import sys

header = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd";>
<plist version="1.0">
<!-- generated from /usr/X11/bin/showrgb output by rgb2plist.py -->
<dict>"""

closing = """</dict>
</plist>"""

showrgb = '/usr/X11/bin/showrgb'

def main():
    if sys.version_info[:2] >= (2, 4):
        import subprocess
        pipe = subprocess.Popen(showrgb, stdout=subprocess.PIPE).stdout
    else:
        import os
        pipe = os.popen(showrgb)

    colors = {}
    for line in pipe:
        parts = line.split()
        color = ''.join(parts[3:]).lower()
        red, green, blue = [int(i) for i in parts[0:3]]
        rgb = red << 16 | green << 8 | blue
        colors[color] = rgb
    pipe.close()

    print header

    for color in sorted(colors):
        print "\t<key>" + color + "</key>"
        print "\t<integer>" + str(colors[color]) + "</integer>"

    print closing

if  __name__ == '__main__':
    main()

Attachment: Colors.plist
Description: Binary data

Reply via email to