|
|
@@ -1,8 +1,8 @@
|
|
|
"""Functions that help you work with QMK keymaps.
|
|
|
"""
|
|
|
-from functools import lru_cache
|
|
|
import json
|
|
|
import sys
|
|
|
+from functools import lru_cache
|
|
|
from pathlib import Path
|
|
|
from subprocess import DEVNULL
|
|
|
|
|
|
@@ -32,6 +32,7 @@ __KEYMAP_GOES_HERE__
|
|
|
"""
|
|
|
|
|
|
|
|
|
+@lru_cache(maxsize=0)
|
|
|
def template_json(keyboard):
|
|
|
"""Returns a `keymap.json` template for a keyboard.
|
|
|
|
|
|
@@ -49,6 +50,7 @@ def template_json(keyboard):
|
|
|
return template
|
|
|
|
|
|
|
|
|
+@lru_cache(maxsize=0)
|
|
|
def template_c(keyboard):
|
|
|
"""Returns a `keymap.c` template for a keyboard.
|
|
|
|
|
|
@@ -124,6 +126,7 @@ def keymap_completer(prefix, action, parser, parsed_args):
|
|
|
return []
|
|
|
|
|
|
|
|
|
+@lru_cache(maxsize=0)
|
|
|
def is_keymap_dir(keymap, c=True, json=True, additional_files=None):
|
|
|
"""Return True if Path object `keymap` has a keymap file inside.
|
|
|
|
|
|
@@ -182,6 +185,7 @@ def generate_json(keymap, keyboard, layout, layers):
|
|
|
return new_keymap
|
|
|
|
|
|
|
|
|
+@lru_cache(maxsize=0)
|
|
|
def generate_c(keyboard, layout, layers):
|
|
|
"""Returns a `keymap.c` or `keymap.json` for the specified keyboard, layout, and layers.
|
|
|
|
|
|
@@ -268,6 +272,7 @@ def write(keyboard, keymap, layout, layers):
|
|
|
return write_file(keymap_file, keymap_content)
|
|
|
|
|
|
|
|
|
+@lru_cache(maxsize=0)
|
|
|
def locate_keymap(keyboard, keymap):
|
|
|
"""Returns the path to a keymap for a specific keyboard.
|
|
|
"""
|
|
|
@@ -307,7 +312,7 @@ def locate_keymap(keyboard, keymap):
|
|
|
return community_layout / 'keymap.c'
|
|
|
|
|
|
|
|
|
-@lru_cache()
|
|
|
+@lru_cache(maxsize=0)
|
|
|
def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=False):
|
|
|
"""List the available keymaps for a keyboard.
|
|
|
|
|
|
@@ -361,6 +366,7 @@ def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=Fa
|
|
|
return sorted(names)
|
|
|
|
|
|
|
|
|
+@lru_cache(maxsize=0)
|
|
|
def _c_preprocess(path, stdin=DEVNULL):
|
|
|
""" Run a file through the C pre-processor
|
|
|
|
|
|
@@ -380,6 +386,7 @@ def _c_preprocess(path, stdin=DEVNULL):
|
|
|
return pre_processed_keymap.stdout
|
|
|
|
|
|
|
|
|
+@lru_cache(maxsize=0)
|
|
|
def _get_layers(keymap): # noqa C901 : until someone has a good idea how to simplify/split up this code
|
|
|
""" Find the layers in a keymap.c file.
|
|
|
|
|
|
@@ -500,6 +507,7 @@ def _get_layers(keymap): # noqa C901 : until someone has a good idea how to sim
|
|
|
return layers
|
|
|
|
|
|
|
|
|
+@lru_cache(maxsize=0)
|
|
|
def parse_keymap_c(keymap_file, use_cpp=True):
|
|
|
""" Parse a keymap.c file.
|
|
|
|
|
|
@@ -529,6 +537,7 @@ def parse_keymap_c(keymap_file, use_cpp=True):
|
|
|
return keymap
|
|
|
|
|
|
|
|
|
+@lru_cache(maxsize=0)
|
|
|
def c2json(keyboard, keymap, keymap_file, use_cpp=True):
|
|
|
""" Convert keymap.c to keymap.json
|
|
|
|