diff options
Diffstat (limited to 'lib/python/qmk/cli/info.py')
-rwxr-xr-x | lib/python/qmk/cli/info.py | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py index 337b494a9..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 | ||
@@ -93,15 +89,6 @@ def print_friendly_output(kb_info_json): | |||
93 | 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()] |
94 | cli.echo('{fg_blue}Layout aliases:{fg_reset} %s' % (', '.join(aliases),)) | 90 | cli.echo('{fg_blue}Layout aliases:{fg_reset} %s' % (', '.join(aliases),)) |
95 | 91 | ||
96 | if cli.config.info.layouts: | ||
97 | show_layouts(kb_info_json, True) | ||
98 | |||
99 | if cli.config.info.matrix: | ||
100 | show_matrix(kb_info_json, True) | ||
101 | |||
102 | if cli.config_source.info.keymap and cli.config_source.info.keymap != 'config_file': | ||
103 | show_keymap(kb_info_json, True) | ||
104 | |||
105 | 92 | ||
106 | def print_text_output(kb_info_json): | 93 | def print_text_output(kb_info_json): |
107 | """Print the info.json in a plain text format. | 94 | """Print the info.json in a plain text format. |
@@ -122,6 +109,24 @@ def print_text_output(kb_info_json): | |||
122 | show_keymap(kb_info_json, False) | 109 | show_keymap(kb_info_json, False) |
123 | 110 | ||
124 | 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 | |||
125 | def print_parsed_rules_mk(keyboard_name): | 130 | def print_parsed_rules_mk(keyboard_name): |
126 | rules = rules_mk(keyboard_name) | 131 | rules = rules_mk(keyboard_name) |
127 | for k in sorted(rules.keys()): | 132 | for k in sorted(rules.keys()): |
@@ -162,10 +167,22 @@ def info(cli): | |||
162 | # Output in the requested format | 167 | # Output in the requested format |
163 | if cli.args.format == 'json': | 168 | if cli.args.format == 'json': |
164 | print(json.dumps(kb_info_json, cls=InfoJSONEncoder)) | 169 | print(json.dumps(kb_info_json, cls=InfoJSONEncoder)) |
170 | return True | ||
165 | elif cli.args.format == 'text': | 171 | elif cli.args.format == 'text': |
166 | print_text_output(kb_info_json) | 172 | print_dotted_output(kb_info_json) |
173 | title_caps = False | ||
167 | elif cli.args.format == 'friendly': | 174 | elif cli.args.format == 'friendly': |
168 | print_friendly_output(kb_info_json) | 175 | print_friendly_output(kb_info_json) |
176 | title_caps = True | ||
169 | else: | 177 | else: |
170 | cli.log.error('Unknown format: %s', cli.args.format) | 178 | cli.log.error('Unknown format: %s', cli.args.format) |
171 | 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) | ||