#!/usr/bin/env python
data = {}
theme = None
for X in open('Xresources').readlines():
X = X.strip()
if X.startswith('!'):
comment = X[1:].strip()
elif '*' in X:
X = X.split('!')[0]
theme, rest = X.split('*')
theme = theme.strip()
color, val = [x.strip() for x in rest.split(':')]
if color.lower() == 'foreground':
color = 'color16'
elif color.lower() == 'background':
color = 'color17'
n = int(color[5:])
if theme not in data:
data[theme] = {}
data[theme][n] = val.lower()
data[theme]['comment'] = comment
for (theme, colors) in data.items():
data[theme] = {'comment':colors['comment'], 'colors':[colors[i] for i in range(18)]}
import json
open("color_themes.js",'w').write("Terminal.color_schemes="+json.dumps(data,separators=(',',':'), indent = 2))