yskoht / keymapviz Goto Github PK
View Code? Open in Web Editor NEWkeymap.c visualizer
License: MIT License
keymap.c visualizer
License: MIT License
deleting, posted in wrong repo
I'm unable to render art if the keymap.c
uses Drashna's wrapper, for example this keymap.c.
I tried a bunch of random things like putting macro definitions inside a config file:
[legends]
___________________EMPTY___________________ = XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
_________________QWERTY_L1_________________ = "KC_Q, KC_W, KC_E, KC_R, KC_T"
_________________QWERTY_L2_________________ = KC_A, KC_S, KC_D, KC_F, KC_G
_________________QWERTY_L3_________________ = KC_Z, KC_X, KC_C, KC_V, KC_B
Anyway to support this? Since this wrapper is also common to use.
Currently, adding keymapviz support for a keyboard requires a considerable amount of manual effort; This is not scalable to QMK's 2k+ boards.
An "easy" way to extend keymapviz's support from 16 boards to ~2k keyboards would be to take inspiration from qmk info -m
.
To give an example, qmk info --matrix --keyboard merge/um70
reads qmk_firmware/keyboards/merge/um70/info.json
to determine how to draw the layout diagram (this is also what the online QMK configurator uses to draw the layout)
❯ qmk info -m -kb merge/um70
Keyboard Name: UM-70
Manufacturer: Merge
Website: https://mergedesign.store/um-70
Maintainer: duoshock
Keyboard Folder: merge/um70
Layouts: LAYOUT_lspace_2u_bksp, LAYOUT_lspace_split_bksp, LAYOUT_rspace_2u_bksp, LAYOUT_rspace_split_bksp
Processor: atmega32u4
Bootloader: atmel-dfu
Matrix for "LAYOUT_rspace_split_bksp":
┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐
│0A││0B││0C││0D││0E││0F││0G│ │5A││5B││5C││5D││5E││5F││5G││5H│ │7H│
└──┘└──┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└──┘└──┘└──┘ └──┘
┌────┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌────┐ ┌──┐
│1A ││1B││1C││1D││1E││1F│ │6A││6B││6C││6D││6E││6F││6G││6H │ │8H│
└────┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└──┘└──┘└────┘ └──┘
┌──┐ ┌─────┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌───────┐ ┌──┐
│4F│ │2A ││2B││2C││2D││2E││2F│ │7A││7B││7C││7D││7E││7F││7G │ │9H│
└──┘ └─────┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└──┘└───────┘ └──┘
┌──┐ ┌───────┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌─────┐
│4G│ │3A ││3B││3C││3D││3E││3F│ │8A││8B││8C││8D││8E││8F │ ┌──┐
└──┘ └───────┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└─────┘ │8G│
┌──┐ ┌───┐┌───┐┌───┐┌───┐┌───────┐ ┌─────────┐┌────┐┌────┐ └──┘
│4H│ │4A ││4B ││4C ││4D ││4E │ │9A ││9B ││9C │ ┌──┐┌──┐┌──┐
└──┘ └───┘└───┘└───┘└───┘└───────┘ └─────────┘└────┘└────┘ │9D││9E││9F│
└──┘└──┘└──┘
Matrix for "LAYOUT_rspace_2u_bksp":
┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──────┐ ┌──┐
│0A││0B││0C││0D││0E││0F││0G│ │5A││5B││5C││5D││5E││5F││5H │ │7H│
└──┘└──┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└──┘└──────┘ └──┘
┌────┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌────┐ ┌──┐
│1A ││1B││1C││1D││1E││1F│ │6A││6B││6C││6D││6E││6F││6G││6H │ │8H│
└────┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└──┘└──┘└────┘ └──┘
┌──┐ ┌─────┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌───────┐ ┌──┐
│4F│ │2A ││2B││2C││2D││2E││2F│ │7A││7B││7C││7D││7E││7F││7G │ │9H│
└──┘ └─────┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└──┘└───────┘ └──┘
┌──┐ ┌───────┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌─────┐
│4G│ │3A ││3B││3C││3D││3E││3F│ │8A││8B││8C││8D││8E││8F │ ┌──┐
└──┘ └───────┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└─────┘ │8G│
┌──┐ ┌───┐┌───┐┌───┐┌───┐┌───────┐ ┌─────────┐┌────┐┌────┐ └──┘
│4H│ │4A ││4B ││4C ││4D ││4E │ │9A ││9B ││9C │ ┌──┐┌──┐┌──┐
└──┘ └───┘└───┘└───┘└───┘└───────┘ └─────────┘└────┘└────┘ │9D││9E││9F│
└──┘└──┘└──┘
Matrix for "LAYOUT_lspace_2u_bksp":
┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──────┐ ┌──┐
│0A││0B││0C││0D││0E││0F││0G│ │5A││5B││5C││5D││5E││5F││5H │ │7H│
└──┘└──┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└──┘└──────┘ └──┘
┌────┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌────┐ ┌──┐
│1A ││1B││1C││1D││1E││1F│ │6A││6B││6C││6D││6E││6F││6G││6H │ │8H│
└────┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└──┘└──┘└────┘ └──┘
┌──┐ ┌─────┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌───────┐ ┌──┐
│4F│ │2A ││2B││2C││2D││2E││2F│ │7A││7B││7C││7D││7E││7F││7G │ │9H│
└──┘ └─────┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└──┘└───────┘ └──┘
┌──┐ ┌───────┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌─────┐
│4G│ │3A ││3B││3C││3D││3E││3F│ │8A││8B││8C││8D││8E││8F │ ┌──┐
└──┘ └───────┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└─────┘ │8G│
┌──┐ ┌───┐┌───┐┌───┐┌───────┐┌───┐ ┌─────────┐┌────┐┌────┐ └──┘
│4H│ │4A ││4B ││4C ││4E ││4D │ │9A ││9B ││9C │ ┌──┐┌──┐┌──┐
└──┘ └───┘└───┘└───┘└───────┘└───┘ └─────────┘└────┘└────┘ │9D││9E││9F│
└──┘└──┘└──┘
Matrix for "LAYOUT_lspace_split_bksp":
┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐
│0A││0B││0C││0D││0E││0F││0G│ │5A││5B││5C││5D││5E││5F││5G││5H│ │7H│
└──┘└──┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└──┘└──┘└──┘ └──┘
┌────┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌────┐ ┌──┐
│1A ││1B││1C││1D││1E││1F│ │6A││6B││6C││6D││6E││6F││6G││6H │ │8H│
└────┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└──┘└──┘└────┘ └──┘
┌──┐ ┌─────┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌──┐┌───────┐ ┌──┐
│4F│ │2A ││2B││2C││2D││2E││2F│ │7A││7B││7C││7D││7E││7F││7G │ │9H│
└──┘ └─────┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└──┘└───────┘ └──┘
┌──┐ ┌───────┐┌──┐┌──┐┌──┐┌──┐┌──┐ ┌──┐┌──┐┌──┐┌──┐┌──┐┌─────┐
│4G│ │3A ││3B││3C││3D││3E││3F│ │8A││8B││8C││8D││8E││8F │ ┌──┐
└──┘ └───────┘└──┘└──┘└──┘└──┘└──┘ └──┘└──┘└──┘└──┘└──┘└─────┘ │8G│
┌──┐ ┌───┐┌───┐┌───┐┌───────┐┌───┐ ┌─────────┐┌────┐┌────┐ └──┘
│4H│ │4A ││4B ││4C ││4E ││4D │ │9A ││9B ││9C │ ┌──┐┌──┐┌──┐
└──┘ └───┘└───┘└───┘└───────┘└───┘ └─────────┘└────┘└────┘ │9D││9E││9F│
└──┘└──┘└──┘
I'm not suggesting that we use the same display style for keymapviz as qmk info -m
(having dedicated outlines for each key takes too much screen space and doesn't leave enough space for actual key legends) but we can write a program that reads layout x,y information and generates a keymapviz-style string template.
info.json
and qmk info -f json
are both viable methods but the latter would require calling the QMK CLI in a subprocess
and check its output so my preference would go to simply reading the info.json
file instead since we don't need any of the extra information that qmk info -f json
provides.
~/qmk_firmware
❯ cat keyboards/binepad/bn003/info.json
{
"keyboard_name": "BN003",
"url": "https://binepad.com",
"maintainer": "binepad",
"layouts": {
"LAYOUT": {
"layout": [
{
"label": "K0",
"x": 0,
"y": 0
},
{
"label": "K1",
"x": 1,
"y": 0
},
{
"label": "K2",
"x": 2,
"y": 0
}
]
}
}
}
~/qmk_firmware
❯ qmk info --keyboard binepad/bn003 -f json | jq ".layouts"
{
"LAYOUT": {
"c_macro": true,
"filename": "keyboards/binepad/bn003/bn003.h",
"layout": [
{
"label": "K0",
"matrix": [
0,
0
],
"w": 1,
"x": 0,
"y": 0
},
{
"label": "K1",
"matrix": [
0,
1
],
"w": 1,
"x": 1,
"y": 0
},
{
"label": "K2",
"matrix": [
0,
2
],
"w": 1,
"x": 2,
"y": 0
}
]
}
}
One downside is that it is not possible (at least easily) to infer a good-looking KLE template from the layout diagram info but clearly the main usecase of keymapviz is to automatically generate ASCII visualisations in the keymap.c
file so the absence of KLE support is not a deal-breaker. We can document the few keyboards that have had KLE support manually added in and let other keyboards graciously "fail" in case the user tries to generate a KLE JSON for an unsupported keyboard and leave a notice saying that "Option -t json
is currently not supported for this keyboard.".
I have the following code block at the top of my keymap rules.mk
:
# Automatically update the keymap visualization when compiling
.PHONY: %
%:
keymapviz -k dactyl_manuform5x6 -t fancy -r keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c -c keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymapviz.toml > /dev/null
This lets me automatically update the keymap visualizations any time I run qmk compile
or qmk flash
which is awesome. However, this only works if I use a single thread for compiling my keymap. If I use the -j
/--jobs
option of the qmk
CLI with any value above 1, keymapviz often throws an error and thus aborts the entire compilation operation. Although in some rare cases, the script works fine and the compilation is not aborted; clear sign of a race condition.
The error that keymapviz throws is the following:
Making handwired/dactyl_manuform/5x6 with keymap precondition
Traceback (most recent call last):
File "/home/vern/.local/bin/keymapviz", line 8, in <module>
sys.exit(main())
File "/home/vern/.local/lib/python3.8/site-packages/keymapviz/keymapviz.py", line 91, in main
output_keymap_c(arg.keymap_c.name, kmvz.keymap_c())
File "/home/vern/.local/lib/python3.8/site-packages/keymapviz/keymapviz.py", line 79, in output_keymap_c
os.rename(output_filename, output_filename + ".bac")
FileNotFoundError: [Errno 2] No such file or directory: 'keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c' -> 'keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c.bac'
Traceback (most recent call last):
File "/home/vern/.local/bin/keymapviz", line 8, in <module>
sys.exit(main())
File "/home/vern/.local/lib/python3.8/site-packages/keymapviz/keymapviz.py", line 91, in main
output_keymap_c(arg.keymap_c.name, kmvz.keymap_c())
File "/home/vern/.local/lib/python3.8/site-packages/keymapviz/keymapviz.py", line 79, in output_keymap_c
os.rename(output_filename, output_filename + ".bac")
FileNotFoundError: [Errno 2] No such file or directory: 'keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c' -> 'keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c.bac'
Traceback (most recent call last):
File "/home/vern/.local/bin/keymapviz", line 8, in <module>
sys.exit(main())
File "/home/vern/.local/lib/python3.8/site-packages/keymapviz/keymapviz.py", line 91, in main
output_keymap_c(arg.keymap_c.name, kmvz.keymap_c())
File "/home/vern/.local/lib/python3.8/site-packages/keymapviz/keymapviz.py", line 79, in output_keymap_c
os.rename(output_filename, output_filename + ".bac")
FileNotFoundError: [Errno 2] No such file or directory: 'keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c' -> 'keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c.bac'
make[1]: *** No rule to make target '.build/obj_handwired_dactyl_manuform_5x6_precondition/quantum/keymap_common.d', needed by '.build/obj_handwired_dactyl_manuform_5x6_precondition/quantum/keymap_common.o'. Stop.
make[1]: *** Waiting for unfinished jobs....
avr-gcc (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Make finished with errors
make: *** [Makefile:535: handwired/dactyl_manuform/5x6:precondition] Error 1
Honestly, I'm not sure whether the problem has to be solved within keymapviz itself, within my particular .PHONY
block or within the QMK CLI.
PS: I use keymapviz 1.7.0
$ keymapviz keyboards/helix/rev2/keymaps/default/keymap.c
Traceback (most recent call last):
File "/Users/yskoht/.pyenv/versions/3.7.0/bin/keymapviz", line 11, in <module>
load_entry_point('keymapviz==1.1.0', 'console_scripts', 'keymapviz')()
File "/Users/yskoht/.pyenv/versions/3.7.0/lib/python3.7/site-packages/keymapviz/keymapviz.py", line 86, in main
keymaps = getattr(kmvz, TYPES[arg.type_])()
File "/Users/yskoht/.pyenv/versions/3.7.0/lib/python3.7/site-packages/keymapviz/__init__.py", line 91, in ascii_art
self.__ascii_art = [aa.format(*self.__legends(_)) for _ in self.keymaps]
File "/Users/yskoht/.pyenv/versions/3.7.0/lib/python3.7/site-packages/keymapviz/__init__.py", line 91, in <listcomp>
self.__ascii_art = [aa.format(*self.__legends(_)) for _ in self.keymaps]
IndexError: tuple index out of range
Helix default keymap.c has ROW=5 version keymap and ROW=4 version keymap.
keymapviz assumes ROW = 5 version keymap for helix. So, ROW = 4 keymap raises above error.
If there is a unicode character (anywhere) in the keymap.c file, the following type of exception is generated:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 226: character maps to
This occurs during the read() function due to the file encoding, before the regex can remove comment lines from the input.
I discovered this problem when trying to generate new ascii art from a keymap.c file that already had "fancy" artwork in it. Specifically, the character position that caused the error always corresponds to the ' ┐' character (box drawing down-left). It seemed to handle the other characters which I cannot explain and I did not try to investigate further.
I think it's reasonably safe to open the file assuming encoding='utf-8'
KLEs JSON allows for Metadata to be included. The JSON template for the Model01 in #90 contains such metadata.
But keymapviz doesn’t handle it correctly and this results in a broken JSON that cannot be imported in KLE.
The problem is that the metadata dict is transformed into a list and all entries in it will be reduced to their keys.
LAYOUT_kc
, LAYOUT_split_3x6_7_4
, LAYOUT_split_2x6_8_5
Hey! Awesome tool, it would be great if you could tag your releases (just normal git tags, no github releases needed) so that I can more easily package it in nixpkgs
Cheers
The code seems to remove surrounding parentheses before splitting a keymap into chunks. However it seems that if the last key in a keymap ends with a parentheses this one will be stripped as well and therefore the key is parsed incorrectly.
See for example the Model01 keymap from QMK. The last two keys (the palm keys) are both defined as MO(FUN)
. But when running keymapviz over (via PR #90) it the last one is incorrectly parsed as MO
.
/* ┌──────┬──────┬──────┬──────┬──────┬──────┬──────┐ ┌──────┬──────┬──────┬──────┬──────┬──────┬──────┐
* │QK_BOO│ 1 │ 2 │ 3 │ 4 │ 5 │RGB_MO│ │ │ 6 │ 7 │ 8 │ 9 │ 0 │TG(NUM│
* ├──────┼──────┼──────┼──────┼──────┼──────┼──────┤ ├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
* │ GRV │ Q │ W │ E │ R │ T │ │ │ │ Y │ U │ I │ O │ P │ EQL │
* ├──────┼──────┼──────┼──────┼──────┼──────┤ TAB │ │ ENT ├──────┼──────┼──────┼──────┼──────┼──────┤
* │ PGUP │ A │ S │ D │ F │ G ├──────┤ ├──────┤ H │ J │ K │ L │ SCLN │ QUOT │
* ├──────┼──────┼──────┼──────┼──────┼──────┤ │ │ ├──────┼──────┼──────┼──────┼──────┼──────┤
* │ PGDN │ Z │ X │ C │ V │ B │ ESC │ │ │ N │ M │ COMM │ DOT │ SLSH │ MINS │
* └──────┴──────┴──────┴──────┴──────┴──────┴──────┘ └──────┴──────┴──────┴──────┴──────┴──────┴──────┘
*
* ┌──────┬──────┐ ┌──────┬──────┐
* │ LCTL │ BSPC ├──────┐ ┌──────┤ SPC │ RCTL │
* │ │ │ LGUI ├──────┐ ┌──────┤ RALT │ │ │
* └──────┴──────┤ │ LSFT │ │ RSFT │ ├──────┴──────┘
* └──────┤ │ │ ├──────┘
* ┌──────┐ └──────┘ └──────┘ ┌──────┐
* │ │ │ │
* │MO(FUN│ │ MO │
* │ │ │ │
* └──────┘ └──────┘
* generated by [keymapviz] */
This is not specific to PR #90. It happens with already existing code, too.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.