Closed tgirod closed 2 years ago
Hi! You actually just match on a literal space:
// It's usually simplest to just use the Stringer interface
switch msg.String() {
case " ":
// It's a space!
}
// The super verbose way
if msg.Type == tea.KeyRunes && string(msg.Runes) == " " {
// It's a space!
}
Thanks, I figured that part by myself! ;)
What I meant is, pressing [space] in bubbletea will produce a Key{Type: KeyRunes}
event, but no keystroke will ever produce a Key{Type: KeySpace}
, and I find it misleading.
In my first program I wanted [space] to trigger a special behaviour, so naturally I went for something like this:
switch msg.Type {
case tea.KeySpace:
// triggers something special
case tea.KeyRunes:
// append to the model's state
}
... and it took me some time to realize that this won't match the space key.
I think (correct me if I'm wrong) it is not possible to match any event to
tea.KeySpace
.