summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/cli/info.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli/info.py')
-rwxr-xr-xlib/python/qmk/cli/info.py55
1 files changed, 35 insertions, 20 deletions
diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py
index 0d08d242cd..3131d4b53f 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):
keymap_path = locate_keymap(cli.config.info.keyboard, cli.config.info.keymap)
if keymap_path and keymap_path.suffix == '.json':
- if title_caps:
- cli.echo('{fg_blue}Keymap "%s"{fg_reset}:', cli.config.info.keymap)
- else:
- cli.echo('{fg_blue}keymap_%s{fg_reset}:', cli.config.info.keymap)
-
keymap_data = json.load(keymap_path.open(encoding='utf-8'))
layout_name = keymap_data['layout']
+ layout_name = kb_info_json.get('layout_aliases', {}).get(layout_name, layout_name) # Resolve alias names
for layer_num, layer in enumerate(keymap_data['layers']):
if title_caps:
- cli.echo('{fg_cyan}Layer %s{fg_reset}:', layer_num)
+ cli.echo('{fg_cyan}Keymap %s Layer %s{fg_reset}:', cli.config.info.keymap, layer_num)
else:
- cli.echo('{fg_cyan}layer_%s{fg_reset}:', layer_num)
+ cli.echo('{fg_cyan}keymap.%s.layer.%s{fg_reset}:', cli.config.info.keymap, layer_num)
print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, layer))
@@ -45,7 +41,7 @@ def show_layouts(kb_info_json, title_caps=True):
"""Render the layouts with info.json labels.
"""
for layout_name, layout_art in render_layouts(kb_info_json, cli.config.info.ascii).items():
- title = layout_name.title() if title_caps else layout_name
+ title = f'Layout {layout_name.title()}' if title_caps else f'layouts.{layout_name}'
cli.echo('{fg_cyan}%s{fg_reset}:', title)
print(layout_art) # Avoid passing dirty data to cli.echo()
@@ -87,23 +83,12 @@ def print_friendly_output(kb_info_json):
cli.echo('{fg_blue}Maintainer{fg_reset}: %s', kb_info_json['maintainer'])
cli.echo('{fg_blue}Keyboard Folder{fg_reset}: %s', kb_info_json.get('keyboard_folder', 'Unknown'))
cli.echo('{fg_blue}Layouts{fg_reset}: %s', ', '.join(sorted(kb_info_json['layouts'].keys())))
- if 'width' in kb_info_json and 'height' in kb_info_json:
- cli.echo('{fg_blue}Size{fg_reset}: %s x %s' % (kb_info_json['width'], kb_info_json['height']))
cli.echo('{fg_blue}Processor{fg_reset}: %s', kb_info_json.get('processor', 'Unknown'))
cli.echo('{fg_blue}Bootloader{fg_reset}: %s', kb_info_json.get('bootloader', 'Unknown'))
if 'layout_aliases' in kb_info_json:
aliases = [f'{key}={value}' for key, value in kb_info_json['layout_aliases'].items()]
cli.echo('{fg_blue}Layout aliases:{fg_reset} %s' % (', '.join(aliases),))
- if cli.config.info.layouts:
- show_layouts(kb_info_json, True)
-
- if cli.config.info.matrix:
- show_matrix(kb_info_json, True)
-
- if cli.config_source.info.keymap and cli.config_source.info.keymap != 'config_file':
- show_keymap(kb_info_json, True)
-
def print_text_output(kb_info_json):
"""Print the info.json in a plain text format.
@@ -124,6 +109,24 @@ def print_text_output(kb_info_json):
show_keymap(kb_info_json, False)
+def print_dotted_output(kb_info_json, prefix=''):
+ """Print the info.json in a plain text format with dot-joined keys.
+ """
+ for key in sorted(kb_info_json):
+ new_prefix = f'{prefix}.{key}' if prefix else key
+
+ if key in ['parse_errors', 'parse_warnings']:
+ continue
+ elif key == 'layouts' and prefix == '':
+ cli.echo('{fg_blue}layouts{fg_reset}: %s', ', '.join(sorted(kb_info_json['layouts'].keys())))
+ elif isinstance(kb_info_json[key], dict):
+ print_dotted_output(kb_info_json[key], new_prefix)
+ elif isinstance(kb_info_json[key], list):
+ cli.echo('{fg_blue}%s{fg_reset}: %s', new_prefix, ', '.join(map(str, sorted(kb_info_json[key]))))
+ else:
+ cli.echo('{fg_blue}%s{fg_reset}: %s', new_prefix, kb_info_json[key])
+
+
def print_parsed_rules_mk(keyboard_name):
rules = rules_mk(keyboard_name)
for k in sorted(rules.keys()):
@@ -164,10 +167,22 @@ def info(cli):
# Output in the requested format
if cli.args.format == 'json':
print(json.dumps(kb_info_json, cls=InfoJSONEncoder))
+ return True
elif cli.args.format == 'text':
- print_text_output(kb_info_json)
+ print_dotted_output(kb_info_json)
+ title_caps = False
elif cli.args.format == 'friendly':
print_friendly_output(kb_info_json)
+ title_caps = True
else:
cli.log.error('Unknown format: %s', cli.args.format)
return False
+
+ if cli.config.info.layouts:
+ show_layouts(kb_info_json, title_caps)
+
+ if cli.config.info.matrix:
+ show_matrix(kb_info_json, title_caps)
+
+ if cli.config_source.info.keymap and cli.config_source.info.keymap != 'config_file':
+ show_keymap(kb_info_json, title_caps)