2017-03-14 22:34:09 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
ui "github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Common action keybindings
|
|
|
|
var keyMap = map[string][]string{
|
|
|
|
"up": []string{
|
|
|
|
"/sys/kbd/<up>",
|
|
|
|
"/sys/kbd/k",
|
|
|
|
},
|
|
|
|
"down": []string{
|
|
|
|
"/sys/kbd/<down>",
|
|
|
|
"/sys/kbd/j",
|
|
|
|
},
|
2017-03-24 02:31:08 +00:00
|
|
|
"pgup": []string{
|
|
|
|
"/sys/kbd/<previous>",
|
|
|
|
"/sys/kbd/C-<up>",
|
|
|
|
},
|
|
|
|
"pgdown": []string{
|
|
|
|
"/sys/kbd/<next>",
|
|
|
|
"/sys/kbd/C-<down>",
|
2017-03-28 03:57:30 +00:00
|
|
|
},
|
2017-03-14 22:34:09 +00:00
|
|
|
"exit": []string{
|
|
|
|
"/sys/kbd/q",
|
|
|
|
"/sys/kbd/C-c",
|
2017-06-08 12:47:30 +00:00
|
|
|
"/sys/kbd/<escape>",
|
2017-03-14 22:34:09 +00:00
|
|
|
},
|
|
|
|
"help": []string{
|
|
|
|
"/sys/kbd/h",
|
|
|
|
"/sys/kbd/?",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply a common handler function to all given keys
|
|
|
|
func HandleKeys(i string, f func()) {
|
|
|
|
for _, k := range keyMap[i] {
|
|
|
|
ui.Handle(k, func(ui.Event) { f() })
|
|
|
|
}
|
|
|
|
}
|