Skip to content

Commit

Permalink
feat: testing and configurable iterative mapping
Browse files Browse the repository at this point in the history
Co-authored-by: tris203 <[email protected]>
  • Loading branch information
tris203 and tris203 authored Dec 20, 2023
1 parent 39f4f96 commit dae77e1
Show file tree
Hide file tree
Showing 13 changed files with 514 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .githooks/tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

make test
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test

on:
push:
branches:
- "main"
pull_request:
branches:
- "main"

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
nvim-versions: ['stable', 'nightly']
name: Plenary Tests
steps:
- name: checkout
uses: actions/checkout@v3

- uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: ${{ matrix.nvim-versions }}

- name: run tests
run: make test
7 changes: 7 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"diagnostics.globals": [
"describe",
"it",
"before_each"
]
}
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
TESTS_INIT=tests/minimal_init.lua
TESTS_DIR=tests/

.PHONY: test

test:
@nvim \
--headless \
--noplugin \
-u ${TESTS_INIT} \
-c "PlenaryBustedDirectory ${TESTS_DIR} { minimal_init = '${TESTS_INIT}' }"
43 changes: 43 additions & 0 deletions lua/hawtkeys/init.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,53 @@
local M = {}

---@alias SupportedKeyboardLayouts "qwerty" | "dvorak"

---@class HawtKeyConfig
---@field leader string
---@field homerow number
---@field powerFingers number[]
---@field keyboardLayout SupportedKeyboardLayouts
---@field customMaps { [string] : TSKeyMapArgs | WhichKeyMapargs } | nil

---@class HawtKeyPartialConfig
---@field leader string | nil
---@field homerow number | nil
---@field powerFingers number[] | nil
---@field keyboardLayout SupportedKeyboardLayouts | nil
---@field customMaps { [string] : TSKeyMapArgs | WhichKeyMapargs } | nil
---

---@type { [string] : TSKeyMapArgs | WhichKeyMapargs }---

local _defaultSet = {
["vim.keymap.set"] = {
modeIndex = 1,
lhsIndex = 2,
rhsIndex = 3,
optsIndex = 4,
method = "dot_index_expression",
}, --method 1
["vim.api.nvim_set_keymap"] = {
modeIndex = 1,
lhsIndex = 2,
rhsIndex = 3,
optsIndex = 4,
method = "dot_index_expression",
}, --method 2
["whichkey.register"] = {
method = "which_key",
}, -- method 6
}

---@param config HawtKeyPartialConfig
function M.setup(config)
config = config or {}
M.leader = config.leader or " "
M.homerow = config.homerow or 2
M.powerFingers = config.powerFingers or { 2, 3, 6, 7 }
M.keyboardLayout = config.keyboardLayout or "qwerty"
M.keyMapSet = vim.tbl_extend("force", _defaultSet, config.customMaps or {})

vim.api.nvim_create_user_command(
"Hawtkeys",
"lua require('hawtkeys.ui').show()",
Expand Down
Loading

0 comments on commit dae77e1

Please sign in to comment.