diff options
| author | QMK Bot <hello@qmk.fm> | 2025-11-08 18:44:13 +0000 |
|---|---|---|
| committer | QMK Bot <hello@qmk.fm> | 2025-11-08 18:44:13 +0000 |
| commit | cf05c7d1e4bd93ccd184e3a78eaba9f2eeb5976e (patch) | |
| tree | 89d311ee41e4ee4b15730e6a9c8a924c0b8fb2a8 /lib/python | |
| parent | 4b393a1ff58ae51977c82b2b9ece65b21b0943c6 (diff) | |
| parent | 22b213e1915a49cc8419fe0d449ca26fb372b43c (diff) | |
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'lib/python')
| -rwxr-xr-x | lib/python/qmk/cli/info.py | 46 |
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): | |||
| 102 | print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, labels)) | 102 | print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, labels)) |
| 103 | 103 | ||
| 104 | 104 | ||
| 105 | def show_leds(kb_info_json, title_caps=True): | ||
| 106 | """Render LED indices per key, using the keyboard's key layout geometry. | ||
| 107 | |||
| 108 | We build a map from (row, col) -> LED index using rgb_matrix/led_matrix layout, | ||
| 109 | then label each key with its LED index. Keys without an associated LED are left blank. | ||
| 110 | """ | ||
| 111 | # Prefer rgb_matrix, fall back to led_matrix | ||
| 112 | led_feature = None | ||
| 113 | for feature in ['rgb_matrix', 'led_matrix']: | ||
| 114 | if 'layout' in kb_info_json.get(feature, {}): | ||
| 115 | led_feature = feature | ||
| 116 | break | ||
| 117 | |||
| 118 | if not led_feature: | ||
| 119 | cli.echo('{fg_yellow}No rgb_matrix/led_matrix layout found to derive LED indices.{fg_reset}') | ||
| 120 | return | ||
| 121 | |||
| 122 | # Build mapping from matrix position -> LED indices for faster lookup later | ||
| 123 | by_matrix = {} | ||
| 124 | for idx, led in enumerate(kb_info_json[led_feature]['layout']): | ||
| 125 | if 'matrix' in led: | ||
| 126 | led_key = tuple(led.get('matrix')) | ||
| 127 | by_matrix[led_key] = idx | ||
| 128 | |||
| 129 | # For each keyboard layout (e.g., LAYOUT), render keys labeled with LED index (or blank) | ||
| 130 | for layout_name, layout in kb_info_json['layouts'].items(): | ||
| 131 | labels = [] | ||
| 132 | for key in layout['layout']: | ||
| 133 | led_key = tuple(key.get('matrix')) | ||
| 134 | label = str(by_matrix[led_key]) if led_key in by_matrix else '' | ||
| 135 | |||
| 136 | labels.append(label) | ||
| 137 | |||
| 138 | # Header | ||
| 139 | if title_caps: | ||
| 140 | cli.echo('{fg_blue}LED indices for "%s"{fg_reset}:', layout_name) | ||
| 141 | else: | ||
| 142 | cli.echo('{fg_blue}leds_%s{fg_reset}:', layout_name) | ||
| 143 | |||
| 144 | print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, labels)) | ||
| 145 | |||
| 146 | |||
| 105 | def print_friendly_output(kb_info_json): | 147 | def print_friendly_output(kb_info_json): |
| 106 | """Print the info.json in a friendly text format. | 148 | """Print the info.json in a friendly text format. |
| 107 | """ | 149 | """ |
| @@ -169,6 +211,7 @@ def print_parsed_rules_mk(keyboard_name): | |||
| 169 | @cli.argument('-km', '--keymap', help='Keymap to show info for (Optional).') | 211 | @cli.argument('-km', '--keymap', help='Keymap to show info for (Optional).') |
| 170 | @cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.') | 212 | @cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.') |
| 171 | @cli.argument('-m', '--matrix', action='store_true', help='Render the layouts with matrix information.') | 213 | @cli.argument('-m', '--matrix', action='store_true', help='Render the layouts with matrix information.') |
| 214 | @cli.argument('-L', '--leds', action='store_true', help='Render the LED layout with LED indices (rgb_matrix/led_matrix).') | ||
| 172 | @cli.argument('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).') | 215 | @cli.argument('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).') |
| 173 | @cli.argument('--ascii', action='store_true', default=not UNICODE_SUPPORT, help='Render layout box drawings in ASCII only.') | 216 | @cli.argument('--ascii', action='store_true', default=not UNICODE_SUPPORT, help='Render layout box drawings in ASCII only.') |
| 174 | @cli.argument('-r', '--rules-mk', action='store_true', help='Render the parsed values of the keyboard\'s rules.mk file.') | 217 | @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): | |||
| 227 | if cli.config.info.matrix: | 270 | if cli.config.info.matrix: |
| 228 | show_matrix(kb_info_json, title_caps) | 271 | show_matrix(kb_info_json, title_caps) |
| 229 | 272 | ||
| 273 | if cli.config.info.leds: | ||
| 274 | show_leds(kb_info_json, title_caps) | ||
| 275 | |||
| 230 | if cli.config.info.keymap: | 276 | if cli.config.info.keymap: |
| 231 | show_keymap(kb_info_json, title_caps) | 277 | show_keymap(kb_info_json, title_caps) |
