Following Changes have been made in addition to `https://github.com/aditya-K2/goMP/pull/5/commits/1572a460b042c25c93d4d5ed27b1a75432a53464` 1. config.go : ReadMappings Reads Array for each function Basically we are going to define mappings like this : ```yml Function : - first mapping - second mapping - third mapping ````` 2. kMap.go : GetAsciiValues will help us to get e.Rune() for the event for the handler function. So basically we will have a keymappings map generated which will help us to handle events. for e.g if an user has defined following mappings ````yml togglePlayBack : - P - p - B ```` then the keymappings map will look like this []keymappings = { GetAsciiValues("P") : togglePlayBack(), GetAsciiValues("p") : togglePlayBack(), GetAsciiValues("B") : togglePlayBack(), } so when the handler function will get an event e we will just pass it to this keymappings map i.e keymappings[e] which will return the function
28 lines
489 B
Go
28 lines
489 B
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
var KMAP = map[string]int{
|
|
"TAB": 9,
|
|
"RETURN": 13,
|
|
"ENTER": 13,
|
|
"SPACE": 32,
|
|
}
|
|
|
|
func GetAsciiValue(s string) (int, error) {
|
|
if len([]rune(s)) == 1 {
|
|
char := []rune(s)[0]
|
|
if (int(char) >= 65 && int(char) <= 90) || (int(char) >= 97 && int(char) <= 122) {
|
|
return int(char), nil
|
|
} else {
|
|
return -1, errors.New("Not Found")
|
|
}
|
|
} else if val, ok := KMAP[s]; ok {
|
|
return val, nil
|
|
} else {
|
|
return -1, errors.New("Not Found")
|
|
}
|
|
}
|