mirror of
https://github.com/makeworld-the-better-one/amfora.git
synced 2024-11-26 21:35:09 +03:00
25 lines
573 B
Go
25 lines
573 B
Go
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
|
|
}
|