[Keymap] Signum3.0 Generate printable keymap (#5818)

* Externalize generation of visual text keymap

* Generate keymap in Asciidoc format for further processing

* Remove artifacts from a2x call
master
Jan Christoph Ebersbach 2019-05-08 20:04:32 +02:00 committed by Drashna Jaelre
parent 86532fa8d3
commit aa65cd7a90
2 changed files with 59 additions and 21 deletions

View File

@ -56,7 +56,29 @@ def toLgd(s):
return _translate(s)[1]
def writeKeymap(f_template, f_keymap, columns, rows):
def quoteC(text):
yield "/*"
for line in text:
yield " * " + line
yield " */\n"
def getKeymapText(id, layer, columns, rows):
keymap = []
keymap.append("Layer %d" % id)
keymap.append("------------------------------------------------- -------------------------------------------------")
keymap.append("|{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|".format(*map(toLgd, layer[:12])))
keymap.append("------------------------------------------------- -------------------------------------------------")
keymap.append("|{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|".format(*map(toLgd, layer[12:24])))
keymap.append("------------------------------------------------- -------------------------------------------------")
keymap.append("|{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|".format(*map(toLgd, layer[24:36])))
keymap.append("-----------------------------------------------------------------------------------------------------------------")
keymap.append(" {0} {1} {2} |{3}|{4}|{5}|{6}|{7}|{8}| {9} {10} {11}".format(*map(toLgd, layer[36:48])).rstrip())
keymap.append(" -------------------------------------------------")
return keymap
def writeKeymap(f_template, f_keymap, layers, columns, rows):
doCopy = False
for line in f_template:
@ -78,19 +100,9 @@ def writeKeymap(f_template, f_keymap, columns, rows):
f_keymap.write(u"\t[{0}] = {1}, // {2}\n".format(k, v, chr(int(v, 0))))
elif line.startswith("//<keymaps/>"):
doCopy = False
for layer, L in enumerate(layout.layers):
for layer, L in enumerate(layers):
r_counter = rows
f_keymap.write("/* Layer %d\n" % layer)
f_keymap.write(" * ------------------------------------------------- -------------------------------------------------\n")
f_keymap.write(" * |{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|\n".format(*map(toLgd, L[:12])))
f_keymap.write(" * ------------------------------------------------- -------------------------------------------------\n")
f_keymap.write(" * |{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|\n".format(*map(toLgd, L[12:24])))
f_keymap.write(" * ------------------------------------------------- -------------------------------------------------\n")
f_keymap.write(" * |{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|\n".format(*map(toLgd, L[24:36])))
f_keymap.write(" * -----------------------------------------------------------------------------------------------------------------\n")
f_keymap.write(" * {0} {1} {2} |{3}|{4}|{5}|{6}|{7}|{8}| {9} {10} {11}".format(*map(toLgd, L[36:48])).rstrip()+"\n")
f_keymap.write(" * -------------------------------------------------\n")
f_keymap.write(" */\n")
f_keymap.write('\n'.join(quoteC(getKeymapText(layer, L, columns, rows))))
l_code = '\tLAYOUT_ortho_4x12(\n'
for r in range(r_counter):
@ -123,6 +135,20 @@ def getKeymapJSON(keyboard, keymap, layout, layers):
}, sort_keys=True, indent=4)
def getKeymapAsciidoc(title, layers, columns, rows):
yield '= ' + title
yield ''
for id, layer in enumerate(layers):
keymap = getKeymapText(id, layer, columns, rows)
if len(keymap):
yield '.' + keymap[0]
yield '--------------------------'
for line in keymap[1:]:
yield ' ' + line
yield '--------------------------'
yield ''
def layersToKC(layers):
return [list(map(toKC, layer)) for layer in layers]
@ -147,7 +173,7 @@ def pathToKeyboard(path):
if __name__ == "__main__":
with open("km_template.txt", mode="r") as f_template:
with open("keymap.c", mode="w", encoding='utf-8') as f_keymap:
writeKeymap(f_template, f_keymap, columns=12, rows=4)
writeKeymap(f_template, f_keymap, layout.layers, columns=12, rows=4)
abspath = os.path.dirname(os.path.abspath(__file__))
keyboard = list(reversed(list(pathToKeyboard(abspath))))
@ -161,3 +187,8 @@ if __name__ == "__main__":
keyboard_layout,
layersToKC(layout.layers))
)
with open("keymap.adoc", mode="w") as f_keymapasciidoc:
f_keymapasciidoc.write('\n'.join(getKeymapAsciidoc('Signum 3.0 %s_%s' % ('_'.join(keyboard), keymap), layout.layers, columns=12, rows=4)))
print("Run the following command to generate a PDF from the keymap")
print("a2x -f pdf --xsltproc-opts '--stringparam page.orientation landscape --stringparam body.font.master 12' --fop -v keymap.adoc")

View File

@ -623,7 +623,8 @@ const uint32_t PROGMEM unicode_map[] = {
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Layer 0
/*
* Layer 0
* ------------------------------------------------- -------------------------------------------------
* | Tab | q | w | e | r | t | | y | u | i | o | p | [ |
* ------------------------------------------------- -------------------------------------------------
@ -641,7 +642,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_LCTL, KC_LALT, KC_LGUI, TT(2), LT(6,KC_SPC), LT(4,KC_DEL), LT(4,KC_ENT), KC_SPC, LT(2,KC_BSPC), KC_RGUI, KC_RALT, KC_RCTL
),
/* Layer 1
/*
* Layer 1
* ------------------------------------------------- -------------------------------------------------
* | Tab | q | w | f | p | g | | j | l | u | y | ; | [ |
* ------------------------------------------------- -------------------------------------------------
@ -659,7 +661,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_LCTL, KC_LALT, KC_LGUI, TT(2), LT(6,KC_SPC), LT(4,KC_DEL), LT(4,KC_ENT), KC_SPC, LT(2,KC_BSPC), KC_RGUI, KC_RALT, KC_RCTL
),
/* Layer 2
/*
* Layer 2
* ------------------------------------------------- -------------------------------------------------
* | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | ] |
* ------------------------------------------------- -------------------------------------------------
@ -677,7 +680,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
TG(2), KC_TRNS, KC_TRNS, KC_TRNS, KC_DEL, KC_TRNS, KC_TRNS, KC_BSPC, KC_0, KC_TRNS, KC_TRNS, KC_TRNS
),
/* Layer 3
/*
* Layer 3
* ------------------------------------------------- -------------------------------------------------
* | | F1 | F2 | F3 | F4 | F5 | | F6 | F7 | F8 | F9 | F10 | XXX |
* ------------------------------------------------- -------------------------------------------------
@ -695,7 +699,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
TG(3), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
),
/* Layer 4
/*
* Layer 4
* ------------------------------------------------- -------------------------------------------------
* | Esc | Esc | Tab x | Tab n |CPg Dn |CPg Dn | |Pg Down| Home |^ Arrow|Insert |SInsert| Esc |
* ------------------------------------------------- -------------------------------------------------
@ -713,7 +718,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
TG(4), KC_TRNS, KC_TRNS, KC_TRNS, KC_DEL, KC_TRNS, KC_TRNS, KC_BSPC, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
),
/* Layer 5
/*
* Layer 5
* ------------------------------------------------- -------------------------------------------------
* | | XXX |play/ps| Vol + | Vol + | XXX | | XXX | XXX | XXX | XXX |_reset | Power |
* ------------------------------------------------- -------------------------------------------------
@ -731,7 +737,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
TG(5), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
),
/* Layer 6
/*
* Layer 6
* ------------------------------------------------- -------------------------------------------------
* | | acc1 | XXX | XXX | XXX | XXX | |^ Wheel|< Wheel|^ Mouse|> Wheel| XXX | XXX |
* ------------------------------------------------- -------------------------------------------------