summaryrefslogtreecommitdiffstats
path: root/layouts/community/ortho_4x12/guidoism/generate_c.py
blob: 7876bee68b9301999aec7ba13e823315da9010f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import itertools
import json
from pprint import pprint as pp

layers = dict(enumerate(['_QWERTY', '_LOWER', '_RAISE', '_MOVEMENT', '_NUMPAD']))
key_names = {('MO(%d)' % i): layers.get(i).strip('_') for i in layers.keys()}

unicodes = {
    "<i class='fa fa-fast-forward'></i>": "next",
    "<i class='fa fa-volume-down'></i>": "vol-",
    "<i class='fa fa-volume-up'></i>": "vol+",
    "<i class='fa fa-play'></i>": "play",
}

d = json.load(open('layouts/community/ortho_4x12/guidoism/guidoism.json'))

def grouper(iterable, n):
    args = [iter(iterable)] * n
    return itertools.zip_longest(*args, fillvalue='')

def truthy(s):
    return [a for a in s if a]

def just(s, n):
    return [a.center(n*2+1 if len(s) == 11 and i == 5 else n) for i, a in enumerate(s)]

def replace(s):
    return [key_names.get(a, a) for a in s]

def layer(i, l):
    n = max(len(s) for s in l)
    rows = [', '.join(replace(truthy(row))) for row in grouper(l, 12)]
    return '[%s] = %s(\n%s)' % (layers[i], d['layout'], ',\n'.join(rows))

print(',\n\n'.join(layer(i, l) for i, l in enumerate(d['layers'])))

def surround(s, a, b, c):
    return a + b.join(s) + c

def pattern(cell, table):
    return ['─'*cell for i in range(table)]

keys = json.load(open('layouts/community/ortho_4x12/guidoism/keys.json'))

def layer2(i, l):
    def replace(s):
        s = [keys.get(a, a) for a in s]
        return [unicodes.get(a, a) for a in s]
    n = max(len(s) for s in l)
    return [surround(just(replace(truthy(row)), 5), '│', '│', '│') for row in grouper(l, 12)]

for i, l in enumerate(d['layers']):
    print(surround(pattern(5, 12), '┌', '┬', '┐'))
    for n, row in enumerate(layer2(i, l)):
        print(row)
        if n < 3:
            print(surround(pattern(5, 12), '├', '┼', '┤'))
        else:
            print(surround(pattern(5, 12), '└', '┴', '┘'))