Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 181 lines (175 sloc) 6.1 KB
#!/usr/bin/ruby -w
#
# Converts X11 color names into hex codes or vice
# versa, depending on the filename of this script.
#
# Usage: x11-to-hex < INPUT_FILE
# Usage: cat INPUT_FILE | x11-to-hex
#
# Usage: hex-to-x11 < INPUT_FILE
# Usage: cat INPUT_FILE | hex-to-x11
#
# Written in 2010 by Suraj N. Kurapati <https://github.com/sunaku>
# X11 color names and hex values, gotten from:
# http://www.mcfedries.com/books/cightml/x11color.htm
COLORS = {
:MediumAquamarine => '#66CDAA',
:Aquamarine => '#7FFFD4',
:DarkTurquoise => '#00CED1',
:BurlyWood => '#DEB887',
:SandyBrown => '#F4A460',
:MediumTurquoise => '#48D1CC',
:RoyalBlue => '#4169E1',
:LavenderBlush => '#FFF0F5',
:Peru => '#CD853F',
:Silver => '#C0C0C0',
:Tomato => '#FF6347',
:Aqua => '#00FFFF',
:SlateBlue => '#6A5ACD',
:SpringGreen => '#00FF7F',
:ForestGreen => '#228B22',
:Indigo => '#4B0082',
:Thistle => '#D8BFD8',
:DarkGoldenrod => '#B8860B',
:Beige => '#F5F5DC',
:LightSkyBlue => '#87CEFA',
:LemonChiffon => '#FFFACD',
:PaleTurquoise => '#AFEEEE',
:IndianRed => '#CD5C5C',
:LightCoral => '#F08080',
:Brown => '#A52A2A',
:DarkSlateGray => '#2F4F4F',
:DarkSlateGrey => '#2F4F4F',
:DarkViolet => '#9400D3',
:CadetBlue => '#5F9EA0',
:FireBrick => '#B22222',
:DarkSalmon => '#E9967A',
:Chartreuse => '#7FFF00',
:PeachPuff => '#FFDAB9',
:Moccasin => '#FFE4B5',
:SkyBlue => '#87CEEB',
:OrangeRed => '#FF4500',
:Gray => '#808080',
:Grey => '#808080',
:DarkGray => '#A9A9A9',
:DarkGrey => '#A9A9A9',
:Linen => '#FAF0E6',
:CornflowerBlue => '#6495ED',
:DarkSlateBlue => '#483D8B',
:Chocolate => '#D2691E',
:Honeydew => '#F0FFF0',
:MediumSeaGreen => '#3CB371',
:Magenta => '#FF00FF',
:DeepPink => '#FF1493',
:SeaGreen => '#2E8B57',
:Green => '#008000',
:Maroon => '#800000',
:Sienna => '#A0522D',
:DarkSeaGreen => '#8FBC8F',
:PowderBlue => '#B0E0E6',
:DeepSkyBlue => '#00BFFF',
:RosyBrown => '#BC8F8F',
:Navy => '#000080',
:Orange => '#FFA500',
:PaleGoldenrod => '#EEE8AA',
:SaddleBrown => '#8B4513',
:Yellow => '#FFFF00',
:Crimson => '#DC143C',
:NavajoWhite => '#FFDEAD',
:Pink => '#FFC0CB',
:MediumSlateBlue => '#7B68EE',
:Wheat => '#F5DEB3',
:Tan => '#D2B48C',
:LightPink => '#FFB6C1',
:Black => '#000000',
:PaleGreen => '#98FB98',
:Red => '#FF0000',
:LightYellow => '#FFFFE0',
:LawnGreen => '#7CFC00',
:DarkGreen => '#006400',
:Blue => '#0000FF',
:Coral => '#FF7F50',
:LightBlue => '#ADD8E6',
:Purple => '#800080',
:DarkBlue => '#00008B',
:DarkOrange => '#FF8C00',
:LightSeaGreen => '#20B2AA',
:Turquoise => '#40E0D0',
:Cornsilk => '#FFF8DC',
:YellowGreen => '#9ACD32',
:LimeGreen => '#32CD32',
:HotPink => '#FF69B4',
:Seashell => '#FFF5EE',
:FloralWhite => '#FFFAF0',
:Plum => '#DDA0DD',
:Bisque => '#FFE4C4',
:Ivory => '#FFFFF0',
:LightGray => '#D3D3D3',
:LightGrey => '#D3D3D3',
:GreenYellow => '#ADFF2F',
:GhostWhite => '#F8F8FF',
:Azure => '#F0FFFF',
:SteelBlue => '#4682B4',
:DarkMagenta => '#8B008B',
:Khaki => '#F0E68C',
:MistyRose => '#FFE4E1',
:BlueViolet => '#8A2BE2',
:AliceBlue => '#F0F8FF',
:DarkCyan => '#008B8B',
:Goldenrod => '#DAA520',
:MediumBlue => '#0000CD',
:MediumPurple => '#9370DB',
:OldLace => '#FDF5E6',
:MintCream => '#F5FFFA',
:OliveDrab => '#6B8E23',
:LightSteelBlue => '#B0C4DE',
:MidnightBlue => '#191970',
:SlateGray => '#708090',
:SlateGrey => '#708090',
:Orchid => '#DA70D6',
:MediumVioletRed => '#C71585',
:WhiteSmoke => '#F5F5F5',
:Violet => '#EE82EE',
:DarkOliveGreen => '#556B2F',
:Teal => '#008080',
:Fuchsia => '#FF00FF',
:MediumSpringGreen => '#00FA9A',
:DarkKhaki => '#BDB76B',
:BlanchedAlmond => '#FFEBCD',
:LightGoldenrodYellow => '#FAFAD2',
:Salmon => '#FA8072',
:DimGray => '#696969',
:DimGrey => '#696969',
:Snow => '#FFFAFA',
:LightCyan => '#E0FFFF',
:AntiqueWhite => '#FAEBD7',
:Cyan => '#00FFFF',
:LightSlateGray => '#778899',
:LightSlateGrey => '#778899',
:White => '#FFFFFF',
:MediumOrchid => '#BA55D3',
:DodgerBlue => '#1E90FF',
:Gold => '#FFD700',
:PaleVioletRed => '#DB7093',
:LightGreen => '#90EE90',
:Gainsboro => '#DCDCDC',
:DarkRed => '#8B0000',
:LightSalmon => '#FFA07A',
:Lime => '#00FF00',
:PapayaWhip => '#FFEFD5',
:DarkOrchid => '#9932CC',
:Lavender => '#E6E6FA',
:Olive => '#808000'
}
input = STDIN.read
case $0
when /hex$/
COLORS.each_pair do |x11, hex|
input.gsub! %r{\b#{x11}\b}i, hex
end
when /x11$/
COLORS.each_pair do |x11, hex|
input.gsub! hex, x11.to_s
end
end
print input