diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..0cafecb --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,23 @@ +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... diff --git a/README.md b/README.md index 3fd74a7..8f72526 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,15 @@ keybinding.Parse("ctrl+c") // get a list of keybindings keybinding.ParseAll("ctrl+A, ctrl+B, CTRL+ALT+C") ``` + +# TODO + +* [ ] improve error messages, for example parsing invalid string `ctl + A` +``` +-unsupported keybinding: KeyCtlA ++error parsing `ctl + A`: KeyCtlA is not defined +``` + +* [ ] uppercase single letter shortcuts are different from lowercase + +* [ ] do case insensitive detection for special key names diff --git a/keybinding.go b/keybinding.go index 7384a08..26ff222 100644 --- a/keybinding.go +++ b/keybinding.go @@ -18,13 +18,11 @@ var translate = map[string]string{ "~": "Tilde", "pageup": "Pgup", "pagedown": "Pgdn", - "pgup": "Pgup", "pgdown": "Pgdn", "up": "ArrowUp", "down": "ArrowDown", "right": "ArrowRight", "left": "ArrowLeft", - "ctl": "Ctrl", } var display = map[string]string{ @@ -116,6 +114,7 @@ var supportedKeybindings = map[string]gocui.Key{ // Key contains all relevant information about the key type Key struct { + // Value is either `rune` for single key or `gocui.Key` Value interface{} Modifier gocui.Modifier Tokens []string diff --git a/keybinding_test.go b/keybinding_test.go index 269736d..369e9dc 100644 --- a/keybinding_test.go +++ b/keybinding_test.go @@ -15,8 +15,8 @@ func TestParse(t *testing.T) { }{ {"ctrl + A", gocui.KeyCtrlA, gocui.ModNone, ""}, {"Ctrl + a", gocui.KeyCtrlA, gocui.ModNone, ""}, - {"Ctl + a", gocui.KeyCtrlA, gocui.ModNone, ""}, - {"ctl + A", gocui.KeyCtrlA, gocui.ModNone, ""}, + {"Ctl + a", 0, gocui.ModNone, "unsupported keybinding: KeyCtlA"}, + {"ctl + A", 0, gocui.ModNone, "unsupported keybinding: KeyCtlA"}, {"f2", gocui.KeyF2, gocui.ModNone, ""}, {"ctrl + [", gocui.KeyCtrlLsqBracket, gocui.ModNone, ""}, {" ctrl + ] ", gocui.KeyCtrlRsqBracket, gocui.ModNone, ""}, @@ -36,6 +36,7 @@ func TestParse(t *testing.T) { {"ctrl + alt + !", 0, gocui.ModAlt, "unsupported keybinding: KeyCtrl! (+1)"}, {"q", rune('q'), gocui.ModNone, ""}, {" q", rune('q'), gocui.ModNone, ""}, + {" Q", rune('q'), gocui.ModNone, ""}, } for idx, trial := range table {