-
Notifications
You must be signed in to change notification settings - Fork 0
Keyboard
Brandon Jordan edited this page Nov 10, 2024
·
6 revisions
To bind keys, ttuy uses github.com/eiannone/keyboard
, then the binding details with the struct.
BindKey(key keyboard.Key, binding KeyBinding)
// KeyBinding describes a key binding to an action.
type KeyBinding struct {
// Description of what the handler will do.
descriptor string
// Representation of key (e.g. ^C).
keyString string
// Called when the key is pressed.
handler func()
}
BindKey(keyboard.KeyCtrlC, KeyBinding{
descriptor: "Exit",
keyString: "^C",
handler: func() {
StopPainting()
fmt.Print("Exited.\n\n")
},
})
To list keybindings, use PrintKeyBindings()
.
PrintKeyBindings(separator string)
This returns a styled string of the registered key bindings.
^C Exit • ^Q Toggle highlight