yskoht / keymapviz

keymap.c visualizer
MIT License
120 stars 27 forks source link

Unable to render if using drashna's wrapper. #89

Open vunhatchuong opened 1 year ago

vunhatchuong commented 1 year ago

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.

vunhatchuong commented 1 year ago

I try to write a small code that can substitute:

substitutions = {
   "___________________EMPTY___________________":  "XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX",
   "_________________QWERTY_L1_________________":  "KC_Q,    KC_W,    KC_E,    KC_R,    KC_T"
}

with open('../keymap_test.c', 'r') as file:
    contents = file.read()

for key, value in substitutions.items():
    pattern = re.escape(key) + r'\s*,?'
    replacement = value + ','
    contents = re.sub(pattern, replacement, contents)

with open('../keymap_test.c', 'w') as file:
    file.write(contents)

Another problem is that the layers don't use LAYOUT() but LAYOUT_wrapper().

precondition commented 1 year ago

I started working on wrapper support a long time ago in my wrapper branch (can be found here: https://github.com/precondition/keymapviz/tree/wrapper) but while wrappers like rishka's worked, I couldn't find a way to make drashna-style wrappers work.

❯ keymapviz -k dactyl_manuform5x6 -w /home/vern/qmk_firmware/users/rishka/rishka.h ~/qmk_firmware/keyboards/handwired/dactyl_manuform/5x6/keymaps/rishka/keymap.c

/*                 ,-------------------------------. ,-------------------------------.
 * ,---------------|   2   |   3   |   4   |   5   | |   6   |   7   |   8   |   9   |--------------.
 * |  EQL  |   1   |-------+-------+-------+-------| |-------+-------+-------+-------|   0   | MINS |
 * |-------+-------|   W   |   E   |   R   |   T   | |   Y   |   U   |   I   |   O   |-------+------|
 * |  ESC  |   Q   |-------+-------+-------+-------| |-------+-------+-------+-------|   P   | BSLS |
 * |-------+-------|SFT_T(K|GUI_T(K|ALT_T(K|   G   | |   H   |ALT_T(K|GUI_T(K|SFT_T(K|-------+------|
 * |  F1   |CTL_T(K|-------+-------+-------+-------| |-------+-------+-------+-------|CTL_T(K| QUOT |
 * |-------+-------|   X   |   C   |   V   |   B   | |   N   |   M   | COMM  |  DOT  |-------+------|
 * |OS_LSFT|   Z   |-------+-------+---------------' `---------------+-------+-------| SLSH  |OS_RSF|
 * `---------------| LEFT  | RGHT  |                                 |  UP   | DOWN  |--------------'
 *                 `---------------'                                 `---------------'
 *                                 ,---------------. ,---------------.
 *                                 | BSPC  |  SPC  | |  TAB  |  ENT  |
 *                                 |-------+-------| |-------+-------|
 *                                 | LGUI  |MO(SYMB| |MO(SYMB|TT(MDIA|
 *                                 |-------+-------| |-------+-------|
 *                                 |  DEL  |  GRV  | |TT(WIN)| LALT  |
 *                                 `---------------' `---------------'       generated by [keymapviz] */

/*                 ,-------------------------------. ,-------------------------------.
 * ,---------------|       |       |       |       | |       |       |       |       |--------------.
 * |       |       |-------+-------+-------+-------| |-------+-------+-------+-------|       |      |
 * |-------+-------|       |       |       |       | |       |       |       |       |-------+------|
 * |       |       |-------+-------+-------+-------| |-------+-------+-------+-------|       |      |
 * |-------+-------|   S   |   D   |   F   |   G   | |       |       |       |       |-------+------|
 * |       |   A   |-------+-------+-------+-------| |-------+-------+-------+-------|       |      |
 * |-------+-------|       |       |       |       | |       |       |       |       |-------+------|
 * |       |       |-------+-------+---------------' `---------------+-------+-------|       |      |
 * `---------------|       |       |                                 |       |       |--------------'
 *                 `---------------'                                 `---------------'
 *                                 ,---------------. ,---------------.
 *                                 |       |       | |       |       |
 *                                 |-------+-------| |-------+-------|
 *                                 | LCTL  |       | |       |       |
 *                                 |-------+-------| |-------+-------|
 *                                 |       |       | |       |       |
 *                                 `---------------' `---------------'       generated by [keymapviz] */

/*                 ,-------------------------------. ,-------------------------------.
 * ,---------------|  F2   |  F3   |  F4   |  F5   | |  F6   |  F7   |  F8   |  F9   |--------------.
 * |  F12  |  F1   |-------+-------+-------+-------| |-------+-------+-------+-------|  F10  | F11  |
 * |-------+-------|  AT   | LCBR  | RCBR  | UNDS  | | BSLS  |  P7   |  P8   |  P9   |-------+------|
 * |       | EXLM  |-------+-------+-------+-------| |-------+-------+-------+-------| PAST  | NUM  |
 * |-------+-------|  DLR  | LPRN  | RPRN  | MINS  | |  EQL  |  P4   |  P5   |  P6   |-------+------|
 * |       | HASH  |-------+-------+-------+-------| |-------+-------+-------+-------| PPLS  |      |
 * |-------+-------| CIRC  | LBRC  | RBRC  | PLUS  | | ASTR  |  P1   |  P2   |  P3   |-------+------|
 * |       | PERC  |-------+-------+---------------' `---------------+-------+-------| PMNS  |      |
 * `---------------|       |       |                                 |  P0   | PDOT  |--------------'
 *                 `---------------'                                 `---------------'
 *                                 ,---------------. ,---------------.
 *                                 |       |       | |       |       |
 *                                 |-------+-------| |-------+-------|
 *                                 |QK_BOOT|       | |       |       |
 *                                 |-------+-------| |-------+-------|
 *                                 |RGB_TOG|       | |       |       |
 *                                 `---------------' `---------------'       generated by [keymapviz] */

/*                 ,-------------------------------. ,-------------------------------.
 * ,---------------|       |       |       |       | |       |       |       |       |--------------.
 * |RGB_MOD|RGB_HUI|-------+-------+-------+-------| |-------+-------+-------+-------|       |      |
 * |-------+-------|       | MS_U  |       | WH_U  | |       |       | WH_U  |       |-------+------|
 * |RGB_M_S|RGB_HUD|-------+-------+-------+-------| |-------+-------+-------+-------|       |      |
 * |-------+-------| MS_L  | MS_D  | MS_R  | WH_D  | |       |MOUSE_L| WH_D  |MOUSE_R|-------+------|
 * |RGB_VAI|RGB_SAI|-------+-------+-------+-------| |-------+-------+-------+-------|       |      |
 * |-------+-------|       |       |       |       | |       |       |       |       |-------+------|
 * |RGB_VAD|RGB_SAD|-------+-------+---------------' `---------------+-------+-------|       |      |
 * `---------------|       |       |                                 |       |       |--------------'
 *                 `---------------'                                 `---------------'
 *                                 ,---------------. ,---------------.
 *                                 | BTN1  | BTN2  | |       |       |
 *                                 |-------+-------| |-------+-------|
 *                                 | BTN3  | BTN4  | |       |       |
 *                                 |-------+-------| |-------+-------|
 *                                 | BTN5  |       | |       |       |
 *                                 `---------------' `---------------'       generated by [keymapviz] */
❯ keymapviz -k kyria -w /home/vern/qmk_firmware/users/drashna/keyrecords/wrappers.h /home/vern/qmk_firmware/keyboards/splitkb/kyria/keymaps/drashna/keymap.c

/* ,-----------------------------------------.                              ,-----------------------------------------.
 * |__VA_A|      |      |      |      |      |                              |      |      |      |      |      |      |
 * |------+------+------+------+------+------|                              |------+------+------+------+------+------|
 * |      |      |      |      |      |      |                              |      |      |      |      |      |      |
 * |------+------+------+------+------+------+------+------.  ,------+------+------+------+------+------+------+------|
 * |      |      |      |      |      |      |      |      |  |      |      |      |      |      |      |      |      |
 * `------+------+------+------+------+------+------+------.  ,------+------+------+------+------+------+------+------'
 *                      |      |      |      |      |      |  |      |      |      |      |      |
 *                      |      |      |      |      |      |  |      |      |      |      |      |
 *                      `----------------------------------'  `----------------------------------'
 *                                                                               generated by [keymapviz] */

It is definitely not production-ready, nor up-to-date with develop but if you want to play around with it, go ahead. The relevant commit hash is https://github.com/precondition/keymapviz/commit/4de7b28398cb7f7fe7c0f6b9ef242ea5a37106a2

vunhatchuong commented 9 months ago

You can try this regex instead: d = dict(re.findall(r"\#define (_[\S]+_)(.+)", self.wrappers, flags=re.MULTILINE)). With this you can remove the first loop that does d[k] = d[d[k]].