From 22b213e1915a49cc8419fe0d449ca26fb372b43c Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Date: Sat, 8 Nov 2025 15:43:34 -0300 Subject: [PATCH] Add LED index map to `qmk info` cli command (#25743) --- lib/python/qmk/cli/info.py | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py index 5925b57258..26f7f0269d 100755 --- a/lib/python/qmk/cli/info.py +++ b/lib/python/qmk/cli/info.py @@ -102,6 +102,48 @@ def show_matrix(kb_info_json, title_caps=True): print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, labels)) +def show_leds(kb_info_json, title_caps=True): + """Render LED indices per key, using the keyboard's key layout geometry. + + We build a map from (row, col) -> LED index using rgb_matrix/led_matrix layout, + then label each key with its LED index. Keys without an associated LED are left blank. + """ + # Prefer rgb_matrix, fall back to led_matrix + led_feature = None + for feature in ['rgb_matrix', 'led_matrix']: + if 'layout' in kb_info_json.get(feature, {}): + led_feature = feature + break + + if not led_feature: + cli.echo('{fg_yellow}No rgb_matrix/led_matrix layout found to derive LED indices.{fg_reset}') + return + + # Build mapping from matrix position -> LED indices for faster lookup later + by_matrix = {} + for idx, led in enumerate(kb_info_json[led_feature]['layout']): + if 'matrix' in led: + led_key = tuple(led.get('matrix')) + by_matrix[led_key] = idx + + # For each keyboard layout (e.g., LAYOUT), render keys labeled with LED index (or blank) + for layout_name, layout in kb_info_json['layouts'].items(): + labels = [] + for key in layout['layout']: + led_key = tuple(key.get('matrix')) + label = str(by_matrix[led_key]) if led_key in by_matrix else '' + + labels.append(label) + + # Header + if title_caps: + cli.echo('{fg_blue}LED indices for "%s"{fg_reset}:', layout_name) + else: + cli.echo('{fg_blue}leds_%s{fg_reset}:', layout_name) + + print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, labels)) + + def print_friendly_output(kb_info_json): """Print the info.json in a friendly text format. """ @@ -169,6 +211,7 @@ def print_parsed_rules_mk(keyboard_name): @cli.argument('-km', '--keymap', help='Keymap to show info for (Optional).') @cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.') @cli.argument('-m', '--matrix', action='store_true', help='Render the layouts with matrix information.') +@cli.argument('-L', '--leds', action='store_true', help='Render the LED layout with LED indices (rgb_matrix/led_matrix).') @cli.argument('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).') @cli.argument('--ascii', action='store_true', default=not UNICODE_SUPPORT, help='Render layout box drawings in ASCII only.') @cli.argument('-r', '--rules-mk', action='store_true', help='Render the parsed values of the keyboard\'s rules.mk file.') @@ -227,5 +270,8 @@ def info(cli): if cli.config.info.matrix: show_matrix(kb_info_json, title_caps) + if cli.config.info.leds: + show_leds(kb_info_json, title_caps) + if cli.config.info.keymap: show_keymap(kb_info_json, title_caps)