Added Default Mappings
Following Changes Have been made:
    1.  Rename KMAP -> SPECIAL_KEYS
    2.  Added Default Mappings through KEY_MAPPINGS
	so when the config is read it will change the KEY_MAPPINGS map
	which will be then used by the handler function for events.
			
			
This commit is contained in:
		
							parent
							
								
									3c5835dba1
								
							
						
					
					
						commit
						482978897d
					
				@ -4,12 +4,35 @@ import (
 | 
				
			|||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var KMAP = map[string]int{
 | 
					var (
 | 
				
			||||||
	"TAB":    9,
 | 
						SPECIAL_KEYS = map[string]int{
 | 
				
			||||||
	"RETURN": 13,
 | 
							"TAB":    9,
 | 
				
			||||||
	"ENTER":  13,
 | 
							"RETURN": 13,
 | 
				
			||||||
	"SPACE":  32,
 | 
							"ENTER":  13,
 | 
				
			||||||
}
 | 
							"SPACE":  32,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						KEY_MAP = map[int]string{
 | 
				
			||||||
 | 
							108: "showChildrenContent",
 | 
				
			||||||
 | 
							112: "togglePlayBack",
 | 
				
			||||||
 | 
							104: "showParentContent",
 | 
				
			||||||
 | 
							110: "nextSong",
 | 
				
			||||||
 | 
							99:  "clearPlaylist",
 | 
				
			||||||
 | 
							78:  "previousSong",
 | 
				
			||||||
 | 
							97:  "addToPlaylist",
 | 
				
			||||||
 | 
							122: "toggleRandom",
 | 
				
			||||||
 | 
							114: "toggleRepeat",
 | 
				
			||||||
 | 
							45:  "decreaseVolume",
 | 
				
			||||||
 | 
							61:  "increaseVolume",
 | 
				
			||||||
 | 
							50:  "navigateToFiles",
 | 
				
			||||||
 | 
							49:  "navigateToPlaylist",
 | 
				
			||||||
 | 
							51:  "navigateToMostPlayed",
 | 
				
			||||||
 | 
							113: "quit",
 | 
				
			||||||
 | 
							115: "stop",
 | 
				
			||||||
 | 
							117: "updateDB",
 | 
				
			||||||
 | 
							100: "deleteSongFromPlaylist",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func GetAsciiValue(s string) (int, error) {
 | 
					func GetAsciiValue(s string) (int, error) {
 | 
				
			||||||
	if len([]rune(s)) == 1 {
 | 
						if len([]rune(s)) == 1 {
 | 
				
			||||||
@ -19,7 +42,7 @@ func GetAsciiValue(s string) (int, error) {
 | 
				
			|||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			return -1, errors.New("Not Found")
 | 
								return -1, errors.New("Not Found")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else if val, ok := KMAP[s]; ok {
 | 
						} else if val, ok := SPECIAL_KEYS[s]; ok {
 | 
				
			||||||
		return val, nil
 | 
							return val, nil
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return -1, errors.New("Not Found")
 | 
							return -1, errors.New("Not Found")
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestGetAsciiValue(t *testing.T) {
 | 
					func TestGetAsciiValue(t *testing.T) {
 | 
				
			||||||
	for k, v := range KMAP {
 | 
						for k, v := range SPECIAL_KEYS {
 | 
				
			||||||
		result, err := GetAsciiValue(k)
 | 
							result, err := GetAsciiValue(k)
 | 
				
			||||||
		if result != v {
 | 
							if result != v {
 | 
				
			||||||
			t.Errorf("Values From KMAP Failed")
 | 
								t.Errorf("Values From KMAP Failed")
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user