From 6440f4af878150b501befdb91a73ef7e92a52bee Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Sat, 13 Apr 2024 14:03:28 +0200 Subject: [PATCH] plugins/qmk: init --- plugins/default.nix | 1 + plugins/languages/qmk.nix | 120 +++++++++++++++++++ tests/test-sources/plugins/languages/qmk.nix | 49 ++++++++ 3 files changed, 170 insertions(+) create mode 100644 plugins/languages/qmk.nix create mode 100644 tests/test-sources/plugins/languages/qmk.nix diff --git a/plugins/default.nix b/plugins/default.nix index 9d19fc9a..ef66974b 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -63,6 +63,7 @@ ./languages/parinfer-rust.nix ./languages/plantuml-syntax.nix ./languages/python/jupytext.nix + ./languages/qmk.nix ./languages/rust-tools.nix ./languages/rustaceanvim.nix ./languages/sniprun.nix diff --git a/plugins/languages/qmk.nix b/plugins/languages/qmk.nix new file mode 100644 index 00000000..29f8f6c6 --- /dev/null +++ b/plugins/languages/qmk.nix @@ -0,0 +1,120 @@ +{ + lib, + helpers, + config, + pkgs, + ... +}: +with lib; + helpers.neovim-plugin.mkNeovimPlugin config { + name = "qmk"; + originalName = "qmk.nvim"; + defaultPackage = pkgs.vimPlugins.qmk-nvim; + + maintainers = [maintainers.GaetanLepage]; + + settingsOptions = { + name = mkOption { + type = types.str; + example = "LAYOUT_preonic_grid"; + description = '' + The name of your layout, for example `LAYOUT_preonic_grid` for the preonic keyboard, for + zmk this can just be anything, it won't be used. + ''; + }; + + layout = mkOption { + type = with types; listOf str; + example = [ + "x x" + "x^x" + ]; + description = '' + The keyboard key layout. + + The layout config describes your layout as expected by qmk_firmware. + As qmk_firmware is simply expecting an array of key codes, the layout is pretty much up to + you. + + A layout is a list of strings, where each string in the list represents a single row. + Rows must all be the same width, and you'll see they visually align to what your keymap + looks like. + ''; + }; + + variant = helpers.defaultNullOpts.mkEnumFirstDefault ["qmk" "zmk"] '' + Chooses the expected hardware target. + ''; + + timeout = helpers.defaultNullOpts.mkUnsignedInt 5000 '' + Duration of `vim.notify` timeout if using `nvim-notify`. + ''; + + auto_format_pattern = helpers.defaultNullOpts.mkStr "*keymap.c" '' + The autocommand file pattern to use when applying `QMKFormat` on save. + ''; + + comment_preview = { + position = helpers.defaultNullOpts.mkEnumFirstDefault ["top" "bottom" "inside" "none"] '' + Control the position of the preview, set to `none` to disable (`inside` is only valid for + `variant=qmk`). + ''; + + keymap_overrides = helpers.defaultNullOpts.mkAttrsOf types.str "{}" '' + A dictionary of key codes to text replacements, any provided value will be merged with the + existing dictionary, see [key_map.lua](https://github.com/codethread/qmk.nvim/blob/main/lua/qmk/config/key_map.lua) for details. + ''; + + symbols = + helpers.defaultNullOpts.mkAttrsOf types.str + '' + { + space = " "; + horz = "─"; + vert = "│"; + tl = "┌"; + tm = "┬"; + tr = "┐"; + ml = "├"; + mm = "┼"; + mr = "┤"; + bl = "└"; + bm = "┴"; + br = "┘"; + } + '' + '' + A dictionary of symbols used for the preview comment border chars see [default.lua](https://github.com/codethread/qmk.nvim/blob/main/lua/qmk/config/default.lua) for details. + ''; + }; + }; + + settingsExample = { + name = "LAYOUT_preonic_grid"; + layout = [ + "x x" + "x^x" + ]; + variant = "qmk"; + timeout = 5000; + auto_format_pattern = "*keymap.c"; + comment_preview = { + position = "top"; + keymap_overrides = {}; + symbols = { + space = " "; + horz = "─"; + vert = "│"; + tl = "┌"; + tm = "┬"; + tr = "┐"; + ml = "├"; + mm = "┼"; + mr = "┤"; + bl = "└"; + bm = "┴"; + br = "┘"; + }; + }; + }; + } diff --git a/tests/test-sources/plugins/languages/qmk.nix b/tests/test-sources/plugins/languages/qmk.nix new file mode 100644 index 00000000..a2ca3042 --- /dev/null +++ b/tests/test-sources/plugins/languages/qmk.nix @@ -0,0 +1,49 @@ +{ + minimal = { + plugins.qmk = { + enable = true; + settings = { + name = "LAYOUT_preonic_grid"; + layout = [ + "x x" + "x^x" + ]; + }; + }; + }; + + example = { + plugins.qmk = { + enable = true; + + settings = { + name = "LAYOUT_preonic_grid"; + layout = [ + "x x" + "x^x" + ]; + variant = "qmk"; + timeout = 5000; + auto_format_pattern = "*keymap.c"; + comment_preview = { + position = "top"; + keymap_overrides = {}; + symbols = { + space = " "; + horz = "─"; + vert = "│"; + tl = "┌"; + tm = "┬"; + tr = "┐"; + ml = "├"; + mm = "┼"; + mr = "┤"; + bl = "└"; + bm = "┴"; + br = "┘"; + }; + }; + }; + }; + }; +}