charmbracelet / bubbletea

A powerful little TUI framework 🏗
MIT License
27.85k stars 805 forks source link

cannot match `tea.KeySpace` #264

Closed tgirod closed 2 years ago

tgirod commented 2 years ago

I think (correct me if I'm wrong) it is not possible to match any event to tea.KeySpace.

meowgorithm commented 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!
}
tgirod commented 2 years ago

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.