Skip to content

v2: KeyReleaseMsgs not working as expected on macos #1387

Open
@KaminFay

Description

@KaminFay

Describe the bug
It looks as though the tea.KeyReleaseMsgs 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
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]

Screen.Recording.2025-04-11.at.12.33.46.AM.mov

Showing [terminal w/ tmux] and then [terminal w/o tmux]

Screen.Recording.2025-04-11.at.12.35.48.AM.mov

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions