Skip to content

Commit

Permalink
Correctly handle json keymaps with ANY()
Browse files Browse the repository at this point in the history
  • Loading branch information
skullydazed committed Apr 7, 2020
1 parent f4b67cd commit b4ef724
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/python/qmk/keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/* THIS FILE WAS GENERATED!
*
* This file was generated by qmk-compile-json. You may or may not want to
* This file was generated by qmk json2c. You may or may not want to
* edit it directly.
*/
Expand Down Expand Up @@ -39,6 +39,15 @@ def template(keyboard):
return DEFAULT_KEYMAP_C


def _strip_any(keycode):
"""Remove ANY() from a keycode.
"""
if keycode.startswith('ANY(') and keycode.endswith(')'):
keycode = keycode[4:-1]

return keycode


def generate(keyboard, layout, layers):
"""Returns a keymap.c for the specified keyboard, layout, and layers.
Expand All @@ -53,9 +62,12 @@ def generate(keyboard, layout, layers):
An array of arrays describing the keymap. Each item in the inner array should be a string that is a valid QMK keycode.
"""
layer_txt = []

for layer_num, layer in enumerate(layers):
if layer_num != 0:
layer_txt[-1] = layer_txt[-1] + ','

layer = map(_strip_any, layer)
layer_keys = ', '.join(layer)
layer_txt.append('\t[%s] = %s(%s)' % (layer_num, layout, layer_keys))

Expand Down

0 comments on commit b4ef724

Please sign in to comment.