From a8c09f2584b1642623717a6cd58be63ece30fee5 Mon Sep 17 00:00:00 2001 From: Nick Coutsos Date: Mon, 20 Dec 2021 18:00:45 -0500 Subject: Experimental support for .keymap template --- README.md | 27 ++++++++++++++++----------- api/services/github/files.js | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b5fde3d..0a2c3c8 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Keymap Editor -A browser app (plus NodeJS server) to edit QMK and ZMK keymaps. This was hastily -thrown together and then even more hastily converted to a Vue app with support -for ZMK tossed in. +A browser app (plus NodeJS server) to edit ZMK keymaps. This is still in its +infancy and doesn't yet support parsing existing ZMK keymaps which limits some +kinds of functionality (mainly those involving custom/configured behaviours). ![Screenshot](editor-screenshot.png) @@ -68,14 +68,19 @@ I know that QMK moves quickly and now supports a lot of configuration in I haven't defined, and would benefit from a schema definition agreed on by the dev team. -In a previous version I had started working on supporting combos but gave up -because I couldn't be bothered to experiment with `TAPPING_TERM` settings that -felt comfortable. +Some ZMK behaviours can be configured and some nodes of the device tree can be +aliased, but I don't understand it well enough to make these first-class +editable resources in this tool. As a short term solution I've added simplistic +"templating" of an existing keymap file. If your repository includes a file +called `config/*.keymap.template` the editor will replace the following tags +with the appropriate generated code -More recently I've ripped out QMK-related code. Some interfaces haven't been -updated, so there's still some vestigial support for both. It's less important -to make this a 100% fit for the ZMK codebase and more important to provide a -proof of concept for how apps can be built to support users of the firmware. +* `{{behaviour_includes}}` +* `{{rendered_layers}}` + +Note that "simplistic" means "find-and-replace" and doesn't support templating +other content of each layer section. So you may be able to define encoders in +your keymap template but you can't make per-layer bindings for them. ### What else? @@ -95,4 +100,4 @@ The collection of ZMK keycodes is taken from the ZMK documentation under the MIT license as well. [keymap-editor]: https://nickcoutsos.github.io/keymap-editor/ -[zmk-config-corne-demo]: https://github.com/nickcoutsos/zmk-config-corne-demo \ No newline at end of file +[zmk-config-corne-demo]: https://github.com/nickcoutsos/zmk-config-corne-demo diff --git a/api/services/github/files.js b/api/services/github/files.js index 9c2b6f9..41cc91d 100644 --- a/api/services/github/files.js +++ b/api/services/github/files.js @@ -73,9 +73,24 @@ async function findCodeKeymap (installationToken, repository, branch) { return originalCodeKeymap } +async function findCodeKeymapTemplate (installationToken, repository, branch) { + // Assume that the relevant files are under `config/` and not a complicated + // directory structure, and that there are fewer than 1000 files in this path + // (a limitation of GitHub's repo contents API). + const { data: directory } = await fetchFile(installationToken, repository, 'config', { branch }) + const template = directory.find(file => file.name.toLowerCase().endsWith('.keymap.template')) + + if (template) { + const { data: content } = await fetchFile(installationToken, repository, template.path, { branch, raw: true }) + return content + } +} + async function commitChanges (installationId, repository, branch, layout, keymap) { const { data: { token: installationToken } } = await auth.createInstallationToken(installationId) - const generatedKeymap = zmk.generateKeymap(layout, keymap) + const template = await findCodeKeymapTemplate(installationToken, repository, branch) + + const generatedKeymap = zmk.generateKeymap(layout, keymap, template) const originalCodeKeymap = await findCodeKeymap(installationToken, repository, branch) const { data: {sha, commit} } = await api.request({ url: `/repos/${repository}/commits/${branch}`, token: installationToken }) -- cgit v1.2.3