mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
add keymap, handle wrapper for common keybindings
This commit is contained in:
32
keys.go
Normal file
32
keys.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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",
|
||||
},
|
||||
"exit": []string{
|
||||
"/sys/kbd/q",
|
||||
"/sys/kbd/C-c",
|
||||
},
|
||||
"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() })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user