forked from qmk/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Keyboard] add keymap beautifier for Ergodox EZ (qmk#4393)
* add beautifier * add example * Update keyboards/ergodox_ez/util/keymap_beautifier.py Co-Authored-By: tsankuanglee <[email protected]> * Update keyboards/ergodox_ez/util/keymap_beautifier.py Co-Authored-By: tsankuanglee <[email protected]> * works for regular layout * all planned features implemented * add justification switch * docker support * doc and starting script * clean up the container after done
- Loading branch information
1 parent
dcb2d63
commit 8b832c4
Showing
7 changed files
with
558 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM python:3.7.4-alpine3.10 | ||
|
||
WORKDIR /usr/src/app | ||
COPY requirements.txt ./ | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
COPY ./KeymapBeautifier.py ./KeymapBeautifier.py | ||
|
||
CMD [ "python", "./KeymapBeautifier.py", "-h" ] |
399 changes: 399 additions & 0 deletions
399
keyboards/ergodox_ez/util/keymap_beautifier/KeymapBeautifier.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# keymap_beautifier.py | ||
|
||
## About | ||
This Python 3 script, by [Tsan-Kuang Lee](https://github.com/tsankuanglee) takes the keymap.c downloaded from [ErgoDox EZ Configurator](https://configure.ergodox-ez.com/) and beautifies it for easier customization, allowing one to quickly draft a layout to build upon. | ||
|
||
## Features | ||
For example, the original `keymap.c` looks like | ||
|
||
``` | ||
[0] = LAYOUT_ergodox(KC_EQUAL,KC_1,KC_2,KC_3,KC_4,KC_5,LCTL(KC_MINUS),KC_DELETE,KC_Q,KC_W,KC_E,KC_R,KC_T,KC_LBRACKET,KC_BSPACE,KC_A,KC_S,KC_D,KC_F,KC_G,KC_LSPO,CTL_T(KC_Z),KC_X,KC_C,KC_V,KC_B,ALL_T(KC_NO),LT(1,KC_GRAVE),KC_QUOTE,LALT(KC_LSHIFT),KC_LEFT,KC_RIGHT,ALT_T(KC_APPLICATION),KC_LGUI,KC_HOME,KC_SPACE,KC_UNDS,KC_END,LCTL(KC_EQUAL),KC_6,KC_7,KC_8,KC_9,KC_0,KC_MINUS,KC_RBRACKET,KC_Y,KC_U,KC_I,KC_O,KC_P,KC_BSLASH,KC_H,ALT_T(KC_J),KC_K,KC_L,LT(2,KC_SCOLON),GUI_T(KC_QUOTE),MEH_T(KC_NO),KC_N,KC_M,KC_COMMA,KC_DOT,CTL_T(KC_SLASH),KC_RSPC,KC_UP,KC_DOWN,KC_LBRACKET,KC_RBRACKET,TT(1),KC_LALT,CTL_T(KC_ESCAPE),KC_PGUP,KC_PGDOWN,LT(1,KC_TAB),KC_ENTER), | ||
``` | ||
|
||
The beautifier parses it and outputs: | ||
|
||
``` | ||
[0] = LAYOUT_ergodox( | ||
// left hand | ||
KC_EQUAL , KC_1 , KC_2 , KC_3 , KC_4 , KC_5, LCTL(KC_MINUS), | ||
KC_DELETE , KC_Q , KC_W , KC_E , KC_R , KC_T, KC_LBRACKET , | ||
KC_BSPACE , KC_A , KC_S , KC_D , KC_F , KC_G, | ||
KC_LSPO , CTL_T(KC_Z), KC_X , KC_C , KC_V , KC_B, ALL_T(KC_NO) , | ||
LT(1,KC_GRAVE), KC_QUOTE , LALT(KC_LSHIFT), KC_LEFT, KC_RIGHT, | ||
// left thumb | ||
ALT_T(KC_APPLICATION), KC_LGUI, | ||
KC_HOME, | ||
KC_SPACE, KC_UNDS , KC_END , | ||
// right hand | ||
LCTL(KC_EQUAL), KC_6, KC_7 , KC_8 , KC_9 , KC_0 , KC_MINUS , | ||
KC_RBRACKET , KC_Y, KC_U , KC_I , KC_O , KC_P , KC_BSLASH , | ||
KC_H, ALT_T(KC_J), KC_K , KC_L , LT(2,KC_SCOLON), GUI_T(KC_QUOTE), | ||
MEH_T(KC_NO) , KC_N, KC_M , KC_COMMA, KC_DOT , CTL_T(KC_SLASH), KC_RSPC , | ||
KC_UP , KC_DOWN , KC_LBRACKET, KC_RBRACKET , TT(1) , | ||
// right thumb | ||
KC_LALT , CTL_T(KC_ESCAPE), | ||
KC_PGUP , | ||
KC_PGDOWN, LT(1,KC_TAB) , KC_ENTER | ||
) | ||
``` | ||
|
||
Optionally, it can also render [LAYOUT_ergodox_pretty](https://github.com/qmk/qmk_firmware/blob/ee700b2e831067bdb7584425569b61bc6329247b/keyboards/ergodox_ez/keymaps/bpruitt-goddard/keymap.c#L49-L57): | ||
``` | ||
[0] = LAYOUT_ergodox_pretty( | ||
KC_ESCAPE, KC_1, KC_2, KC_3, KC_4, KC_5, KC_LEAD, KC_LEAD, KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_BSPACE , | ||
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_HYPR, KC_HYPR, KC_Y , KC_U , KC_I , KC_O , KC_P , KC_BSLASH , | ||
KC_LCTRL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H , KC_J , KC_K , KC_L , KC_SCOLON , KC_QUOTE , | ||
KC_LSHIFT, KC_Z, KC_X, KC_C, KC_V, KC_B, SH_MON, SH_MON , KC_N , KC_M , KC_COMMA , KC_DOT , KC_SLASH , KC_RSHIFT , | ||
LT(6,KC_NO), LT(7,KC_NO), KC_LCTRL, KC_LGUI, KC_LALT, ALGR_T(KC_MINUS), RGUI_T(KC_EQUAL), RCTL_T(KC_LBRACKET), LT(10,KC_RBRACKET), LT(6,KC_APPLICATION), | ||
LT(6,KC_GRAVE), MEH_T(KC_NO), KC_LEFT, KC_RIGHT , | ||
LT(10,KC_DELETE), KC_UP , | ||
KC_SPACE, LT(8,KC_ENTER), LT(7,KC_BSPACE), KC_DOWN, LT(7,KC_SPACE), LT(8,KC_ENTER) | ||
) | ||
``` | ||
|
||
We can also align everythng t othe left (easier editing in my opinon): | ||
``` | ||
[0] = LAYOUT_ergodox_pretty( | ||
KC_ESCAPE , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_LEAD , KC_LEAD, KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_BSPACE , | ||
KC_TAB , KC_Q , KC_W , KC_E , KC_R , KC_T , KC_HYPR , KC_HYPR, KC_Y , KC_U , KC_I , KC_O , KC_P , KC_BSLASH , | ||
KC_LCTRL , KC_A , KC_S , KC_D , KC_F , KC_G , KC_H , KC_J , KC_K , KC_L , KC_SCOLON , KC_QUOTE , | ||
KC_LSHIFT , KC_Z , KC_X , KC_C , KC_V , KC_B , SH_MON , SH_MON , KC_N , KC_M , KC_COMMA , KC_DOT , KC_SLASH , KC_RSHIFT , | ||
LT(6,KC_NO), LT(7,KC_NO), KC_LCTRL, KC_LGUI, KC_LALT , ALGR_T(KC_MINUS), RGUI_T(KC_EQUAL), RCTL_T(KC_LBRACKET), LT(10,KC_RBRACKET), LT(6,KC_APPLICATION), | ||
LT(6,KC_GRAVE), MEH_T(KC_NO) , KC_LEFT, KC_RIGHT , | ||
LT(10,KC_DELETE), KC_UP , | ||
KC_SPACE, LT(8,KC_ENTER), LT(7,KC_BSPACE) , KC_DOWN, LT(7,KC_SPACE), LT(8,KC_ENTER) | ||
) | ||
``` | ||
|
||
## Usage | ||
|
||
### With docker | ||
This is the cleaner way. `Docker` is the only requirement. The program executes within a container that has all dependencies installed. | ||
|
||
First build the images. (Run once) | ||
``` | ||
cd QMK_GIT_REPO_dir/keyboards/ergodox_ez/util/keymap_beautifier | ||
docker build -t keymapbeautifier:1.0 . | ||
``` | ||
Run it | ||
``` | ||
cd QMK_GIT_REPO_dir/keyboards/ergodox_ez/util/keymap_beautifier | ||
cp PATH_TO_YOUR_C_SOURCE_FILE.c input.c | ||
./docker_run.sh input.c -p -c -o output.c | ||
``` | ||
The prettified file is written to `output.c`. See the section Tweaks for non-default settings. | ||
|
||
### Without docker | ||
Requirements: | ||
* python3 (tested on 3.7.4) | ||
* python module `pycparser` installed (with `pip install pycparser`) | ||
|
||
To run: | ||
``` | ||
cd QMK_GIT_REPO_dir/keyboards/ergodox_ez/util/keymap_beautifier | ||
cp PATH_TO_YOUR_C_SOURCE_FILE.c input.c | ||
./KeymapBeautifier.py input.c -p -c -o output.c | ||
``` | ||
The prettified file is written to `output.c`. See the section Tweaks for non-default settings. | ||
|
||
## Tweaks | ||
``` | ||
usage: KeymapBeautifier.py [-h] [-o OUTPUT_FILENAME] [-p] [-c] input_filename | ||
Beautify keymap.c downloaded from ErgoDox-Ez Configurator for easier | ||
customization. | ||
positional arguments: | ||
input_filename input file: c source code file that has the layer | ||
keymaps | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
-o OUTPUT_FILENAME, --output-filename OUTPUT_FILENAME | ||
output file: beautified c filename. If not given, | ||
output to STDOUT. | ||
-p, --pretty-output-layout | ||
use LAYOUT_ergodox_pretty for output instead of | ||
LAYOUT_ergodox | ||
-c, --justify-toward-center | ||
for LAYOUT_ergodox_pretty, align right for the left | ||
half, and align left for the right half. Default is | ||
align left for both halves. | ||
``` | ||
For example, | ||
``` | ||
./docker_run.sh input.c -p -c -o output.c | ||
# or if you don't want to use docker: | ||
#./KeymapBeautifier.py input.c -p -c -o output.c | ||
``` | ||
will read `input.c`, and produce `output.c` with LAYOUT_ergodox_pretty, and have the key symbols gravitating toward the center. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
docker run --mount type=bind,source="${PWD}",target=/usr/src/app --name keymapbeautifier --rm keymapbeautifier:1.0 ./KeymapBeautifier.py $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pycparser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
# ErgoDox EZ Utilities | ||
|
||
## compile_keymap.py | ||
|
||
The Python script in this directory, by [mbarkhau](https://github.com/mbarkhau) allows you to write out a basic ErgoDox EZ keymap using Markdown notation, and then transpile it to C, which you can then compile. It's experimental, but if you're not comfortable using C, it's a nice option. | ||
|
||
## keymap_beautifier.py | ||
|
||
This Python 3 script, by [Tsan-Kuang Lee](https://github.com/tsankuanglee) takes the keymap.c downloaded from [ErgoDox EZ Configurator](https://configure.ergodox-ez.com/) and beautifies it for easier customization, allowing one to quickly draft a layout to build upon. | ||
|
||
See [README.md](./keymap_beautifier/README.md) for this utility for more details. |