I would like to compare to constants, not strings #697
Replies: 2 comments
-
The |
Beta Was this translation helpful? Give feedback.
-
Hi! There actually are exported constants for keys. A type Key struct {
Type KeyType
Runes []rune
Alt bool
} So here's how you could work with key constants: switch msg := msg.(type) {
case KeyMsg:
switch msg.Type {
case tea.KeyEnter:
fmt.Println("you pressed enter!")
case tea.KeyRunes:
switch string(msg.Runes) {
case "a":
fmt.Println("you pressed a!")
}
}
} Keep in mind there are no constants for letter keys (such as the "a" key) because we need to be able to match all sorts of input like Anyway, for more info see Key, KeyMsg, and KeyType in the docs. |
Beta Was this translation helpful? Give feedback.
-
This just feels a little dirty. I see there's constants in
key.go
, can we export them?Beta Was this translation helpful? Give feedback.
All reactions