Last active
October 19, 2017 23:39
-
-
Save mavc/5e3a07ce1e770a394f75a7faa126af3d to your computer and use it in GitHub Desktop.
Convert 16-color X resources themes to MinTTY
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import re | |
import sys | |
PAT = re.compile(r'^\*\.?(\w+):\s+#([a-fA-F0-9]{6})') | |
MAPPING = { | |
'cursorColor': 'CursorColour', | |
'background': 'BackgroundColour', | |
'foreground': 'ForegroundColour', | |
} | |
TERM_COLOURS = 'Black Red Green Yellow Blue Magenta Cyan White'.split() | |
for (i, name) in enumerate(TERM_COLOURS): | |
MAPPING['color{}'.format(i + 0)] = name | |
MAPPING['color{}'.format(i + 8)] = 'Bold' + name | |
def hex_to_triplet(code): | |
return ','.join(str(int(''.join(pair), base=16)) | |
for pair in zip(code[::2], code[1::2])) | |
def main(args): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('file') | |
args = parser.parse_args(args) | |
with open(args.file, 'r') as f: | |
lines = f.readlines() | |
for m in filter(None, map(PAT.search, lines)): | |
key, code = m.groups() | |
mapped_key = MAPPING.get(key, None) | |
if mapped_key: | |
print('{}={}'.format(mapped_key, hex_to_triplet(code))) | |
if __name__ == '__main__': | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment