charmbracelet / charmbracelet/bubbletea
v2: KeyReleaseMsgs not working as expected on macos
- Dominant language
- Go
- Stars
- 44.9k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
It looks as though the `tea.KeyReleaseMsg`s are not being handled correctly on macOS. In some instances [ghostty w/o tmux] it is working as expected. But in a few tested instances [ghostty w. tmux] [macos stock terminal w or w/o tmux]] I am seeing no release messages making it through
**Setup**
#### Setup One
- OS [macOS 15.3.1 ]
- Shell [zsh]
- Terminal Emulator [ghostty]
- Terminal Multiplexer [tmux]
#### Setup Two
- OS [macOS 15.3.1 ]
- Shell [zsh]
- Terminal Emulator [macos stock terminal]
- Terminal Multiplexer [tmux or without]
**To Reproduce**
Steps to reproduce the behavior:
1. Build the code
2. Run the application in different environments
3. See the lack of key release messages
**Source Code**
```go
package main
import (
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea/v2"
)
type model struct{}
func (m model) Init() tea.Cmd {
// Nothing needs to be initialized
return nil
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
// I'm a key press or release message
switch key := msg.(type) {
case tea.KeyReleaseMsg:
// I'm a key release message ;)
return m, tea.Printf("Key released: %s", key)
case tea.KeyPressMsg:
switch key.Mod {
case tea.ModCtrl:
switch key.Code {
case 'c':
return m, tea.Quit
}
}
// I'm a key press message
return m, tea.Printf("You pressed %s", key)
}
}
return m, nil
}
func (m model) View() string {
return "Press keys..."
}
func main() {
p := tea.NewProgram(model{}, tea.WithKeyboardEnhancements(
tea.WithKeyReleases, // Do we want to listen to key releases?
tea.WithUniformKeyLayout,
))
if _, err := p.Run(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}
}
```
**Expected behavior**
Key release messages correctly fire across macOS terminals.
**Screenshots**
#### Showing [ghostty w/ tmux] and then [ghostty w/o tmux]
https://github.com/user-attachments/assets/6f68b5fc-749f-4969-a9bd-00f1d9c84e00
#### Showing [terminal w/ tmux] and then [terminal w/o tmux]
https://github.com/user-attachments/assets/f231105f-cc48-40fe-8ceb-1b108b81431d
Contributor guide
Research direction
Start with the supplied Go reproducer and its tea.NewProgram configuration using WithKeyboardEnhancements and WithKeyReleases. Run it across the listed macOS, Ghostty, stock Terminal, and tmux setups, then trace why KeyReleaseMsg events are missing and verify that release messages fire consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, macos, zsh
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100