Created
November 10, 2016 17:07
-
-
Save Roger/205b18793ffef068835fcdb8009e5341 to your computer and use it in GitHub Desktop.
Download themes from https://terminal.sexy and convert them to st
This file contains hidden or 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
# to use the themes, remove your colors from config.h and #include themes/themename.h | |
import os | |
import re | |
import json | |
import unicodedata | |
import urllib.request | |
USER_AGENT = 'SThemer/0.1.0' | |
HEADERS = { | |
'User-Agent': USER_AGENT, | |
} | |
HOST = 'https://terminal.sexy' | |
INDEX = HOST + '/schemes/index.json' | |
SCHEMA = HOST + '/schemes/%s.json?v=0.2.10' | |
template = ''' | |
/* Terminal colors (16 first used in escape sequence) */ | |
static const char *colorname[] = { | |
/* 8 normal colors */ | |
[0] = "%s", /* black */ | |
[1] = "%s", /* red */ | |
[2] = "%s", /* green */ | |
[3] = "%s", /* yellow */ | |
[4] = "%s", /* blue */ | |
[5] = "%s", /* magenta */ | |
[6] = "%s", /* cyan */ | |
[7] = "%s", /* white */ | |
/* 8 bright colors */ | |
[8] = "%s", /* black */ | |
[9] = "%s", /* red */ | |
[10] = "%s", /* green */ | |
[11] = "%s", /* yellow */ | |
[12] = "%s", /* blue */ | |
[13] = "%s", /* magenta */ | |
[14] = "%s", /* cyan */ | |
[15] = "%s", /* white */ | |
/* special colors */ | |
[256] = "%s", /* background */ | |
[257] = "%s", /* foreground */ | |
}; | |
/* | |
* Default colors (colorname index) | |
* foreground, background, cursor | |
*/ | |
static unsigned int defaultfg = 257; | |
static unsigned int defaultbg = 256; | |
static unsigned int defaultcs = 257; | |
/* | |
* Colors used, when the specific fg == defaultfg. So in reverse mode this | |
* will reverse too. Another logic would only make the simple feature too | |
* complex. | |
*/ | |
static unsigned int defaultitalic = 7; | |
static unsigned int defaultunderline = 7; | |
''' | |
def normalize(value): | |
value = value.replace('/', '-') | |
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') | |
value = re.sub('[^\w\s-]', '', value.decode('utf-8')).strip().lower() | |
return re.sub('[\s]+', '_', value) | |
def read(url): | |
req = urllib.request.Request(url, headers=HEADERS) | |
with urllib.request.urlopen(req) as response: | |
data = response.read() | |
return json.loads(data.decode('utf-8')) | |
for theme in read(INDEX): | |
uri = SCHEMA % theme | |
theme_path = os.path.join('themes', normalize(theme) + '.h') | |
if os.path.exists(theme_path): | |
continue | |
print('Downloading..', theme) | |
data = read(uri) | |
colors = data['color'] | |
colors.append(data['background']) | |
colors.append(data['foreground']) | |
with open(os.path.join('themes', normalize(theme) + '.h'), 'w') as fd: | |
fd.write(template % tuple(colors)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment