Skip to content

Commit

Permalink
qmk new-keyboard - detach community layout when selecting "none of …
Browse files Browse the repository at this point in the history
…the above" (qmk#20405)
  • Loading branch information
zvecr authored and whoisjordangarcia committed Jun 8, 2024
1 parent 1b7e878 commit 04e1405
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/python/qmk/cli/new/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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}},')
Expand Down

0 comments on commit 04e1405

Please sign in to comment.