mirror of
https://github.com/qmk/qmk_firmware.git
synced 2026-08-04 08:21:08 -04:00
Merge remote-tracking branch 'origin/develop' into xap
This commit is contained in:
@@ -8,7 +8,7 @@ from pathlib import Path
|
||||
from dotty_dict import dotty
|
||||
|
||||
from milc import cli
|
||||
from milc.questions import choice, question
|
||||
from milc.questions import choice, question, yesno
|
||||
|
||||
from qmk.git import git_get_username
|
||||
from qmk.json_schema import load_jsonschema
|
||||
@@ -131,60 +131,70 @@ def _question(*args, **kwargs):
|
||||
return ret
|
||||
|
||||
|
||||
def prompt_keyboard():
|
||||
prompt = """{fg_yellow}Name Your Keyboard Project{style_reset_all}
|
||||
For more infomation, see:
|
||||
https://docs.qmk.fm/hardware_keyboard_guidelines#naming-your-keyboard-project
|
||||
def prompt_heading_subheading(heading, subheading):
|
||||
cli.log.info(f"{{fg_yellow}}{heading}{{style_reset_all}}")
|
||||
cli.log.info(subheading)
|
||||
|
||||
Keyboard Name? """
|
||||
|
||||
def prompt_keyboard():
|
||||
prompt_heading_subheading("Name Your Keyboard Project", """For more information, see:
|
||||
https://docs.qmk.fm/hardware_keyboard_guidelines#naming-your-keyboard-project""")
|
||||
|
||||
errmsg = 'Keyboard already exists! Please choose a different name:'
|
||||
|
||||
return _question(prompt, reprompt=errmsg, validate=lambda x: not keyboard(x).exists())
|
||||
return _question("Keyboard Name?", reprompt=errmsg, validate=lambda x: not keyboard(x).exists())
|
||||
|
||||
|
||||
def prompt_user():
|
||||
prompt = """
|
||||
{fg_yellow}Attribution{style_reset_all}
|
||||
Used for maintainer, copyright, etc
|
||||
prompt_heading_subheading("Attribution", "Used for maintainer, copyright, etc.")
|
||||
|
||||
Your GitHub Username? """
|
||||
return question(prompt, default=git_get_username())
|
||||
return question("Your GitHub Username?", default=git_get_username())
|
||||
|
||||
|
||||
def prompt_name(def_name):
|
||||
prompt = """
|
||||
{fg_yellow}More Attribution{style_reset_all}
|
||||
Used for maintainer, copyright, etc
|
||||
prompt_heading_subheading("More Attribution", "Used for maintainer, copyright, etc.")
|
||||
|
||||
Your Real Name? """
|
||||
return question(prompt, default=def_name)
|
||||
return question("Your Real Name?", default=def_name)
|
||||
|
||||
|
||||
def prompt_layout():
|
||||
prompt = """
|
||||
{fg_yellow}Pick Base Layout{style_reset_all}
|
||||
As a starting point, one of the common layouts can be used to bootstrap the process
|
||||
prompt_heading_subheading("Pick Base Layout", """As a starting point, one of the common layouts can be used to
|
||||
bootstrap the process""")
|
||||
|
||||
Default Layout? """
|
||||
# avoid overwhelming user - remove some?
|
||||
filtered_layouts = [x for x in available_layouts if not any(xs in x for xs in ['_split', '_blocker', '_tsangan', '_f13'])]
|
||||
filtered_layouts.append("none of the above")
|
||||
|
||||
return choice(prompt, filtered_layouts, default=len(filtered_layouts) - 1)
|
||||
return choice("Default Layout?", filtered_layouts, default=len(filtered_layouts) - 1)
|
||||
|
||||
|
||||
def prompt_mcu_type():
|
||||
prompt_heading_subheading(
|
||||
"What Powers Your Project", """Is your board using a separate development board, such as a Pro Micro,
|
||||
or is the microcontroller integrated onto the PCB?
|
||||
|
||||
For more information, see:
|
||||
https://docs.qmk.fm/compatible_microcontrollers"""
|
||||
)
|
||||
|
||||
return yesno("Using a Development Board?")
|
||||
|
||||
|
||||
def prompt_dev_board():
|
||||
prompt_heading_subheading("Select Development Board", """For more information, see:
|
||||
https://docs.qmk.fm/compatible_microcontrollers""")
|
||||
|
||||
return choice("Development Board?", dev_boards, default=dev_boards.index("promicro"))
|
||||
|
||||
|
||||
def prompt_mcu():
|
||||
prompt = """
|
||||
{fg_yellow}What Powers Your Project{style_reset_all}
|
||||
For more infomation, see:
|
||||
https://docs.qmk.fm/#/compatible_microcontrollers
|
||||
prompt_heading_subheading("Select Microcontroller", """For more information, see:
|
||||
https://docs.qmk.fm/compatible_microcontrollers""")
|
||||
|
||||
MCU? """
|
||||
# remove any options strictly used for compatibility
|
||||
filtered_mcu = [x for x in (dev_boards + mcu_types) if not any(xs in x for xs in ['cortex', 'unknown'])]
|
||||
filtered_mcu = [x for x in mcu_types if not any(xs in x for xs in ['cortex', 'unknown'])]
|
||||
|
||||
return choice(prompt, filtered_mcu, default=filtered_mcu.index("atmega32u4"))
|
||||
return choice("Microcontroller?", filtered_mcu, default=filtered_mcu.index("atmega32u4"))
|
||||
|
||||
|
||||
@cli.argument('-kb', '--keyboard', help='Specify the name for the new keyboard directory', arg_only=True, type=keyboard_name)
|
||||
@@ -211,7 +221,11 @@ def new_keyboard(cli):
|
||||
user_name = cli.config.new_keyboard.name if cli.config.new_keyboard.name else prompt_user()
|
||||
real_name = cli.args.realname or cli.config.new_keyboard.name if cli.args.realname or cli.config.new_keyboard.name else prompt_name(user_name)
|
||||
default_layout = cli.args.layout if cli.args.layout else prompt_layout()
|
||||
mcu = cli.args.type if cli.args.type else prompt_mcu()
|
||||
|
||||
if cli.args.type:
|
||||
mcu = cli.args.type
|
||||
else:
|
||||
mcu = prompt_dev_board() if prompt_mcu_type() else prompt_mcu()
|
||||
|
||||
config = {}
|
||||
if mcu in dev_boards:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""This script automates the copying of the default keymap into your own keymap.
|
||||
"""
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from milc import cli
|
||||
@@ -13,6 +14,13 @@ from qmk.keyboard import keyboard_completer, keyboard_folder
|
||||
from qmk.userspace import UserspaceDefs
|
||||
|
||||
|
||||
def validate_keymap_name(name):
|
||||
"""Returns True if the given keymap name contains only a-z, 0-9 and underscore characters.
|
||||
"""
|
||||
regex = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_]+$')
|
||||
return bool(regex.match(name))
|
||||
|
||||
|
||||
def prompt_keyboard():
|
||||
prompt = """{fg_yellow}Select Keyboard{style_reset_all}
|
||||
If you`re unsure you can view a full list of supported keyboards with {fg_yellow}qmk list-keyboards{style_reset_all}.
|
||||
@@ -60,6 +68,10 @@ def new_keymap(cli):
|
||||
cli.log.error(f'Default keymap {{fg_cyan}}{keymap_path_default}{{fg_reset}} does not exist!')
|
||||
return False
|
||||
|
||||
if not validate_keymap_name(user_name):
|
||||
cli.log.error('Keymap names must contain only {fg_cyan}a-z{fg_reset}, {fg_cyan}0-9{fg_reset} and {fg_cyan}_{fg_reset}! Please choose a different name.')
|
||||
return False
|
||||
|
||||
if keymap_path_new.exists():
|
||||
cli.log.error(f'Keymap {{fg_cyan}}{user_name}{{fg_reset}} already exists! Please choose a different name.')
|
||||
return False
|
||||
|
||||
@@ -29,6 +29,7 @@ def _convert_macros(via_macros):
|
||||
if len(via_macros) == 0:
|
||||
return list()
|
||||
split_regex = re.compile(r'(}\,)|(\,{)')
|
||||
macro_group_regex = re.compile(r'({.+?})')
|
||||
macros = list()
|
||||
for via_macro in via_macros:
|
||||
# Split VIA macro to its elements
|
||||
@@ -38,13 +39,28 @@ def _convert_macros(via_macros):
|
||||
macro_data = list()
|
||||
for m in macro:
|
||||
if '{' in m or '}' in m:
|
||||
# Found keycode(s)
|
||||
keycodes = m.split(',')
|
||||
# Remove whitespaces and curly braces from around keycodes
|
||||
keycodes = list(map(lambda s: s.strip(' {}'), keycodes))
|
||||
# Remove the KC prefix
|
||||
keycodes = list(map(lambda s: s.replace('KC_', ''), keycodes))
|
||||
macro_data.append({"action": "tap", "keycodes": keycodes})
|
||||
# Split macro groups
|
||||
macro_groups = macro_group_regex.findall(m)
|
||||
for macro_group in macro_groups:
|
||||
# Remove whitespaces and curly braces from around group
|
||||
macro_group = macro_group.strip(' {}')
|
||||
|
||||
macro_action = 'tap'
|
||||
macro_keycodes = []
|
||||
|
||||
if macro_group[0] == '+':
|
||||
macro_action = 'down'
|
||||
macro_keycodes.append(macro_group[1:])
|
||||
elif macro_group[0] == '-':
|
||||
macro_action = 'up'
|
||||
macro_keycodes.append(macro_group[1:])
|
||||
else:
|
||||
macro_keycodes.extend(macro_group.split(',') if ',' in macro_group else [macro_group])
|
||||
|
||||
# Remove the KC prefixes
|
||||
macro_keycodes = list(map(lambda s: s.replace('KC_', ''), macro_keycodes))
|
||||
|
||||
macro_data.append({"action": macro_action, "keycodes": macro_keycodes})
|
||||
else:
|
||||
# Found text
|
||||
macro_data.append(m)
|
||||
@@ -54,13 +70,13 @@ def _convert_macros(via_macros):
|
||||
|
||||
|
||||
def _fix_macro_keys(keymap_data):
|
||||
macro_no = re.compile(r'MACRO0?([0-9]{1,2})')
|
||||
macro_no = re.compile(r'MACRO0?\(([0-9]{1,2})\)')
|
||||
for i in range(0, len(keymap_data)):
|
||||
for j in range(0, len(keymap_data[i])):
|
||||
kc = keymap_data[i][j]
|
||||
m = macro_no.match(kc)
|
||||
if m:
|
||||
keymap_data[i][j] = f'MACRO_{m.group(1)}'
|
||||
keymap_data[i][j] = f'MC_{m.group(1)}'
|
||||
return keymap_data
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user