aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <[email protected]>2024-03-14 10:24:24 +0000
committerGitHub <[email protected]>2024-03-14 21:24:24 +1100
commit6720e9c58c3a239ff0de4be1ff2ad075a0b2c248 (patch)
treecd4dba192787a4d36fa592d25422bdc9776a1da0
parentaea414fd828964c13301191b88a56174f85fad8d (diff)
downloadqmk_firmware-6720e9c58c3a239ff0de4be1ff2ad075a0b2c248.tar.gz
qmk_firmware-6720e9c58c3a239ff0de4be1ff2ad075a0b2c248.zip
`qmk new-keyboard` - detach community layout when selecting "none of the above" (#20405)
-rw-r--r--lib/python/qmk/cli/new/keyboard.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/python/qmk/cli/new/keyboard.py b/lib/python/qmk/cli/new/keyboard.py
index 700afc96a6..37bf2923d6 100644
--- a/lib/python/qmk/cli/new/keyboard.py
+++ b/lib/python/qmk/cli/new/keyboard.py
@@ -74,6 +74,10 @@ def replace_placeholders(src, dest, tokens):
dest.write_text(content)
+def replace_string(src, token, value):
+ src.write_text(src.read_text().replace(token, value))
+
+
def augment_community_info(src, dest):
"""Splice in any additional data into info.json
"""
@@ -218,6 +222,11 @@ def new_keyboard(cli):
else:
bootloader = select_default_bootloader(mcu)
+ detach_layout = False
+ if default_layout == 'none of the above':
+ default_layout = "ortho_4x4"
+ detach_layout = True
+
tokens = { # Comment here is to force multiline formatting
'YEAR': str(date.today().year),
'KEYBOARD': kb_name,
@@ -233,10 +242,6 @@ def new_keyboard(cli):
for key, value in tokens.items():
cli.echo(f" {key.ljust(10)}: {value}")
- # TODO: detach community layout and rename to just "LAYOUT"
- if default_layout == 'none of the above':
- default_layout = "ortho_4x4"
-
# begin with making the deepest folder in the tree
keymaps_path = keyboard(kb_name) / 'keymaps/'
keymaps_path.mkdir(parents=True)
@@ -253,6 +258,11 @@ def new_keyboard(cli):
community_info = Path(COMMUNITY / f'{default_layout}/info.json')
augment_community_info(community_info, keyboard(kb_name) / 'keyboard.json')
+ # detach community layout and rename to just "LAYOUT"
+ if detach_layout:
+ replace_string(keyboard(kb_name) / 'keyboard.json', 'LAYOUT_ortho_4x4', 'LAYOUT')
+ replace_string(keymaps_path / 'default/keymap.c', 'LAYOUT_ortho_4x4', 'LAYOUT')
+
cli.log.info(f'{{fg_green}}Created a new keyboard called {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}')
cli.log.info(f"Build Command: {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.")
cli.log.info(f'Project Location: {{fg_cyan}}{QMK_FIRMWARE}/{keyboard(kb_name)}{{fg_reset}},')