Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to parse all printable utf chars #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ A golang wrapper for parsing gocui keybindings.
```go
// get a single keybinding
keybinding.Parse("ctrl+c")
keybinding.Parse("/")
keybinding.Parse("ü")
keybinding.Parse("ö")

// get a list of keybindings
keybinding.ParseAll("ctrl+A, ctrl+B, CTRL+ALT+C")
Expand Down
6 changes: 3 additions & 3 deletions keybinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func Parse(input string) (Key, error) {
f := func(c rune) bool { return unicode.IsSpace(c) || c == '+' }
tokens := strings.FieldsFunc(input, f)

if len(tokens) == 1 && len(tokens[0]) == 1 {
single := rune(tokens[0][0])
if unicode.IsLetter(single) {
if len(tokens) == 1 && len([]rune(tokens[0])) == 1 {
single := []rune(tokens[0])[0]
if unicode.IsPrint(single) {
return Key{single, gocui.ModNone, tokens}, nil
}
}
Expand Down
3 changes: 3 additions & 0 deletions keybinding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func TestParse(t *testing.T) {
{"ctrl + alt + !", 0, gocui.ModAlt, "unsupported keybinding: KeyCtrl! (+1)"},
{"q", rune('q'), gocui.ModNone, ""},
{" q", rune('q'), gocui.ModNone, ""},
{"ü", rune('ü'), gocui.ModNone, ""},
{"ö", rune('ö'), gocui.ModNone, ""},
{"/", rune('/'), gocui.ModNone, ""},
}

for idx, trial := range table {
Expand Down