Skip to content

Instantly share code, notes, and snippets.

@takashyx
Last active February 20, 2019 09:25
Show Gist options
  • Save takashyx/901420da415563b1ccaa657671c1d554 to your computer and use it in GitHub Desktop.
Save takashyx/901420da415563b1ccaa657671c1d554 to your computer and use it in GitHub Desktop.
WIP: convert .itemcolors (theme file for iterm) to colors settings for hyper term (currently 16 ANSI colors only)
import xml.etree.ElementTree as ET
# import pprint
tree = ET.parse('input.itermcolors')
root = tree.getroot()
color_dict = {}
for i in range(len(tree.find("dict"))):
dc = tree.find("dict")[i]
if dc.text.strip().find('Ansi') == 0:
color_n = dc.text.strip().split(' ')[1]
dd = tree.find("dict")[i + 1]
cd = {}
for j in range(len(dd)):
# print(f'{i+1}-{j} : {dd[j].tag} {dd[j].attrib} {dd[j].text}')
if dd[j].tag == 'key' and dd[j].text.strip().find('Component') != -1:
color = dd[j].text.strip().split(' ')[0]
value = dd[j + 1].text.strip()
cd[color] = value
color_dict[color_n] = cd
# pprint.pprint(color_dict)
ansi_n_to_colors_name = ['black',
'red',
'green',
'yellow',
'blue',
'magenda',
'cyan',
'white',
'lightBlack',
'lightRed',
'lightGreen',
'lightYellow',
'lightBlue',
'lightMagenda',
'lightCyan',
'lightWhite'
]
s = "colors: {\n"
for i in range(16):
r = int(255 * float(color_dict[str(i)]['Red']))
g = int(255 * float(color_dict[str(i)]['Green']))
b = int(255 * float(color_dict[str(i)]['Blue']))
converted_color = '#{:02x}{:02x}{:02x}'.format(r, g, b)
s = s + " " + ansi_n_to_colors_name[i] + ": '" + converted_color + "',\n"
s += "},"
print(s)
with open('output.colors_for_hyper', mode='w') as f:
f.write(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment