diff options
Diffstat (limited to 'lib/python/qmk/cli/info.py')
| -rwxr-xr-x | lib/python/qmk/cli/info.py | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py index 0d08d242c..3131d4b53 100755 --- a/lib/python/qmk/cli/info.py +++ b/lib/python/qmk/cli/info.py | |||
| @@ -24,19 +24,15 @@ def show_keymap(kb_info_json, title_caps=True): | |||
| 24 | keymap_path = locate_keymap(cli.config.info.keyboard, cli.config.info.keymap) | 24 | keymap_path = locate_keymap(cli.config.info.keyboard, cli.config.info.keymap) |
| 25 | 25 | ||
| 26 | if keymap_path and keymap_path.suffix == '.json': | 26 | if keymap_path and keymap_path.suffix == '.json': |
| 27 | if title_caps: | ||
| 28 | cli.echo('{fg_blue}Keymap "%s"{fg_reset}:', cli.config.info.keymap) | ||
| 29 | else: | ||
| 30 | cli.echo('{fg_blue}keymap_%s{fg_reset}:', cli.config.info.keymap) | ||
| 31 | |||
| 32 | keymap_data = json.load(keymap_path.open(encoding='utf-8')) | 27 | keymap_data = json.load(keymap_path.open(encoding='utf-8')) |
| 33 | layout_name = keymap_data['layout'] | 28 | layout_name = keymap_data['layout'] |
| 29 | layout_name = kb_info_json.get('layout_aliases', {}).get(layout_name, layout_name) # Resolve alias names | ||
| 34 | 30 | ||
| 35 | for layer_num, layer in enumerate(keymap_data['layers']): | 31 | for layer_num, layer in enumerate(keymap_data['layers']): |
| 36 | if title_caps: | 32 | if title_caps: |
| 37 | cli.echo('{fg_cyan}Layer %s{fg_reset}:', layer_num) | 33 | cli.echo('{fg_cyan}Keymap %s Layer %s{fg_reset}:', cli.config.info.keymap, layer_num) |
| 38 | else: | 34 | else: |
| 39 | cli.echo('{fg_cyan}layer_%s{fg_reset}:', layer_num) | 35 | cli.echo('{fg_cyan}keymap.%s.layer.%s{fg_reset}:', cli.config.info.keymap, layer_num) |
| 40 | 36 | ||
| 41 | print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, layer)) | 37 | print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, layer)) |
| 42 | 38 | ||
| @@ -45,7 +41,7 @@ def show_layouts(kb_info_json, title_caps=True): | |||
| 45 | """Render the layouts with info.json labels. | 41 | """Render the layouts with info.json labels. |
| 46 | """ | 42 | """ |
| 47 | for layout_name, layout_art in render_layouts(kb_info_json, cli.config.info.ascii).items(): | 43 | for layout_name, layout_art in render_layouts(kb_info_json, cli.config.info.ascii).items(): |
| 48 | title = layout_name.title() if title_caps else layout_name | 44 | title = f'Layout {layout_name.title()}' if title_caps else f'layouts.{layout_name}' |
| 49 | cli.echo('{fg_cyan}%s{fg_reset}:', title) | 45 | cli.echo('{fg_cyan}%s{fg_reset}:', title) |
| 50 | print(layout_art) # Avoid passing dirty data to cli.echo() | 46 | print(layout_art) # Avoid passing dirty data to cli.echo() |
| 51 | 47 | ||
| @@ -87,23 +83,12 @@ def print_friendly_output(kb_info_json): | |||
| 87 | cli.echo('{fg_blue}Maintainer{fg_reset}: %s', kb_info_json['maintainer']) | 83 | cli.echo('{fg_blue}Maintainer{fg_reset}: %s', kb_info_json['maintainer']) |
| 88 | cli.echo('{fg_blue}Keyboard Folder{fg_reset}: %s', kb_info_json.get('keyboard_folder', 'Unknown')) | 84 | cli.echo('{fg_blue}Keyboard Folder{fg_reset}: %s', kb_info_json.get('keyboard_folder', 'Unknown')) |
| 89 | cli.echo('{fg_blue}Layouts{fg_reset}: %s', ', '.join(sorted(kb_info_json['layouts'].keys()))) | 85 | cli.echo('{fg_blue}Layouts{fg_reset}: %s', ', '.join(sorted(kb_info_json['layouts'].keys()))) |
| 90 | if 'width' in kb_info_json and 'height' in kb_info_json: | ||
| 91 | cli.echo('{fg_blue}Size{fg_reset}: %s x %s' % (kb_info_json['width'], kb_info_json['height'])) | ||
| 92 | cli.echo('{fg_blue}Processor{fg_reset}: %s', kb_info_json.get('processor', 'Unknown')) | 86 | cli.echo('{fg_blue}Processor{fg_reset}: %s', kb_info_json.get('processor', 'Unknown')) |
| 93 | cli.echo('{fg_blue}Bootloader{fg_reset}: %s', kb_info_json.get('bootloader', 'Unknown')) | 87 | cli.echo('{fg_blue}Bootloader{fg_reset}: %s', kb_info_json.get('bootloader', 'Unknown')) |
| 94 | if 'layout_aliases' in kb_info_json: | 88 | if 'layout_aliases' in kb_info_json: |
| 95 | aliases = [f'{key}={value}' for key, value in kb_info_json['layout_aliases'].items()] | 89 | aliases = [f'{key}={value}' for key, value in kb_info_json['layout_aliases'].items()] |
| 96 | cli.echo('{fg_blue}Layout aliases:{fg_reset} %s' % (', '.join(aliases),)) | 90 | cli.echo('{fg_blue}Layout aliases:{fg_reset} %s' % (', '.join(aliases),)) |
| 97 | 91 | ||
| 98 | if cli.config.info.layouts: | ||
| 99 | show_layouts(kb_info_json, True) | ||
| 100 | |||
| 101 | if cli.config.info.matrix: | ||
| 102 | show_matrix(kb_info_json, True) | ||
| 103 | |||
| 104 | if cli.config_source.info.keymap and cli.config_source.info.keymap != 'config_file': | ||
| 105 | show_keymap(kb_info_json, True) | ||
| 106 | |||
| 107 | 92 | ||
| 108 | def print_text_output(kb_info_json): | 93 | def print_text_output(kb_info_json): |
| 109 | """Print the info.json in a plain text format. | 94 | """Print the info.json in a plain text format. |
| @@ -124,6 +109,24 @@ def print_text_output(kb_info_json): | |||
| 124 | show_keymap(kb_info_json, False) | 109 | show_keymap(kb_info_json, False) |
| 125 | 110 | ||
| 126 | 111 | ||
| 112 | def print_dotted_output(kb_info_json, prefix=''): | ||
| 113 | """Print the info.json in a plain text format with dot-joined keys. | ||
| 114 | """ | ||
| 115 | for key in sorted(kb_info_json): | ||
| 116 | new_prefix = f'{prefix}.{key}' if prefix else key | ||
| 117 | |||
| 118 | if key in ['parse_errors', 'parse_warnings']: | ||
| 119 | continue | ||
| 120 | elif key == 'layouts' and prefix == '': | ||
| 121 | cli.echo('{fg_blue}layouts{fg_reset}: %s', ', '.join(sorted(kb_info_json['layouts'].keys()))) | ||
| 122 | elif isinstance(kb_info_json[key], dict): | ||
| 123 | print_dotted_output(kb_info_json[key], new_prefix) | ||
| 124 | elif isinstance(kb_info_json[key], list): | ||
| 125 | cli.echo('{fg_blue}%s{fg_reset}: %s', new_prefix, ', '.join(map(str, sorted(kb_info_json[key])))) | ||
| 126 | else: | ||
| 127 | cli.echo('{fg_blue}%s{fg_reset}: %s', new_prefix, kb_info_json[key]) | ||
| 128 | |||
| 129 | |||
| 127 | def print_parsed_rules_mk(keyboard_name): | 130 | def print_parsed_rules_mk(keyboard_name): |
| 128 | rules = rules_mk(keyboard_name) | 131 | rules = rules_mk(keyboard_name) |
| 129 | for k in sorted(rules.keys()): | 132 | for k in sorted(rules.keys()): |
| @@ -164,10 +167,22 @@ def info(cli): | |||
| 164 | # Output in the requested format | 167 | # Output in the requested format |
| 165 | if cli.args.format == 'json': | 168 | if cli.args.format == 'json': |
| 166 | print(json.dumps(kb_info_json, cls=InfoJSONEncoder)) | 169 | print(json.dumps(kb_info_json, cls=InfoJSONEncoder)) |
| 170 | return True | ||
| 167 | elif cli.args.format == 'text': | 171 | elif cli.args.format == 'text': |
| 168 | print_text_output(kb_info_json) | 172 | print_dotted_output(kb_info_json) |
| 173 | title_caps = False | ||
| 169 | elif cli.args.format == 'friendly': | 174 | elif cli.args.format == 'friendly': |
| 170 | print_friendly_output(kb_info_json) | 175 | print_friendly_output(kb_info_json) |
| 176 | title_caps = True | ||
| 171 | else: | 177 | else: |
| 172 | cli.log.error('Unknown format: %s', cli.args.format) | 178 | cli.log.error('Unknown format: %s', cli.args.format) |
| 173 | return False | 179 | return False |
| 180 | |||
| 181 | if cli.config.info.layouts: | ||
| 182 | show_layouts(kb_info_json, title_caps) | ||
| 183 | |||
| 184 | if cli.config.info.matrix: | ||
| 185 | show_matrix(kb_info_json, title_caps) | ||
| 186 | |||
| 187 | if cli.config_source.info.keymap and cli.config_source.info.keymap != 'config_file': | ||
| 188 | show_keymap(kb_info_json, title_caps) | ||
