1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-11-03 02:37:23 -05:00
amfora/config/keybindings.go

25 lines
573 B
Go
Raw Normal View History

2020-08-06 13:55:43 -04:00
package config
import (
"errors"
"github.com/spf13/viper"
)
// KeyToNum returns the number on the user's keyboard they pressed,
// using the rune returned when when they press Shift+Num.
// The error is not nil if the provided key is invalid.
func KeyToNum(key rune) (int, error) {
runes := []rune(viper.GetString("keybindings.shift_numbers"))
for i := range runes {
if key == runes[i] {
if i == len(runes)-1 {
// Last key is 0, not 10
return 0, nil
}
return i + 1, nil
}
}
return -1, errors.New("provided key is invalid") //nolint:goerr113
2020-08-06 13:55:43 -04:00
}