aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorCarlos Eduardo2025-11-08 19:43:34 +0100
committerGitHub2025-11-08 19:43:34 +0100
commit22b213e1915a49cc8419fe0d449ca26fb372b43c (patch)
tree5930168957ef29393950ed15e1b940f65d184580 /lib
parent8522449ccfa36d19c82317e8a49e58862e366c66 (diff)
Add LED index map to `qmk info` cli command (#25743)
Diffstat (limited to 'lib')
-rwxr-xr-xlib/python/qmk/cli/info.py46
1 files changed, 46 insertions, 0 deletions
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)