From 6720e9c58c3a239ff0de4be1ff2ad075a0b2c248 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Thu, 14 Mar 2024 10:24:24 +0000 Subject: [PATCH] `qmk new-keyboard` - detach community layout when selecting "none of the above" (#20405) --- lib/python/qmk/cli/new/keyboard.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/python/qmk/cli/new/keyboard.py b/lib/python/qmk/cli/new/keyboard.py index 700afc96a62..37bf2923d63 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}},')