Skip to content

Commit

Permalink
add the ability to show the matrix locations
Browse files Browse the repository at this point in the history
  • Loading branch information
skullydazed committed Apr 7, 2020
1 parent 2f8ab87 commit 032975f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/python/qmk/cli/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from qmk.info import info_json


ROW_LETTERS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop'
COL_LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijilmnopqrstuvwxyz'


def show_keymap(info_json, title_caps=True):
"""Render the keymap in ascii art.
"""
Expand All @@ -35,9 +39,32 @@ def show_keymap(info_json, title_caps=True):
print(render_layout(info_json['layouts'][layout_name]['layout'], layer))


def show_matrix(info_json, title_caps=True):
"""Render the layout with matrix labels in ascii art.
"""
for layout_name, layout in info_json['layouts'].items():
# Build our label list
labels = []
for key in layout['layout']:
if key['matrix']:
row = ROW_LETTERS[key['matrix'][0]]
col = COL_LETTERS[key['matrix'][1]]

labels.append(row + col)

# Print the header
if title_caps:
cli.echo('{fg_blue}Matrix for "%s"{fg_reset}:', layout_name)
else:
cli.echo('{fg_blue}matrix_%s{fg_reset}:', layout_name)

print(render_layout(info_json['layouts'][layout_name]['layout'], labels))


@cli.argument('-kb', '--keyboard', help='Keyboard to show info for.')
@cli.argument('-km', '--keymap', help='Show the layers for a JSON keymap too.')
@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('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).')
@cli.subcommand('Keyboard information.')
@automagic_keyboard
Expand Down Expand Up @@ -70,6 +97,9 @@ def info(cli):
cli.echo('{fg_cyan}%s{fg_reset}:', layout_name)
print(layout_art) # Avoid passing dirty data to cli.echo()

if cli.config.info.matrix:
show_matrix(kb_info_json, False)

if cli.config_source.info.keymap != 'config_file':
show_keymap(kb_info_json, False)

Expand All @@ -94,6 +124,9 @@ def info(cli):
cli.echo('{fg_cyan}%s{fg_reset}:', layout_name)
print(layout_art) # Avoid passing dirty data to cli.echo()

if cli.config.info.matrix:
show_matrix(kb_info_json, True)

if cli.config_source.info.keymap != 'config_file':
show_keymap(kb_info_json, True)

Expand Down

0 comments on commit 032975f

Please sign in to comment.