Converting a black TextMate theme to white using a simple Ruby application
Download Theme (once downloaded, simply double click on the file to install) I created the IR_Black theme, and some people asked for a white version of it. So instead of doing it manually I thought a quick Ruby script to make all the colors darker would work well. I started by creating a new theme, then I changed all the foreground colors to their negative. This worked well and maintained the contrast between the different colors, but it changed the whole look of the theme (changing blues to reds, etc.), which I didn't want. Then I tried converting the colors from RGB into HSL and then inverting the L (which is lightness or luminance depending on what you read); this did what I wanted. TextMate stores its colors in HTML Hex triplet format (#FF0000), so all I needed to do was parse those out of the original file, convert the color into HSL, then invert it by subtracting it from its max (which is 1). I used the color-tools gem to do the color manipulation, and it worked well.
# gem install color-tools
regx = /(foregrounds*?)(#.+?)()/
new_xml = STDIN.read.gsub(regx) do
hsl = Color::RGB.from_html($2).to_hsl
hsl.l = 1 - hsl.l
$1 + hsl.html + $3
end
puts new_xml
After I created the script above (which I named c_theme.rb), I just piped the original theme to it and created the new theme:
cat IR_Black.tmTheme | ruby c_theme.rb >> IR_White.tmThemeI then changed the backcolors to white, and manually tweaked it some. It's much harder to make a white theme, because you don't see the color difference as easily, so it's hard to find colors that stand out, without being too glaring. I personally don't like white themes much, but I think I captured the essence of the black theme with my conversion. Example Ruby code using the theme:



This is not working for me. I'm getting
cat SunburstSL.tmTheme | c_theme.rb >> SunburstWhite.tmTheme
/usr/bin/c_theme.rb: line 1: require: command not found
/usr/bin/c_theme.rb: line 2: require: command not found
/usr/bin/c_theme.rb: line 4: syntax error near unexpected token `('
/usr/bin/c_theme.rb: line 4: `regx = /(foregrounds*?)(#.+?)()/'
I'm no Ruby expert. I did download and setup color-tools.
I also added #!/usr/bin/ruby to the begging of the script above, saved the c_theme.rb file into /usr/bin and chmod +x.
Steve,
I would verify your ruby installation, if you are getting errors on the require statements, there is something fundamentally wrong. Verify that you have the latest release of Ruby and Gems installed and working. If you aren't using rubygems, remove that require and make sure color tools is correctly installed.